`mbed dm`: Accept api key and host on the command line

### Description

`mbed dm` will now accept the Pelion Device Management API Key and
Host on the command line with the following switches:
 * `-a`, `--api-key` accepts the API Key
 * `-S` (note capitol), `--server-address` accepts the Host

 This is consistant with manifest tool parameters
 Resolves https://github.com/ARMmbed/mbed-cli/issues/745

### Pull request type

    [x] Fix
    [ ] Refactor
    [ ] Target update
    [ ] Functionality change
    [ ] Breaking change
pull/8063/head
Jimmy Brisson 2018-09-10 11:49:06 -05:00
parent 06106297a4
commit e67a2c7692
1 changed files with 16 additions and 3 deletions

View File

@ -80,10 +80,23 @@ def wrap_payload(func):
def wrap_init(func):
def inner(options):
accounts = AccountManagementAPI()
certs = CertificatesAPI()
if getattr(options, 'api_key', None):
api_key = options.api_key
else:
api_key = getenv("MBED_CLOUD_SDK_API_KEY")
if getattr(options, 'server_address', None):
host_addr = options.server_address
else:
host_addr = getenv("MBED_CLOUD_SDK_HOST",
"https://api.us-east-1.mbedcloud.com/")
config = {
"api_key": api_key,
"host": host_addr,
}
accounts = AccountManagementAPI(config)
certs = CertificatesAPI(config)
api_key = accounts.list_api_keys(filter={
'key': getenv("MBED_CLOUD_SDK_API_KEY")
'key': api_key
}).next()
user = accounts.get_user(api_key.owner_id)
certificates_owned = list(certs.list_certificates())