Skip to content

Commit

Permalink
Add no_auth input to skip Authentication (Fixes digitalocean#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
trinitronx committed Oct 21, 2023
1 parent cf10ddb commit 9c70d8c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
20 changes: 20 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ jobs:
- name: Verify log-in
run: doctl compute region list

test_no_auth:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
steps:
- uses: actions/checkout@master

- name: Install doctl
uses: ./
with:
no_auth: true

- name: Verify installation
run: doctl version

- name: Verify not authenticated
run: |
doctl compute region list 2>&1 | grep -qi "Unable to initialize DigitalOcean API client: access token is required"
test_custom_version_linux_and_mac:
runs-on: ${{ matrix.os }}
strategy:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ See [this repository](https://github.com/do-community/example-doctl-action) for

- `token` – (**Required**) A DigitalOcean personal access token ([more info](https://docs.digitalocean.com/reference/api/create-personal-access-token/)).
- `version` – (Optional) The version of `doctl` to install. If excluded, the latest release will be used.
- `no_auth` – (Optional) Set to `true` to skip the authentication step. The API `token` parameter is _Optional_ in this case.
- _Note:_ This can be useful when running in workflows in untrusted environments, or where auth isn't necessary (e.g. `doctl app spec validate`)

## Contributing

Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ inputs:
version:
description: 'Version of doctl to install'
default: 'latest'
no_auth:
description: 'Skip authentication'
default: 'false'
token:
description: 'DigitalOcean API Token'
required: true
default: ''
runs:
using: 'node16'
main: 'dist/index.js'
8 changes: 8 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ Failed to retrieve latest version; falling back to: ${fallbackVersion}`);
core.addPath(path);
core.info(`>>> doctl version v${version} installed to ${path}`);

// Skip authentication if requested
// for workflows where auth isn't necessary (e.g. doctl app spec validate)
var no_auth = core.getInput('no_auth');
if (no_auth.toLowerCase() === 'true') {
core.info('>>> Skipping doctl auth');
return;
}

var token = core.getInput('token', { required: true });
core.setSecret(token);
await exec.exec('doctl auth init -t', [token]);
Expand Down

0 comments on commit 9c70d8c

Please sign in to comment.