Skip to content

Commit c0a860c

Browse files
Add suppress-version-warning config option (#635)
## 📝 Description **What does this PR do and why is this change necessary?** Adds `get_bool('value')` method for configuration options and adds a step in configuration to support `suppress-version-warning`. Also adds support for `LINODE_CLI_SUPPRESS_VERSION_WARNING` environment variable. ## ✔️ How to Test **What are the steps to reproduce the issue or verify the changes?** 1. Install the new version of the CLI ```bash make install ``` 2. Go through the configuration process ```bash lin configure ``` 3. The last question should ask you about suppressing API Version Warnings 4. Use the CLI and see if you view this warning ### Environment variable 1. Install the new CLI or delete the value from your config 2. Use the cli after setting the environment variable ```bash export LINODE_CLI_SUPPRESS_VERSION_WARNING=true lin linodes ls unset $LINODE_CLI_SUPPRESS_VERSION_WARNING lin linodes ls ``` 3. Verify the output doesn't have the error. **How do I run the relevant unit/integration tests?** ```bash make testunit ``` resolves #582
1 parent 5e6003b commit c0a860c

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

linodecli/api_request.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import itertools
66
import json
7+
import os
78
import sys
89
import time
910
from typing import Any, Iterable, List, Optional
@@ -373,8 +374,10 @@ def _attempt_warn_old_version(ctx, result):
373374
"with --suppress-warnings",
374375
file=sys.stderr,
375376
)
376-
377-
if new_version_exists:
377+
suppress_version_warning = ctx.config.get_bool("suppress-version-warning") or os.getenv(
378+
"LINODE_CLI_SUPPRESS_VERSION_WARNING"
379+
)
380+
if new_version_exists and not suppress_version_warning:
378381
print(
379382
f"The API responded with version {spec_version}, which is newer than "
380383
f"the CLI's version of {ctx.spec_version}. Please update the CLI to get "

linodecli/configuration/config.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,30 @@ def get_value(self, key: str) -> Optional[Any]:
186186

187187
return self.config.get(username, key)
188188

189+
def get_bool(self, key: str) -> bool:
190+
"""
191+
Retrieves and returns an existing config boolean for the current user. This
192+
is intended for plugins to use instead of having to deal with figuring out
193+
who the current user is when accessing their config.
194+
195+
.. warning::
196+
Plugins _MUST NOT_ set values for the user's config except through
197+
``plugin_set_value`` below.
198+
199+
:param key: The key to look up.
200+
:type key: str
201+
202+
:returns: The boolean for that key, or False if the key doesn't exist for the
203+
current user.
204+
:rtype: any
205+
"""
206+
username = self.username or self.default_username()
207+
208+
if not self.config.has_option(username, key):
209+
return False
210+
211+
return self.config.getboolean(username, key)
212+
189213
# plugin methods - these are intended for plugins to utilize to store their
190214
# own persistent config information
191215
def plugin_set_value(self, key: str, value: Any):
@@ -449,6 +473,9 @@ def configure(
449473
if _bool_input("Configure a custom API target?", default=False):
450474
self._configure_api_target(config)
451475

476+
if _bool_input("Suppress API Version Warnings?", default=False):
477+
config["suppress-version-warning"] = "true"
478+
452479
# save off the new configuration
453480
if username != "DEFAULT" and not self.config.has_section(username):
454481
self.config.add_section(username)

tests/unit/test_configuration.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class TestConfiguration:
3838
plugin-testplugin-testkey = plugin-test-value
3939
authorized_users = cli-dev
4040
mysql_engine = mysql/8.0.26
41+
suppress-version-warning = true
4142
4243
[cli-dev2]
4344
token = {test_token}2
@@ -156,6 +157,14 @@ def test_get_value(self):
156157
assert conf.get_value("notakey") == None
157158
assert conf.get_value("region") == "us-east"
158159

160+
def test_get_bool(self):
161+
"""
162+
Test CLIConfig.get_bool({key})
163+
"""
164+
conf = self._build_test_config()
165+
assert conf.get_bool("notakey") == False
166+
assert conf.get_bool("suppress-version-warning") == True
167+
159168
def test_plugin_set_value(self):
160169
"""
161170
Test CLIConfig.plugin_set_value({key}, {value})
@@ -265,6 +274,7 @@ def test_configure_no_default_terminal(self):
265274
"foobar.linode.com",
266275
"v4beta",
267276
"https",
277+
"n",
268278
]
269279
)
270280

@@ -319,7 +329,7 @@ def test_configure_default_terminal(self):
319329
"""
320330
conf = configuration.CLIConfig(self.base_url, skip_config=True)
321331

322-
answers = iter(["1", "1", "1", "1", "1", "1", "n"])
332+
answers = iter(["1", "1", "1", "1", "1", "1", "n", "n"])
323333

324334
def mock_input(prompt):
325335
if not prompt:

wiki/Configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ without having a configuration file, which is desirable in some situations.
3838
You may also specify the path to a custom Certificate Authority file using the `LINODE_CLI_CA`
3939
environment variable.
4040

41+
If you wish to hide the API Version warning you can use the `LINODE_CLI_SUPPRESS_VERSION_WARNING`
42+
environment variable.
43+
4144
## Configurable API URL
4245

4346
In some cases you may want to run linode-cli against a non-default Linode API URL.

0 commit comments

Comments
 (0)