Skip to content

Commit

Permalink
Add spacecmd function - cryptokey_update
Browse files Browse the repository at this point in the history
  • Loading branch information
blu-base committed Jan 29, 2023
1 parent 2a47d90 commit a79995b
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions spacecmd/src/spacecmd/cryptokey.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,77 @@ def do_cryptokey_create(self, args):
####################


def help_cryptokey_update(self):
print(_('cryptokey_update: Update a cryptographic key'))
print(_('''usage: cryptokey_update [options])
options:
-t GPG or SSL
-d DESCRIPTION
-f KEY_FILE'''))


def do_cryptokey_update(self, args):
arg_parser = get_argument_parser()
arg_parser.add_argument('-t', '--type')
arg_parser.add_argument('-d', '--description')
arg_parser.add_argument('-f', '--file')

(args, options) = parse_command_arguments(args, arg_parser)
options.contents = None

if is_interactive(options):
options.type = prompt_user(_('GPG or SSL [G/S]:'))

options.description = ''
while options.description == '':
options.description = prompt_user(_('Description:'))

if self.user_confirm(_('Read an existing file [y/N]:'),
nospacer=True, ignore_yes=True):
options.file = prompt_user('File:')
else:
options.contents = editor(delete=True)
else:
if not options.type:
logging.error(_N('The key type is required'))
return 1

if not options.description:
logging.error(_N('A description is required'))
return 1

if not options.file:
logging.error(_N('A file containing the key is required'))
return 1

# read the file the user specified
if options.file:
options.contents = read_file(options.file)

if not options.contents:
logging.error(_N('No contents of the file'))
return 1

# translate the key type to what the server expects
if re.match('G', options.type, re.I):
options.type = 'GPG'
elif re.match('S', options.type, re.I):
options.type = 'SSL'
else:
logging.error(_N('Invalid key type'))
return 1

self.client.kickstart.keys.update(self.session,
options.description,
options.type,
options.contents)

return 0

####################


def help_cryptokey_delete(self):
print(_('cryptokey_delete: Delete a cryptographic key'))
print(_('usage: cryptokey_delete NAME'))
Expand Down

0 comments on commit a79995b

Please sign in to comment.