11
11
from hashlib import sha512
12
12
from ssh_utils import ssh_connect , ssh_copy_file
13
13
14
+ from configparser import ConfigParser , NoSectionError , NoOptionError
15
+
14
16
# Provide client_id from cli$
15
17
# Same for trust domain
16
18
# Get image id and transform as for server
@@ -26,6 +28,11 @@ def parse_arguments() -> argparse.ArgumentParser:
26
28
"""
27
29
parser = argparse .ArgumentParser (description = "CLI Options" )
28
30
31
+ parser .add_argument (
32
+ "--config" ,
33
+ required = True ,
34
+ help = "Path to the client configuration file" ,
35
+ )
29
36
parser .add_argument (
30
37
"--users" ,
31
38
"-u" ,
@@ -82,19 +89,6 @@ def parse_arguments() -> argparse.ArgumentParser:
82
89
type = str ,
83
90
help = "Path to write the dataset on the supercomputer storage default :" ,
84
91
)
85
- parser .add_argument (
86
- "--sd-server-address" ,
87
- "-a" ,
88
- type = str ,
89
- help = "Server address" ,
90
- )
91
- parser .add_argument (
92
- "--sd-server-port" ,
93
- "-ap" ,
94
- type = int ,
95
- default = 10080 ,
96
- help = "SD API server port (default: 10080)" ,
97
- )
98
92
parser .add_argument (
99
93
"--username" ,
100
94
required = True ,
@@ -103,6 +97,25 @@ def parse_arguments() -> argparse.ArgumentParser:
103
97
104
98
return parser .parse_args ()
105
99
100
+ # Parse configuration file
101
+ def parse_configuration (path : str ):
102
+ config = ConfigParser ()
103
+ config .read (path )
104
+
105
+ if not 'hpcs-server' in config :
106
+ raise NoSectionError ("hpcs-server section missing in configuration file, aborting" )
107
+
108
+ if not 'vault' in config :
109
+ raise NoSectionError ("vault section missing in configuration file, aborting" )
110
+
111
+ if not 'url' in config ['hpcs-server' ]:
112
+ raise NoOptionError ("'hpcs-server' section is incomplete in configuration file, aborting" )
113
+
114
+ if not 'url' in config ['vault' ]:
115
+ raise NoOptionError ("'vault' section is incomplete in configuration file, aborting" )
116
+
117
+ return config
118
+
106
119
107
120
def validate_options (options : argparse .ArgumentParser ):
108
121
"""Check for the cli-provided options
@@ -194,7 +207,7 @@ def validate_options(options: argparse.ArgumentParser):
194
207
195
208
196
209
def create_authorized_workloads (
197
- SVID : JwtSvid , secret , server , port , users , groups , compute_nodes
210
+ SVID : JwtSvid , secret , url , users , groups , compute_nodes
198
211
):
199
212
"""Create workloads that are authorized to access to a secret
200
213
@@ -212,7 +225,7 @@ def create_authorized_workloads(
212
225
"""
213
226
214
227
# Prepare request
215
- url = f"http:// { server } : { port } /api/client/create-workloads"
228
+ url = f"{ url } /api/client/create-workloads"
216
229
payload = {
217
230
"jwt" : SVID .token ,
218
231
"secret" : secret ,
@@ -248,7 +261,9 @@ def create_authorized_workloads(
248
261
249
262
if __name__ == "__main__" :
250
263
# Parse arguments from CLI
251
- options = parse_arguments ()
264
+ options = parse_arguments ()
265
+ # Parse configuration file
266
+ configuration = parse_configuration (options .config )
252
267
253
268
# Validate / Parse them
254
269
(
@@ -277,15 +292,14 @@ def create_authorized_workloads(
277
292
users_spiffeID , client_id , secrets_path , user_role = create_authorized_workloads (
278
293
SVID ,
279
294
secret_name ,
280
- options .sd_server_address ,
281
- options .sd_server_port ,
295
+ configuration ["hpcs-server" ]["url" ],
282
296
users ,
283
297
groups ,
284
298
compute_nodes ,
285
299
)
286
300
287
301
# Login to the vault using client's certificate
288
- hvac_client = vault_login (SVID , f"client_{ client_id } " )
302
+ hvac_client = vault_login (configuration [ "vault" ][ "url" ], SVID , f"client_{ client_id } " )
289
303
290
304
# Prepare secret
291
305
secret = {}
@@ -329,11 +343,11 @@ def create_authorized_workloads(
329
343
ssh_copy_file (
330
344
ssh_client ,
331
345
"/tmp/dataset_info.yaml" ,
332
- f"{ options .data_path_at_rest } { secret_name } .info.yaml" ,
346
+ f"{ options .data_path_at_rest } / { secret_name } .info.yaml" ,
333
347
)
334
348
335
349
print (
336
- f"Data and info file were shipped to te supercomputer. Infos about the dataset are available at { options .data_path_at_rest } /{ secret_name } .info.yaml"
350
+ f"Data and info file were shipped to te supercomputer. Info about the dataset are available at { options .data_path_at_rest } /{ secret_name } .info.yaml"
337
351
)
338
352
339
353
ssh_client .close ()
0 commit comments