1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
"""Create a password for a software component"""
# :license: MIT, see LICENSE for more details.
import click
import SoftLayer
from SoftLayer.CLI import environment
from SoftLayer.CLI import exceptions
from SoftLayer.CLI import formatting
@click.command(cls=SoftLayer.CLI.command.SLCommand, )
@click.argument('identifier')
@click.option('--username', '-U', required=True, help="The username part of the username/password pair")
@click.option('--password', '-P', required=True, help="The password part of the username/password pair.")
@click.option('--notes', '-n', help="A note string stored for this username/password pair.")
@click.option('--system', required=True, help="The name of this specific piece of software.")
@environment.pass_env
def cli(env, identifier, username, password, notes, system):
"""Create a password for a software component."""
mgr = SoftLayer.HardwareManager(env.client)
software = mgr.get_software_components(identifier)
sw_id = ''
try:
for sw_instance in software:
if (sw_instance['softwareLicense']['softwareDescription']['name']).lower() == system:
sw_id = sw_instance['id']
except KeyError as ex:
raise exceptions.CLIAbort('System id not found') from ex
template = {
"notes": notes,
"password": password,
"softwareId": sw_id,
"username": username,
"software": {
"hardwareId": identifier,
"softwareLicense": {
"softwareDescription": {
"name": system
}
}
}}
result = mgr.create_credential(template)
table = formatting.KeyValueTable(['name', 'value'])
table.align['name'] = 'r'
table.align['value'] = 'l'
table.add_row(['Software Id', result['id']])
table.add_row(['Created', result['createDate']])
table.add_row(['Username', result['username']])
table.add_row(['Password', result['password']])
table.add_row(['Notes', result['notes']])
env.fout(table)
|