Skip to content

Commit

Permalink
Merge pull request #576 from linode/dev
Browse files Browse the repository at this point in the history
Release v5.48.2
  • Loading branch information
yec-akamai authored Feb 5, 2024
2 parents ede396a + 17fcb03 commit 72c723f
Show file tree
Hide file tree
Showing 34 changed files with 269 additions and 121 deletions.
24 changes: 24 additions & 0 deletions .github/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: new-feature
description: for new features in the changelog.
color: 225fee
- name: improvement
description: for improvements in existing functionality in the changelog.
color: 22ee47
- name: repo-ci-improvement
description: for improvements in the repository or CI workflow in the changelog.
color: c922ee
- name: bugfix
description: for any bug fixes in the changelog.
color: ed8e21
- name: documentation
description: for updates to the documentation in the changelog.
color: d3e1e6
- name: testing
description: for updates to the testing suite in the changelog.
color: 933ac9
- name: breaking-change
description: for breaking changes in the changelog.
color: ff0000
- name: ignore-for-release
description: PRs you do not want to render in the changelog
color: 7b8eac
21 changes: 0 additions & 21 deletions .github/release-drafter.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: ⚠️ Breaking Change
labels:
- breaking-change
- title: 🐛 Bug Fixes
labels:
- bugfix
- title: 🚀 New Features
labels:
- new-feature
- title: 💡 Improvements
labels:
- improvement
- title: 🧪 Testing Improvements
labels:
- testing
- title: ⚙️ Repo/CI Improvements
labels:
- repo-ci-improvement
- title: 📖 Documentation
labels:
- documentation
- title: 📦 Dependency Updates
labels:
- dependencies
- title: Other Changes
labels:
- "*"
32 changes: 12 additions & 20 deletions .github/workflows/publish-wiki.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
name: Publish Wiki

name: Publish wiki
on:
push:
branches: [main]

paths:
- wiki/**
- .github/workflows/publish-wiki.yml
concurrency:
group: publish-wiki
cancel-in-progress: true
permissions:
contents: write
jobs:
build:
publish-wiki:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Generate App Installation Token
id: generate_token
uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 # pin@v1
with:
app_id: ${{ secrets.CLI_RELEASE_APP_ID }}
private_key: ${{ secrets.CLI_RELEASE_PRIVATE_KEY }}
repository: linode/linode-cli

- name: Upload Documentation to Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: "wiki"
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ steps.generate_token.outputs.token }}
- uses: actions/checkout@v4
- uses: Andrew-Chen-Wang/github-wiki-action@50650fccf3a10f741995523cf9708c53cec8912a # [email protected]
16 changes: 0 additions & 16 deletions .github/workflows/release-drafter.yml

This file was deleted.

1 change: 1 addition & 0 deletions linodecli/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Launches the CLI
"""

from linodecli import main

main()
67 changes: 49 additions & 18 deletions linodecli/api_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
import sys
import time
from sys import version_info
from typing import Iterable, List, Optional
from typing import Any, Iterable, List, Optional

import requests
from packaging import version
from requests import Response

from linodecli.helpers import API_CA_PATH

from .baked.operation import ExplicitNullValue, OpenAPIOperation
from .baked.operation import (
ExplicitEmptyListValue,
ExplicitNullValue,
OpenAPIOperation,
)
from .helpers import handle_url_overrides


Expand Down Expand Up @@ -199,6 +203,47 @@ def _build_request_url(ctx, operation, parsed_args) -> str:
return result


def _traverse_request_body(o: Any) -> Any:
"""
This function traverses is intended to be called immediately before
request body serialization and contains special handling for dropping
keys with null values and translating ExplicitNullValue instances into
serializable null values.
"""
if isinstance(o, dict):
result = {}
for k, v in o.items():
# Implicit null values should be dropped from the request
if v is None:
continue

# Values that are expected to be serialized as empty lists
# and explicit None values are converted here.
# See: operation.py
# NOTE: These aren't handled at the top-level of this function
# because we don't want them filtered out in the step below.
if isinstance(v, ExplicitEmptyListValue):
result[k] = []
continue

if isinstance(v, ExplicitNullValue):
result[k] = None
continue

value = _traverse_request_body(v)

# We should exclude implicit empty lists
if not (isinstance(value, (dict, list)) and len(value) < 1):
result[k] = value

return result

if isinstance(o, list):
return [_traverse_request_body(v) for v in o]

return o


def _build_request_body(ctx, operation, parsed_args) -> Optional[str]:
if operation.method == "get":
# Get operations don't have a body
Expand All @@ -208,32 +253,18 @@ def _build_request_body(ctx, operation, parsed_args) -> Optional[str]:
if ctx.defaults:
parsed_args = ctx.config.update(parsed_args, operation.allowed_defaults)

to_json = {}

for k, v in vars(parsed_args).items():
# Skip null values
if v is None:
continue

# Explicitly include ExplicitNullValues
if isinstance(v, ExplicitNullValue):
to_json[k] = None
continue

to_json[k] = v

expanded_json = {}

# expand paths
for k, v in to_json.items():
for k, v in vars(parsed_args).items():
cur = expanded_json
for part in k.split(".")[:-1]:
if part not in cur:
cur[part] = {}
cur = cur[part]
cur[k.split(".")[-1]] = v

return json.dumps(expanded_json)
return json.dumps(_traverse_request_body(expanded_json))


def _print_request_debug_info(method, url, headers, body):
Expand Down
1 change: 1 addition & 0 deletions linodecli/baked/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
Collection of classes for handling the parsed OpenAPI Spec for the CLI
"""

from .operation import OpenAPIOperation
1 change: 1 addition & 0 deletions linodecli/baked/colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Applies shell color escapes for pretty printing
"""

import os
import platform

Expand Down
16 changes: 15 additions & 1 deletion linodecli/baked/operation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
CLI Operation logic
"""

import argparse
import glob
import json
Expand Down Expand Up @@ -60,6 +61,12 @@ class ExplicitNullValue:
"""


class ExplicitEmptyListValue:
"""
A special type used to explicitly pass empty lists to the API.
"""


def wrap_parse_nullable_value(arg_type):
"""
A helper function to parse `null` as None for nullable CLI args.
Expand Down Expand Up @@ -91,9 +98,16 @@ def __call__(self, parser, namespace, values, option_string=None):

output_list = getattr(namespace, self.dest)

# If a user has already specified an [] but is specifying
# another value, assume "[]" was intended to be a literal.
if isinstance(output_list, ExplicitEmptyListValue):
setattr(namespace, self.dest, ["[]", values])
return

# If the output list is empty and the user specifies a []
# argument, keep the list empty
# argument, set the list to an explicitly empty list.
if values == "[]" and len(output_list) < 1:
setattr(namespace, self.dest, ExplicitEmptyListValue())
return

output_list.append(values)
Expand Down
1 change: 1 addition & 0 deletions linodecli/baked/response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Converting the processed OpenAPI Responses into something the CLI can work with
"""

from openapi3.paths import MediaType

from .colors import colorize_string
Expand Down
9 changes: 6 additions & 3 deletions linodecli/output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Handles formatting the output of commands used in Linode CLI
"""

import copy
import json
from enum import Enum
Expand Down Expand Up @@ -157,9 +158,11 @@ def print_response(
continue

self.print(
self._scope_data_to_subtable(data, table_name)
if table_name is not None
else data,
(
self._scope_data_to_subtable(data, table_name)
if table_name is not None
else data
),
self._get_columns(table_attrs),
title=table_name,
to=to,
Expand Down
1 change: 1 addition & 0 deletions linodecli/overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This allows us to easily alter per-command outputs, etc. without making
large changes to the OpenAPI spec.
"""

from typing import Dict

from rich.align import Align
Expand Down
1 change: 1 addition & 0 deletions linodecli/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Initialize plugins for the CLI
"""

import sys
from argparse import ArgumentParser
from importlib import import_module
Expand Down
1 change: 1 addition & 0 deletions linodecli/plugins/obj/buckets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
The bucket manipulation module of CLI Plugin for handling object storage
"""

import sys
from argparse import ArgumentParser

Expand Down
1 change: 1 addition & 0 deletions linodecli/plugins/obj/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
The config of the object storage plugin.
"""

import shutil

ENV_ACCESS_KEY_NAME = "LINODE_CLI_OBJ_ACCESS_KEY"
Expand Down
1 change: 1 addition & 0 deletions linodecli/plugins/obj/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
The helper functions for the object storage plugin.
"""

from argparse import ArgumentTypeError
from datetime import datetime

Expand Down
1 change: 1 addition & 0 deletions linodecli/plugins/obj/objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
The object manipulation module of CLI Plugin for handling object storage
"""

import platform
import sys
from argparse import ArgumentParser
Expand Down
1 change: 1 addition & 0 deletions linodecli/plugins/region-table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
The region-table plugin displays a table output
for the capabilities of each region.
"""

import sys

from rich.align import Align
Expand Down
4 changes: 4 additions & 0 deletions tests/fixtures/api_request_test_foobar_post.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ components:
field_int:
type: number
description: An arbitrary field.
nullable_string:
type: string
description: An arbitrary nullable string.
nullable: true
Loading

0 comments on commit 72c723f

Please sign in to comment.