Merge pull request #9635 from bridadan/no_pelion_host

Do not provide a default Pelion host address.
pull/9728/head
Cruz Monrreal 2019-02-14 20:25:31 -06:00 committed by GitHub
commit 6278ed66b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 22 deletions

View File

@ -23,7 +23,6 @@ import logging
import sys import sys
import argparse import argparse
from os.path import join, abspath, dirname, basename from os.path import join, abspath, dirname, basename
from os import getenv
from manifesttool import create, parse, verify, cert, init, update from manifesttool import create, parse, verify, cert, init, update
from manifesttool.argparser import MainArgumentParser from manifesttool.argparser import MainArgumentParser
@ -31,9 +30,6 @@ from mbed_cloud import AccountManagementAPI, CertificatesAPI
import colorama import colorama
colorama.init() colorama.init()
from utils import (generate_update_filename)
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
LOG_FORMAT = '[%(levelname)s] %(asctime)s - %(name)s - %(message)s' LOG_FORMAT = '[%(levelname)s] %(asctime)s - %(name)s - %(message)s'
@ -43,6 +39,7 @@ sys.path.insert(0, ROOT)
from tools.config import Config from tools.config import Config
from tools.options import extract_mcus from tools.options import extract_mcus
from tools.utils import generate_update_filename
class MbedExtendedArgs(MainArgumentParser): class MbedExtendedArgs(MainArgumentParser):
@ -92,24 +89,30 @@ def wrap_payload(func):
def wrap_init(func): def wrap_init(func):
def inner(options): def inner(options):
if getattr(options, 'api_key', None): config = {}
api_key = options.api_key if getattr(options, 'api_key'):
else: config["api_key"] = options.api_key
api_key = getenv("MBED_CLOUD_SDK_API_KEY") if getattr(options, 'server_address'):
if getattr(options, 'server_address', None): config["host"] = options.server_address
host_addr = options.server_address
else: try:
host_addr = getenv("MBED_CLOUD_SDK_HOST", accounts = AccountManagementAPI(config)
"https://api.us-east-1.mbedcloud.com/") certs = CertificatesAPI(config)
config = { except Exception as e:
"api_key": api_key, LOG.error(
"host": host_addr, 'Missing api key. Set it with '
} '"mbed config -G CLOUD_SDK_API_KEY <api key>"'
accounts = AccountManagementAPI(config) )
certs = CertificatesAPI(config) exit(1)
api_key = accounts.list_api_keys(filter={
'key': api_key # Get the currently in-use API key (may come from environment or
}).next() # configuration files, which is handled by the cloud SDK)
api_key_value = accounts.config.get("api_key")
api_key = accounts.list_api_keys(
filter={
"key": api_key_value
}
).next()
certificates_owned = list(certs.list_certificates()) certificates_owned = list(certs.list_certificates())
dev_cert_info = None dev_cert_info = None
for certif in certificates_owned: for certif in certificates_owned: