|
15 | 15 | import yaml |
16 | 16 | from britive import exceptions |
17 | 17 | from britive.britive import Britive |
18 | | -from colored import Fore, Style |
19 | 18 | from jwt.exceptions import PyJWTError |
20 | 19 | from tabulate import tabulate |
21 | 20 |
|
|
26 | 25 | from .helpers.credentials import EncryptedFileCredentialManager, FileCredentialManager |
27 | 26 | from .helpers.split import profile_split |
28 | 27 |
|
| 28 | +try: |
| 29 | + from colored import Fore, Style |
| 30 | +except ImportError: # colored in < python3.9 |
| 31 | + from colored import fore, style |
| 32 | + |
29 | 33 | default_table_format = 'fancy_grid' |
30 | 34 | debug_enabled = os.getenv('PYBRITIVE_DEBUG') |
31 | 35 | default_browser = os.getenv('PYBRITIVE_BROWSER') |
@@ -171,14 +175,21 @@ def _display_banner(self): |
171 | 175 | return |
172 | 176 |
|
173 | 177 | # if we get here then we need to at least grab the banner and see if it has changed |
174 | | - banner = self.b.banner() |
175 | | - banner_changed = Cache().save_banner(tenant=self.tenant_name, banner=banner) |
176 | | - msg_type = banner.get('messageType', 'UNKNOWN') |
177 | | - color = {'caution': Style.BOLD + Fore.red, 'warning': Style.BOLD + Fore.yellow}.get( |
178 | | - msg_type.lower(), Style.BOLD + Fore.blue |
179 | | - ) |
180 | | - if banner and banner_changed: |
181 | | - self.print(f'{color}*** {msg_type}: {banner.get("message", "<no message>")} ***{Style.reset}') |
| 178 | + if banner := self.b.banner(): |
| 179 | + banner_changed = Cache().save_banner(tenant=self.tenant_name, banner=banner) |
| 180 | + msg_type = banner.get('messageType', 'UNKNOWN') |
| 181 | + try: |
| 182 | + color = {'caution': Style.BOLD + Fore.red, 'warning': Style.BOLD + Fore.yellow}.get( |
| 183 | + msg_type.lower(), Style.BOLD + Fore.blue |
| 184 | + ) |
| 185 | + style_reset = Style.reset |
| 186 | + except NameError: # colored in < python3.9 |
| 187 | + color = {'caution': style.BOLD + fore.RED, 'warning': style.BOLD + fore.YELLOW}.get( |
| 188 | + msg_type.lower(), style.BOLD + fore.BLUE |
| 189 | + ) |
| 190 | + style_reset = style.RESET |
| 191 | + if banner_changed: |
| 192 | + self.print(f'{color}*** {msg_type}: {banner.get("message", "<no message>")} ***{style_reset}') |
182 | 193 |
|
183 | 194 | def _update_sdk_user_agent(self): |
184 | 195 | # update the user agent to include the pybritive cli version |
|
0 commit comments