Skip to content

Commit 6278ed6

Browse files
author
Cruz Monrreal
authored
Merge pull request #9635 from bridadan/no_pelion_host
Do not provide a default Pelion host address.
2 parents c07410d + 3ff0ca4 commit 6278ed6

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

tools/device_management.py

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,13 @@
2323
import sys
2424
import argparse
2525
from os.path import join, abspath, dirname, basename
26-
from os import getenv
2726

2827
from manifesttool import create, parse, verify, cert, init, update
2928
from manifesttool.argparser import MainArgumentParser
3029
from mbed_cloud import AccountManagementAPI, CertificatesAPI
3130
import colorama
3231
colorama.init()
3332

34-
from utils import (generate_update_filename)
35-
36-
3733
LOG = logging.getLogger(__name__)
3834
LOG_FORMAT = '[%(levelname)s] %(asctime)s - %(name)s - %(message)s'
3935

@@ -43,6 +39,7 @@
4339

4440
from tools.config import Config
4541
from tools.options import extract_mcus
42+
from tools.utils import generate_update_filename
4643

4744

4845
class MbedExtendedArgs(MainArgumentParser):
@@ -92,24 +89,30 @@ def inner(options):
9289

9390
def wrap_init(func):
9491
def inner(options):
95-
if getattr(options, 'api_key', None):
96-
api_key = options.api_key
97-
else:
98-
api_key = getenv("MBED_CLOUD_SDK_API_KEY")
99-
if getattr(options, 'server_address', None):
100-
host_addr = options.server_address
101-
else:
102-
host_addr = getenv("MBED_CLOUD_SDK_HOST",
103-
"https://api.us-east-1.mbedcloud.com/")
104-
config = {
105-
"api_key": api_key,
106-
"host": host_addr,
107-
}
108-
accounts = AccountManagementAPI(config)
109-
certs = CertificatesAPI(config)
110-
api_key = accounts.list_api_keys(filter={
111-
'key': api_key
112-
}).next()
92+
config = {}
93+
if getattr(options, 'api_key'):
94+
config["api_key"] = options.api_key
95+
if getattr(options, 'server_address'):
96+
config["host"] = options.server_address
97+
98+
try:
99+
accounts = AccountManagementAPI(config)
100+
certs = CertificatesAPI(config)
101+
except Exception as e:
102+
LOG.error(
103+
'Missing api key. Set it with '
104+
'"mbed config -G CLOUD_SDK_API_KEY <api key>"'
105+
)
106+
exit(1)
107+
108+
# Get the currently in-use API key (may come from environment or
109+
# configuration files, which is handled by the cloud SDK)
110+
api_key_value = accounts.config.get("api_key")
111+
api_key = accounts.list_api_keys(
112+
filter={
113+
"key": api_key_value
114+
}
115+
).next()
113116
certificates_owned = list(certs.list_certificates())
114117
dev_cert_info = None
115118
for certif in certificates_owned:

0 commit comments

Comments
 (0)