Skip to content

Commit

Permalink
Merge pull request #442 from linode/dev
Browse files Browse the repository at this point in the history
v0.54.0
  • Loading branch information
jriddle-linode authored Apr 19, 2023
2 parents 23a4480 + aefee9a commit 0857e40
Show file tree
Hide file tree
Showing 37 changed files with 1,171 additions and 1,096 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/oci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Clone Repository
uses: actions/checkout@e2f20e631ae6d7dd3b768f56a5d2af784dd54791 # pin@v2
uses: actions/checkout@v3

- name: setup python 3
uses: actions/setup-python@75f3110429a8c05be0e1bf360334e4cced2b63fa # pin@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/publish-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # pin@v3
uses: actions/checkout@v3

- name: Update system packages
run: sudo apt-get update -y
Expand All @@ -17,7 +17,7 @@ jobs:
run: sudo apt-get install -y build-essential

- name: Setup Python
uses: actions/setup-python@75f3110429a8c05be0e1bf360334e4cced2b63fa # pin@v2
uses: actions/setup-python@v4
with:
python-version: '3.x'

Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: install boto3
run: pip3 install boto3
- name: install dependencies
run: pip3 install -r requirements-dev.txt -r requirements.txt

Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include linodecli/data-3
include linodecli/oauth-landing-page.html
include linode-cli.sh
include baked_version
include baked_version
include requirements.txt
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ Suppressing Defaults
""""""""""""""""""""

If you configured default values for ``image``, ``authorized_users``, ``region``,
and Linode ``type``, they will be sent for all requests that accept them if you
do not specify a different value. If you want to send a request *without* these
database ``engine``, and Linode ``type``, they will be sent for all requests that accept them
if you do not specify a different value. If you want to send a request *without* these
arguments, you must invoke the CLI with the ``--no-defaults`` option.

For example, to create a Linode with no ``image`` after a default Image has been
Expand Down Expand Up @@ -474,7 +474,7 @@ added to Linode's OpenAPI spec:
|x-linode-cli-skip | path | If present and truthy, this method will not be available in the CLI. |
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+
+x-linode-cli-allowed-defaults| requestBody | Tells the CLI what configured defaults apply to this request. Valid defaults are "region",|
+ | | "image", "authorized_users", and "type". |
+ | | "image", "authorized_users", "engine", and "type". |
+-----------------------------+-------------+-------------------------------------------------------------------------------------------+
+x-linode-cli-nested-list | content-type| Tells the CLI to flatten a single object into multiple table rows based on the keys |
| | | included in this value. Values should be comma-delimited JSON paths, and must all be |
Expand Down
4 changes: 3 additions & 1 deletion linodecli/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def _build_request_body(ctx, operation, parsed_args) -> Optional[str]:

# Merge defaults into body if applicable
if ctx.defaults:
parsed_args = ctx.config.update(parsed_args, operation.allowed_defaults)
parsed_args = ctx.config.update(
parsed_args, operation.allowed_defaults, operation.action
)

to_json = {k: v for k, v in vars(parsed_args).items() if v is not None}

Expand Down
38 changes: 36 additions & 2 deletions linodecli/configuration/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def plugin_get_value(self, key):
# might be better to move this to argparsing during refactor and just have
# configuration return defaults or keys or something
def update(
self, namespace, allowed_defaults
self, namespace, allowed_defaults, action=None
): # pylint: disable=too-many-branches
"""
This updates a Namespace (as returned by ArgumentParser) with config values
Expand Down Expand Up @@ -242,6 +242,17 @@ def update(
continue
if self.config.has_option(username, key):
value = self.config.get(username, key)
# different types of database creation use different endpoints,
# so we need to set the default engine value based on the type
elif key == "engine":
if action == "mysql-create" and self.config.has_option(
username, "mysql_engine"
):
value = self.config.get(username, "mysql_engine")
elif action == "postgresql-create" and self.config.has_option(
username, "postgresql_engine"
):
value = self.config.get(username, "postgresql_engine")
else:
value = ns_dict[key]
if not value:
Expand Down Expand Up @@ -275,7 +286,7 @@ def write_config(self):

def configure(
self,
): # pylint: disable=too-many-branches,too-many-statements
): # pylint: disable=too-many-branches,too-many-statements,too-many-locals
"""
This assumes we're running interactively, and prompts the user
for a series of defaults in order to make future CLI calls
Expand Down Expand Up @@ -336,6 +347,15 @@ def configure(
images = [
i["id"] for i in _do_get_request(self.base_url, "/images")["data"]
]
engines_list = _do_get_request(self.base_url, "/databases/engines")[
"data"
]
mysql_engines = [
e["id"] for e in engines_list if e["engine"] == "mysql"
]
postgresql_engines = [
e["id"] for e in engines_list if e["engine"] == "postgresql"
]

is_full_access = _check_full_access(self.base_url, token)

Expand Down Expand Up @@ -378,6 +398,20 @@ def configure(
"Please select a valid Image, or press Enter to skip",
)

config["mysql_engine"] = _default_thing_input(
"Default Engine to create a Managed MySQL Database.",
mysql_engines,
"Default Engine (Optional): ",
"Please select a valid MySQL Database Engine, or press Enter to skip",
)

config["postgresql_engine"] = _default_thing_input(
"Default Engine to create a Managed PostgreSQL Database.",
postgresql_engines,
"Default Engine (Optional): ",
"Please select a valid PostgreSQL Database Engine, or press Enter to skip",
)

if auth_users:
config["authorized_users"] = _default_thing_input(
"Select the user that should be given default SSH access to new Linodes.",
Expand Down
16 changes: 15 additions & 1 deletion linodecli/configuration/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _default_thing_input(
return ret


def _handle_no_default_user(self):
def _handle_no_default_user(self): # pylint: disable=too-many-branches
"""
Handle the case that there is no default user in the config
"""
Expand Down Expand Up @@ -167,6 +167,20 @@ def _handle_no_default_user(self):
username, "image", self.config.get("DEFAULT", "image")
)

if self.config.has_option("DEFAULT", "mysql_engine"):
self.config.set(
username,
"mysql_engine",
self.config.get("DEFAULT", "mysql_engine"),
)

if self.config.has_option("DEFAULT", "postgresql_engine"):
self.config.set(
username,
"postgresql_engine",
self.config.get("DEFAULT", "postgresql_engine"),
)

if self.config.has_option("DEFAULT", "authorized_keys"):
self.config.set(
username,
Expand Down
Loading

0 comments on commit 0857e40

Please sign in to comment.