Skip to content

Commit 173fa90

Browse files
authored
Update kms_key_backup.py
Changed as per. review request
1 parent df9e494 commit 173fa90

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

security/security-design/shared-assets/kms-backup/files/kms_key_backup.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,11 @@ def load_config(config_file_name):
8484
"""Load config file and returns dict of configuration"""
8585
try:
8686
config_file = open(config_file_name)
87+
config = json.load(config_file)
88+
config_file.close()
8789
except Exception as ioError:
8890
print("Load of configuration file: " + args.configfile + " failed")
8991
exit(1)
90-
try:
91-
config = json.load(config_file)
92-
config_file.close()
9392
except Exception as ConfigError:
9493
print("JSON Parse of configuration file: " + config_file_name + " failed")
9594
exit(1)
@@ -115,7 +114,7 @@ def parse_cmd_line():
115114
args_parser.add_argument('--'+arg[0],default=arg[1],action='store_true',help=arg[3])
116115
# Parse and return parsed Namespace
117116
args = args_parser.parse_args()
118-
return(args)
117+
return args
119118

120119
#########################################################################
121120
# overwrite_config
@@ -242,7 +241,7 @@ def create_kms_client(oci_config_file,oci_profile_name,kms_vault_ocid):
242241
kms_client['vault_client']=kms_vault_client
243242
kms_client['vault_data']=kms_vault_data
244243
kms_client['ociconfig']=oci_config
245-
return(kms_client)
244+
return kms_client
246245

247246
#########################################################################
248247
# get_kms_key
@@ -256,7 +255,7 @@ def get_kms_key(kms_client,compartment_ocid,kms_keyname,kms_keyocid,wrapping_key
256255
""" get_kms_key """
257256
if kms_keyname is None and kms_keyocid is None:
258257
print("Eiter keyname or keyocid needs to be set")
259-
return(False)
258+
return False
260259
###################################################
261260
#### Allocate KSM management client, KMS vault client
262261
###################################################
@@ -305,23 +304,20 @@ def get_kms_key(kms_client,compartment_ocid,kms_keyname,kms_keyocid,wrapping_key
305304
exported_key = kms_crypto_client.export_key(
306305
export_key_details
307306
)
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
313309
else:
314310
print("Key is not in ENABLED state")
315-
return(False)
311+
return False
316312
else:
317313
print("Key found but it is not a softare key, export not permitted by OCI")
318-
return(False)
314+
return False
319315
#
320316
# This point is reached only if a key with OCID or name is not found
321317
#
322318
print("No key found, verify name/ocid")
323319
#
324-
return(False)
320+
return False
325321

326322
#########################################################################
327323
# import_key
@@ -390,10 +386,10 @@ def import_key(config,key_data,kms_client,wrapping_key,wrapping_algorithm):
390386
)
391387
print("Imported key: " + config['target_keyname'] + " with ID: " + kms_key.id )
392388
print("Target OCID " + response.data.id)
393-
return(response)
389+
return response
394390
except Exception as e:
395391
print("Failed to import key " + kms_key.id + ": " + str(e))
396-
return(False)
392+
return False
397393

398394

399395

@@ -408,7 +404,7 @@ def main():
408404
#
409405
os_name = platform.system().lower()
410406
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'
412408
elif os_name == 'windows':
413409
default_kms_copy_config_file = 'c:\\temp\\key_backup.json'
414410
else:

0 commit comments

Comments
 (0)