vultr / vultr-cli

Official command line tool for Vultr services
Apache License 2.0
478 stars 76 forks source link

Allow some commands to be run without authenticating against the API #364

Closed optik-aper closed 1 year ago

optik-aper commented 1 year ago

Description

These changes re-work some of the authentication logic used to pass the API key when executing commands. Before this, ALL commands authenticated with this key, even the version command. This PR moves the client logic to allow setting a basic HTTP client without bearer tokens. It also moves the missing API key check so that it happens in a pre-Execute check on each top-level command. This check cascades down to all of its children.

Related Issues

closes #359

332

92

Testing

All of which should show something along the lines of:

Error:
Please export your VULTR API key as an environment variable or add 'api-key' to your config file, eg:
export VULTR_API_KEY='<api_key_from_vultr_account>'

Usage:
  vultr-cli database list [flags]

Aliases:
  list, l

Examples:

        # Full example
        vultr-cli database list

        # Summarized view
        vultr-cli database list --summarize

Flags:
  -h, --help            help for list
  -l, --label string    (optional) Filter by label.
  -r, --region string   (optional) Filter by region.
      --summarize       (optional) Summarize the list output. One line per database.
  -t, --tag string      (optional) Filter by tag.

Global Flags:
      --config string   config file (default is $HOME/.vultr-cli.yaml) (default "/home/michael/.vultr-cli.yaml")

exit status 1

Conversely, these should still return data:

Checklist:

github-actions[bot] commented 1 year ago

Unit Tests and Coverage

Show Output ``` ? github.com/vultr/vultr-cli/v2 [no test files] ```

Pusher: @optik-aper, Action: pull_request_target

github-actions[bot] commented 1 year ago

Unit Tests and Coverage

Show Output ``` ? github.com/vultr/vultr-cli/v2 [no test files] ```

Pusher: @optik-aper, Action: pull_request_target

github-actions[bot] commented 1 year ago

Unit Tests and Coverage

Show Output ``` ? github.com/vultr/vultr-cli/v2 [no test files] ```

Pusher: @optik-aper, Action: pull_request_target

github-actions[bot] commented 1 year ago

Unit Tests and Coverage

Show Output ``` ? github.com/vultr/vultr-cli/v2 [no test files] ```

Pusher: @optik-aper, Action: pull_request_target