Skip to content

Commit

Permalink
feat: Adds support for authenticating with access token (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
geofflamrock committed Aug 23, 2023
1 parent 0c9ada0 commit a28e03d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 30 deletions.
63 changes: 47 additions & 16 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@actions/core": "^1.10.0",
"@octopusdeploy/api-client": "^3.0.7",
"@octopusdeploy/api-client": "^3.1.0",
"tmp": "^0.2.1"
},
"description": "GitHub Action to Create a Release in Octopus Deploy",
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -30,6 +30,7 @@ import { createReleaseFromInputs } from './api-wrapper'
userAgentApp: 'GitHubActions (release;create;v3)',
instanceURL: parameters.server,
apiKey: parameters.apiKey,
accessToken: parameters.accessToken,
logging: logger
}

Expand Down
19 changes: 13 additions & 6 deletions src/input-parameters.ts
Expand Up @@ -3,14 +3,17 @@ import { getBooleanInput, getInput, getMultilineInput } from '@actions/core'
const EnvironmentVariables = {
URL: 'OCTOPUS_URL',
ApiKey: 'OCTOPUS_API_KEY',
AccessToken: 'OCTOPUS_ACCESS_TOKEN',
Space: 'OCTOPUS_SPACE'
} as const

export interface InputParameters {
// Optional: A server is required, but you should use the OCTOPUS_URL env
server: string
// Optional: An API key is required, but you should use the OCTOPUS_API_KEY environment variable instead of this.
apiKey: string
apiKey?: string
// Optional: Access token can only be obtained from the OCTOPUS_ACCESS_TOKEN environment variable.
accessToken?: string
// Optional: You should prefer the OCTOPUS_SPACE environment variable
space: string
// Required
Expand All @@ -31,7 +34,8 @@ export interface InputParameters {
export function getInputParameters(): InputParameters {
const parameters: InputParameters = {
server: getInput('server') || process.env[EnvironmentVariables.URL] || '',
apiKey: getInput('api_key') || process.env[EnvironmentVariables.ApiKey] || '',
apiKey: getInput('api_key') || process.env[EnvironmentVariables.ApiKey],
accessToken: process.env[EnvironmentVariables.AccessToken],
space: getInput('space') || process.env[EnvironmentVariables.Space] || '',
project: getInput('project', { required: true }),
releaseNumber: getInput('release_number') || undefined,
Expand All @@ -48,19 +52,22 @@ export function getInputParameters(): InputParameters {
const errors: string[] = []
if (!parameters.server) {
errors.push(
"The Octopus instance URL is required, please specify explictly through the 'server' input or set the OCTOPUS_URL environment variable."
"The Octopus instance URL is required, please specify explicitly through the 'server' input or set the OCTOPUS_URL environment variable."
)
}
if (!parameters.apiKey) {

if (!parameters.apiKey && !parameters.accessToken) {
errors.push(
"The Octopus API Key is required, please specify explictly through the 'api_key' input or set the OCTOPUS_API_KEY environment variable."
"The Octopus API Key is required, please specify explicitly through the 'api_key' input or set the OCTOPUS_API_KEY environment variable."
)
}

if (!parameters.space) {
errors.push(
"The Octopus space name is required, please specify explictly through the 'space' input or set the OCTOPUS_SPACE environment variable."
"The Octopus space name is required, please specify explicitly through the 'space' input or set the OCTOPUS_SPACE environment variable."
)
}

if (parameters.releaseNotes && parameters.releaseNotesFile) {
errors.push(
'Please specify one or other of `release_notes` and `release_notes_files`. Specifying both is not supported.'
Expand Down

0 comments on commit a28e03d

Please sign in to comment.