Skip to content

Commit e67a2c7

Browse files
committed
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 ARMmbed/mbed-cli#745 ### Pull request type [x] Fix [ ] Refactor [ ] Target update [ ] Functionality change [ ] Breaking change
1 parent 0610629 commit e67a2c7

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tools/device_management.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,23 @@ def inner(options):
8080

8181
def wrap_init(func):
8282
def inner(options):
83-
accounts = AccountManagementAPI()
84-
certs = CertificatesAPI()
83+
if getattr(options, 'api_key', None):
84+
api_key = options.api_key
85+
else:
86+
api_key = getenv("MBED_CLOUD_SDK_API_KEY")
87+
if getattr(options, 'server_address', None):
88+
host_addr = options.server_address
89+
else:
90+
host_addr = getenv("MBED_CLOUD_SDK_HOST",
91+
"https://api.us-east-1.mbedcloud.com/")
92+
config = {
93+
"api_key": api_key,
94+
"host": host_addr,
95+
}
96+
accounts = AccountManagementAPI(config)
97+
certs = CertificatesAPI(config)
8598
api_key = accounts.list_api_keys(filter={
86-
'key': getenv("MBED_CLOUD_SDK_API_KEY")
99+
'key': api_key
87100
}).next()
88101
user = accounts.get_user(api_key.owner_id)
89102
certificates_owned = list(certs.list_certificates())

0 commit comments

Comments
 (0)