|
23 | 23 | import sys
|
24 | 24 | import argparse
|
25 | 25 | from os.path import join, abspath, dirname, basename
|
26 |
| -from os import getenv |
27 | 26 |
|
28 | 27 | from manifesttool import create, parse, verify, cert, init, update
|
29 | 28 | from manifesttool.argparser import MainArgumentParser
|
30 | 29 | from mbed_cloud import AccountManagementAPI, CertificatesAPI
|
31 | 30 | import colorama
|
32 | 31 | colorama.init()
|
33 | 32 |
|
34 |
| -from utils import (generate_update_filename) |
35 |
| - |
36 |
| - |
37 | 33 | LOG = logging.getLogger(__name__)
|
38 | 34 | LOG_FORMAT = '[%(levelname)s] %(asctime)s - %(name)s - %(message)s'
|
39 | 35 |
|
|
43 | 39 |
|
44 | 40 | from tools.config import Config
|
45 | 41 | from tools.options import extract_mcus
|
| 42 | +from tools.utils import generate_update_filename |
46 | 43 |
|
47 | 44 |
|
48 | 45 | class MbedExtendedArgs(MainArgumentParser):
|
@@ -92,24 +89,30 @@ def inner(options):
|
92 | 89 |
|
93 | 90 | def wrap_init(func):
|
94 | 91 | 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() |
113 | 116 | certificates_owned = list(certs.list_certificates())
|
114 | 117 | dev_cert_info = None
|
115 | 118 | for certif in certificates_owned:
|
|
0 commit comments