Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{Core} Fix #24542: Support JMESPath Community dependencies and assets. #25590

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ LABEL maintainer="Microsoft" \
# openssh - included for ssh-keygen
# ca-certificates

# curl - required for installing jp
# wget - required for installing jp
springcomp marked this conversation as resolved.
Show resolved Hide resolved
# jq - we include jq as a useful tool
# pip wheel - required for CLI packaging
# jmespath-terminal - we include jpterm as a useful tool
# jmespath-community-terminal - we include jpterm as a useful tool
# libintl and icu-libs - required by azure devops artifact (az extension add --name azure-devops)

# We don't use openssl (3.0) for now. We only install it so that users can use it.
Expand All @@ -44,10 +44,11 @@ RUN apk add --no-cache bash openssh ca-certificates jq curl openssl openssl1.1-c
&& apk add --no-cache bash-completion \
&& update-ca-certificates

ARG JP_VERSION="0.1.3"
ARG JP_VERSION="1.1.0"

RUN curl -L https://github.com/jmespath/jp/releases/download/${JP_VERSION}/jp-linux-amd64 -o /usr/local/bin/jp \
&& chmod +x /usr/local/bin/jp
RUN curl -L https://github.com/jmespath-community/jp/releases/download/v${JP_VERSION}/jp-linux-amd64 -o /usr/local/bin/jp \
&& chmod +x /usr/local/bin/jp \
&& pip install --no-cache-dir --upgrade jmespath-community-terminal

WORKDIR azure-cli
COPY . /azure-cli
Expand Down
12 changes: 6 additions & 6 deletions Dockerfile.spot
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
# This allows Spots to be created directly from PRs.
# The major difference between Dockerfile.spot and Dockerfile is the latter depends on alpine and this one does not.

ARG PYTHON_VERSION="3.6.4"
ARG PYTHON_VERSION="3.7.16"

FROM python:$PYTHON_VERSION

RUN apt-get install -y ca-certificates curl openssl git \
&& apt-get install -y gcc make libffi-dev \
&& update-ca-certificates

ARG JP_VERSION="0.1.3"
ARG JP_VERSION="1.1.0"

RUN curl https://github.com/jmespath/jp/releases/download/${JP_VERSION}/jp-linux-amd64 -o /usr/local/bin/jp \
RUN wget https://github.com/jmespath-community/jp/releases/download/v${JP_VERSION}/jp-linux-amd64 -O /usr/local/bin/jp \
&& chmod +x /usr/local/bin/jp \
&& pip install --no-cache-dir --upgrade jmespath-terminal
&& pip install --no-cache-dir --upgrade jmespath-community-terminal

WORKDIR azure-cli
COPY . /azure-cli
Expand All @@ -28,9 +28,9 @@ COPY . /azure-cli
# openssh - included for ssh-keygen
# ca-certificates

# curl - required for installing jp
# wget - required for installing jp
# pip wheel - required for CLI packaging
# jmespath-terminal - we include jpterm as a useful tool
# jmespath-community-terminal - we include jpterm as a useful tool
# 1. Build packages and store in tmp dir
# 2. Install the cli and the other command modules that weren't included
RUN /bin/bash -c 'TMP_PKG_DIR=$(mktemp -d); \
Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2262,7 +2262,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI

---------------------------------------------------------

jmespath 0.10.0 - MIT
jmespath-community 1.1.0 - MIT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the copyright of jmespath-community still belong to Amazon?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have forked the repository, so I’m not sure what is the best practice.
Also, I’m not familiar at all with respect to licenses and copyright 😱.

What do you think in your experience ?



Copyright (c) 2013 Amazon.com, Inc.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ $ az vm show -g WebPropertiesRG -n Bizlogic

#### Query

You can use the `--query` parameter and the [JMESPath](http://jmespath.org/) query syntax to customize your output.
You can use the `--query` parameter and the [JMESPath](http://jmespath.site/main) query syntax to customize your output.

```bash
$ az vm list --query "[?provisioningState=='Succeeded'].{ name: name, os: storageProfile.osDisk.osType }"
Expand Down
52 changes: 26 additions & 26 deletions build_scripts/windows/resources/ThirdPartyNotices.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion doc/authoring_tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class StorageAccountTests(ScenarioTest):

Notes:

1. The first argument in the `check` method is a JMESPath query. [JMESPath is a query language for JSON](http://jmespath.org/).
1. The first argument in the `check` method is a JMESPath query. [JMESPath is a query language for JSON](http://jmespath.site/main/).
2. If a command returns JSON, multiple JMESPath based checks can be added to the checks list to validate the result.
3. In addition to the `check` method, there are other checks like `is_empty` which validate the output is `None`. The check mechanism is extensible. Any callable accepting a single `ExecutionResult` argument can act as a check: see [checkers.py](https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-testsdk/azure/cli/testsdk/checkers.py).

Expand Down
2 changes: 1 addition & 1 deletion doc/classic_cli_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ $ azure vm list --json \
$ MY_SUBSCRIPTION_ID=$(azure account show --json | jq -r '.[0].id')
```

With the Azure CLI, you can now use the `--query '[expression]'` parameter and the [JMESPath](http://jmespath.org/)
With the Azure CLI, you can now use the `--query '[expression]'` parameter and the [JMESPath](http://jmespath.site/main)
query language to extract values.

```azurecli
Expand Down
6 changes: 4 additions & 2 deletions src/azure-cli-core/azure/cli/core/commands/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,12 @@ def show_exception_handler(ex):


def verify_property(instance, condition):
from jmespath import Options
from jmespath import compile as compile_jmespath
options = Options(dict_cls=OrderedDict, enable_legacy_literals=True)
result = todict(instance)
jmes_query = compile_jmespath(condition)
value = jmes_query.search(result)
jmes_query = compile_jmespath(condition, options)
value = jmes_query.search(result, options)
return value


Expand Down
20 changes: 15 additions & 5 deletions src/azure-cli-testsdk/azure/cli/testsdk/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def __call__(self, execution_result):
actual_result = None
try:
actual_result = jmespath.search(self._query, json_value,
jmespath.Options(collections.OrderedDict))
jmespath.Options(
collections.OrderedDict,
enable_legacy_literals=True))
except jmespath.exceptions.JMESPathTypeError:
raise JMESPathCheckAssertionError(self._query, self._expected_result, actual_result,
execution_result.output)
Expand All @@ -44,7 +46,9 @@ def __init__(self, query):
def __call__(self, execution_result):
json_value = execution_result.get_output_in_json()
actual_result = jmespath.search(self._query, json_value,
jmespath.Options(collections.OrderedDict))
jmespath.Options(
collections.OrderedDict,
enable_legacy_literals=True))
if not actual_result:
raise JMESPathCheckAssertionError(self._query, 'some value', actual_result,
execution_result.output)
Expand All @@ -57,7 +61,9 @@ def __init__(self, query):
def __call__(self, execution_result):
json_value = execution_result.get_output_in_json()
actual_result = jmespath.search(self._query, json_value,
jmespath.Options(collections.OrderedDict))
jmespath.Options(
collections.OrderedDict,
enable_legacy_literals=True))
if actual_result:
raise JMESPathCheckAssertionError(self._query, 'some value', actual_result,
execution_result.output)
Expand All @@ -71,7 +77,9 @@ def __init__(self, query, expected_result):
def __call__(self, execution_result):
json_value = execution_result.get_output_in_json()
actual_result = jmespath.search(self._query, json_value,
jmespath.Options(collections.OrderedDict))
jmespath.Options(
collections.OrderedDict,
enable_legacy_literals=True))
if not actual_result > self._expected_result:
expected_result_format = "> {}".format(self._expected_result)

Expand All @@ -90,7 +98,9 @@ def __init__(self, query, expected_result):
def __call__(self, execution_result):
json_value = execution_result.get_output_in_json()
actual_result = jmespath.search(self._query, json_value,
jmespath.Options(collections.OrderedDict))
jmespath.Options(
collections.OrderedDict,
enable_legacy_literals=True))
if not re.match(self._expected_result, str(actual_result), re.IGNORECASE):
raise JMESPathCheckAssertionError(self._query, self._expected_result, actual_result,
execution_result.output)
Expand Down
31 changes: 20 additions & 11 deletions src/azure-cli/azure/cli/command_modules/acs/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ def _aks_agentpool_table_format(result):
maxPods: maxPods,
provisioningState: provisioningState,
mode: mode
}""")
}""", Options(enable_legacy_literals=True))
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict))
# enable compatibility with legacy JSON literals
return parsed.search(result,
Options(dict_cls=OrderedDict, enable_legacy_literals=True))


def aks_agentpool_list_table_format(results):
Expand Down Expand Up @@ -70,9 +72,11 @@ def _aks_table_format(result):
currentKubernetesVersion: currentKubernetesVersion,
provisioningState: provisioningState,
fqdn: fqdn || privateFqdn
}""")
}""", Options(enable_legacy_literals=True))
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict))
# enable compatibility with legacy JSON literals
return parsed.search(result,
Options(dict_cls=OrderedDict, enable_legacy_literals=True))


def aks_upgrades_table_format(result):
Expand All @@ -92,9 +96,11 @@ def find_preview_versions(versions_bag):
resourceGroup: resourceGroup,
masterVersion: controlPlaneProfile.kubernetesVersion || `unknown`,
upgrades: controlPlaneProfile.upgrades[].kubernetesVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)
}""")
}""", Options(enable_legacy_literals=True))
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
# enable compatibility with legacy JSON literals
return parsed.search(result,
Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview), enable_legacy_literals=True))


def aks_versions_table_format(result):
Expand All @@ -111,11 +117,12 @@ def find_preview_versions():
parsed = compile_jmes("""orchestrators[].{
kubernetesVersion: orchestratorVersion | set_preview(@),
upgrades: upgrades[].orchestratorVersion || [`None available`] | sort_versions(@) | set_preview_array(@) | join(`, `, @)
}""")
}""", Options(enable_legacy_literals=True))

# use ordered dicts so headers are predictable
results = parsed.search(result, Options(
dict_cls=OrderedDict, custom_functions=_custom_functions(preview)))
# enable compatibility with legacy JSON literals
return parsed.search(result,
Options(dict_cls=OrderedDict, custom_functions=_custom_functions(preview), enable_legacy_literals=True))
return sorted(results, key=lambda x: version_to_tuple(x.get('kubernetesVersion')), reverse=True)


Expand All @@ -138,9 +145,11 @@ def _aks_nodepool_snapshot_table_format(result):
kubernetesVersion: kubernetesVersion,
osType: osType,
enableFIPS: enableFIPS
}""")
}""", Options(enable_legacy_literals=True))
# use ordered dicts so headers are predictable
return parsed.search(result, Options(dict_cls=OrderedDict))
# enable compatibility with legacy JSON literals
return parsed.search(result,
Options(dict_cls=OrderedDict, enable_legacy_literals=True))


def version_to_tuple(version):
Expand Down
Loading