@@ -84,12 +84,11 @@ def load_config(config_file_name):
84
84
"""Load config file and returns dict of configuration"""
85
85
try :
86
86
config_file = open (config_file_name )
87
+ config = json .load (config_file )
88
+ config_file .close ()
87
89
except Exception as ioError :
88
90
print ("Load of configuration file: " + args .configfile + " failed" )
89
91
exit (1 )
90
- try :
91
- config = json .load (config_file )
92
- config_file .close ()
93
92
except Exception as ConfigError :
94
93
print ("JSON Parse of configuration file: " + config_file_name + " failed" )
95
94
exit (1 )
@@ -115,7 +114,7 @@ def parse_cmd_line():
115
114
args_parser .add_argument ('--' + arg [0 ],default = arg [1 ],action = 'store_true' ,help = arg [3 ])
116
115
# Parse and return parsed Namespace
117
116
args = args_parser .parse_args ()
118
- return ( args )
117
+ return args
119
118
120
119
#########################################################################
121
120
# overwrite_config
@@ -242,7 +241,7 @@ def create_kms_client(oci_config_file,oci_profile_name,kms_vault_ocid):
242
241
kms_client ['vault_client' ]= kms_vault_client
243
242
kms_client ['vault_data' ]= kms_vault_data
244
243
kms_client ['ociconfig' ]= oci_config
245
- return ( kms_client )
244
+ return kms_client
246
245
247
246
#########################################################################
248
247
# get_kms_key
@@ -256,7 +255,7 @@ def get_kms_key(kms_client,compartment_ocid,kms_keyname,kms_keyocid,wrapping_key
256
255
""" get_kms_key """
257
256
if kms_keyname is None and kms_keyocid is None :
258
257
print ("Eiter keyname or keyocid needs to be set" )
259
- return ( False )
258
+ return False
260
259
###################################################
261
260
#### Allocate KSM management client, KMS vault client
262
261
###################################################
@@ -305,23 +304,20 @@ def get_kms_key(kms_client,compartment_ocid,kms_keyname,kms_keyocid,wrapping_key
305
304
exported_key = kms_crypto_client .export_key (
306
305
export_key_details
307
306
)
308
- key_data = {}
309
- key_data ['exported_key' ]= exported_key
310
- key_data ['kms_key_metadata' ]= kms_key
311
- key_data ['current_key_data' ]= current_key_data
312
- return (key_data )
307
+ key_data = {'exported_key' :exported_key ,'kms_key_metadata' :kms_key ,'current_key_data' :current_key_data }
308
+ return key_data
313
309
else :
314
310
print ("Key is not in ENABLED state" )
315
- return ( False )
311
+ return False
316
312
else :
317
313
print ("Key found but it is not a softare key, export not permitted by OCI" )
318
- return ( False )
314
+ return False
319
315
#
320
316
# This point is reached only if a key with OCID or name is not found
321
317
#
322
318
print ("No key found, verify name/ocid" )
323
319
#
324
- return ( False )
320
+ return False
325
321
326
322
#########################################################################
327
323
# import_key
@@ -390,10 +386,10 @@ def import_key(config,key_data,kms_client,wrapping_key,wrapping_algorithm):
390
386
)
391
387
print ("Imported key: " + config ['target_keyname' ] + " with ID: " + kms_key .id )
392
388
print ("Target OCID " + response .data .id )
393
- return ( response )
389
+ return response
394
390
except Exception as e :
395
391
print ("Failed to import key " + kms_key .id + ": " + str (e ))
396
- return ( False )
392
+ return False
397
393
398
394
399
395
@@ -408,7 +404,7 @@ def main():
408
404
#
409
405
os_name = platform .system ().lower ()
410
406
if os_name == 'linux' :
411
- default_kms_copy_config_file = '/home/users /demo/key_backup.json'
407
+ default_kms_copy_config_file = '~ /demo/key_backup.json'
412
408
elif os_name == 'windows' :
413
409
default_kms_copy_config_file = 'c:\\ temp\\ key_backup.json'
414
410
else :
0 commit comments