1
1
import platform , argparse , subprocess , requests
2
+ from conf .client .conf import parse_configuration
2
3
3
4
4
5
# Parse arguments from the cli
@@ -10,33 +11,6 @@ def parse_arguments():
10
11
"""
11
12
parser = argparse .ArgumentParser (description = "CLI Optinons" )
12
13
13
- parser .add_argument (
14
- "--spire-trust-domain" ,
15
- "-t" ,
16
- type = str ,
17
- default = "lumi-sd-dev" ,
18
- help = "Server address (default: lumi-sd-dev)" ,
19
- )
20
- parser .add_argument (
21
- "--sd-server-address" ,
22
- "-a" ,
23
- type = str ,
24
- help = "Server address" ,
25
- )
26
- parser .add_argument (
27
- "--spire-server-port" ,
28
- "-sp" ,
29
- type = int ,
30
- default = 10081 ,
31
- help = "Spire server port (default: 10081)" ,
32
- )
33
- parser .add_argument (
34
- "--sd-server-port" ,
35
- "-ap" ,
36
- type = int ,
37
- default = 10080 ,
38
- help = "SD API server port (default: 10080)" ,
39
- )
40
14
parser .add_argument (
41
15
"--socketpath" ,
42
16
"-s" ,
@@ -54,8 +28,7 @@ def parse_arguments():
54
28
55
29
return parser .parse_args ()
56
30
57
-
58
- def get_token (server , port , compute_node_token : bool ):
31
+ def get_token (url , compute_node_token : bool ):
59
32
"""Get joinToken to perform node registration from server
60
33
61
34
Args:
@@ -73,9 +46,9 @@ def get_token(server, port, compute_node_token: bool):
73
46
# Check wether we are performing compute node attestation or client attestation, create url
74
47
if compute_node_token :
75
48
hostname = platform .node ()
76
- url = f"http:// { server } : { port } /api/agents/token?hostname={ hostname } "
49
+ url = f"{ url } /api/agents/token?hostname={ hostname } "
77
50
else :
78
- url = f"http:// { server } : { port } /api/client/register"
51
+ url = f"{ url } /api/client/register"
79
52
80
53
# Perform POST request to SD server
81
54
response = requests .post (url )
@@ -89,22 +62,25 @@ def get_token(server, port, compute_node_token: bool):
89
62
if __name__ == "__main__" :
90
63
# Get arguments
91
64
options = parse_arguments ()
65
+
66
+ # Parse configuration file
67
+ configuration = parse_configuration (options .config )
92
68
93
69
# Get token from API
94
70
token = get_token (
95
- options . sd_server_address , options . sd_server_port , options .compute_node
71
+ configuration [ 'hpcs-server' ][ 'url' ] , options .compute_node
96
72
)
97
73
98
74
# Overwrite configuration template
99
75
agent_configuration_template = open ("./utils/agent-on-the-fly.conf" ).read ()
100
76
agent_configuration_template = agent_configuration_template .replace (
101
- "SPIRE_TRUST_DOMAIN" , options . spire_trust_domain
77
+ "SPIRE_TRUST_DOMAIN" , configuration [ 'spire-server' ][ 'trust-domain' ]
102
78
)
103
79
agent_configuration_template = agent_configuration_template .replace (
104
- "SPIRE_SERVER_ADDRESS" , options . sd_server_address
80
+ "SPIRE_SERVER_ADDRESS" , configuration [ 'spire-server' ][ 'address' ]
105
81
)
106
82
agent_configuration_template = agent_configuration_template .replace (
107
- "SPIRE_SERVER_PORT " , str ( options . spire_server_port )
83
+ "SPIRE_SERVER_ADDRESS " , configuration [ 'spire-server' ][ 'port' ]
108
84
)
109
85
agent_configuration_template = agent_configuration_template .replace (
110
86
"SOCKETPATH" , options .socketpath
0 commit comments