Skip to content

Commit

Permalink
feat(cli): Add --output option to config show to support json (aws-de…
Browse files Browse the repository at this point in the history
…adline#586)

Signed-off-by: Alex Hughes <[email protected]>
  • Loading branch information
Ahuge authored Feb 7, 2025
1 parent 96055c6 commit 7c63ca1
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 27 deletions.
31 changes: 20 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ This library requires:

## Versioning

This package's version follows [Semantic Versioning 2.0](https://semver.org/), but is still considered to be in its
This package's version follows [Semantic Versioning 2.0](https://semver.org/), but is still considered to be in its
initial development, thus backwards incompatible versions are denoted by minor version bumps. To help illustrate how
versions will increment during this initial development stage, they are described below:

1. The MAJOR version is currently 0, indicating initial development.
2. The MINOR version is currently incremented when backwards incompatible changes are introduced to the public API.
3. The PATCH version is currently incremented when bug fixes or backwards compatible changes are introduced to the public API.
1. The MAJOR version is currently 0, indicating initial development.
2. The MINOR version is currently incremented when backwards incompatible changes are introduced to the public API.
3. The PATCH version is currently incremented when bug fixes or backwards compatible changes are introduced to the public API.

## Contributing

We welcome all contributions. Please see [CONTRIBUTING.md](https://github.com/aws-deadline/deadline-cloud/blob/mainline/CONTRIBUTING.md)
for guidance on how to contribute. Please report issues such as bugs, inaccurate or confusing information, and so on,
by making feature requests in the [issue tracker](https://github.com/aws-deadline/deadline-cloud/issues). We encourage
code contributions in the form of [pull requests](https://github.com/aws-deadline/deadline-cloud/pulls).
code contributions in the form of [pull requests](https://github.com/aws-deadline/deadline-cloud/pulls).

## Getting Started

Expand Down Expand Up @@ -79,7 +79,7 @@ api.list_farms()
```

## Job-related Files
For job-related files and data, AWS Deadline Cloud supports either transferring files to AWS using job attachments or reading files from network storage that is shared between both your local workstation and your farm.
For job-related files and data, AWS Deadline Cloud supports either transferring files to AWS using job attachments or reading files from network storage that is shared between both your local workstation and your farm.

### Job attachments

Expand Down Expand Up @@ -140,6 +140,15 @@ $ deadline config show
```
and change the settings by running the associated `get`, `set` and `clear` commands.

If you need to parse the settings as json, you can specify the output by running:
```sh
$ deadline config show --output json
```
Which will output:
```sh
{"settings.config_file_path": "~/.deadline/config", "deadline-cloud-monitor.path": "", "defaults.aws_profile_name": "(default)", "settings.job_history_dir": "~/.deadline/job_history/(default)", "defaults.farm_id": "", "settings.storage_profile_id": "", "defaults.queue_id": "", "defaults.job_id": "", "settings.auto_accept": "false", "settings.conflict_resolution": "NOT_SELECTED", "settings.log_level": "WARNING", "telemetry.opt_out": "false", "telemetry.identifier": "00000000-0000-0000-0000-000000000000", "defaults.job_attachments_file_system": "COPIED", "settings.s3_max_pool_connections": "50", "settings.small_file_threshold_multiplier": "20"}
```

To see a list of settings that can be configured, run:
```sh
$ deadline config --help
Expand Down Expand Up @@ -185,18 +194,18 @@ [email protected] with any additional questions or comments.

## Security Issue Notifications

We take all security reports seriously. When we receive such reports, we will
investigate and subsequently address any potential vulnerabilities as quickly
as possible. If you discover a potential security issue in this project, please
We take all security reports seriously. When we receive such reports, we will
investigate and subsequently address any potential vulnerabilities as quickly
as possible. If you discover a potential security issue in this project, please
notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/)
or directly via email to [AWS Security](mailto:[email protected]). Please do not
or directly via email to [AWS Security](mailto:[email protected]). Please do not
create a public GitHub issue in this project.

## Telemetry

See [telemetry](https://github.com/aws-deadline/deadline-cloud/blob/release/docs/telemetry.md) for more information.

## License
## License

This project is licensed under the Apache-2.0 License.

Expand Down
48 changes: 32 additions & 16 deletions src/deadline/client/cli/_groups/config_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import click
import json
import textwrap

from ...config import config_file
Expand All @@ -20,29 +21,44 @@ def cli_config():


@cli_config.command(name="show")
@click.option(
"--output",
type=click.Choice(["verbose", "json"], case_sensitive=False),
default="verbose",
help="Output format of the command",
)
@_handle_error
def config_show():
def config_show(output):
"""
Show all workstation configuration settings and current values.
"""
click.echo(f"AWS Deadline Cloud configuration file:\n {config_file.get_config_file_path()}")
click.echo()

for setting_name in config_file.SETTINGS.keys():
setting_value = config_file.get_setting(setting_name)
setting_default = config_file.get_setting_default(setting_name)

# Wrap and indent the descriptions to 80 characters because they may be multiline.
setting_description: str = config_file.SETTINGS[setting_name].get("description", "")
setting_description = "\n".join(
f" {line}" for line in textwrap.wrap(setting_description, width=77)
)

settings_json = {}
if output == "verbose":
click.echo(
f"{setting_name}: {setting_value} {'(default)' if setting_value == setting_default else ''}"
f"AWS Deadline Cloud configuration file:\n {config_file.get_config_file_path()}"
)
click.echo(setting_description)
click.echo()
for setting_name in config_file.SETTINGS.keys():
setting_value = config_file.get_setting(setting_name)
setting_default = config_file.get_setting_default(setting_name)

# Wrap and indent the descriptions to 80 characters because they may be multiline.
setting_description: str = config_file.SETTINGS[setting_name].get("description", "")
setting_description = "\n".join(
f" {line}" for line in textwrap.wrap(setting_description, width=77)
)
click.echo(
f"{setting_name}: {setting_value} {'(default)' if setting_value == setting_default else ''}"
)
click.echo(setting_description)
click.echo()
else:
settings_json["settings.config_file_path"] = str(config_file.get_config_file_path())
for setting_name in config_file.SETTINGS.keys():
setting_value = config_file.get_setting(setting_name)
settings_json[setting_name] = setting_value

click.echo(json.dumps(settings_json))


@cli_config.command(name="gui")
Expand Down
19 changes: 19 additions & 0 deletions test/unit/deadline_client/cli/test_cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import importlib
import json
import logging
from unittest.mock import patch

Expand Down Expand Up @@ -127,6 +128,24 @@ def test_cli_config_show_modified_config(fresh_deadline_config):
assert "(default)" not in result.output


def test_cli_config_show_json_output(fresh_deadline_config):
"""
Confirm that the CLI interface prints out all the configuration
file data, when the configuration is default
"""
runner = CliRunner()
result = runner.invoke(main, ["config", "show", "--output", "json"])

assert result.exit_code == 0

expected_output = {}
for setting_name in config.config_file.SETTINGS.keys():
expected_output[setting_name] = config.config_file.get_setting(setting_name)
expected_output["settings.config_file_path"] = str(config.config_file.get_config_file_path())

assert json.loads(result.output) == expected_output


@pytest.mark.parametrize("setting_name,default_value,alternate_value", CONFIG_SETTING_ROUND_TRIP)
def test_config_settings_via_cli_roundtrip(
fresh_deadline_config, setting_name, default_value, alternate_value
Expand Down

0 comments on commit 7c63ca1

Please sign in to comment.