Skip to content

Commit

Permalink
feat: Adds support for authenticating using an access token (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
geofflamrock authored Aug 23, 2023
1 parent 0eb8e14 commit a99a39a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 34 deletions.
4 changes: 1 addition & 3 deletions __tests__/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,7 @@ describe('integration tests', () => {
60000,
(serverTask: ServerTask): void => {
// eslint-disable-next-line no-console
console.log(
`Waiting for task ${serverTask.Id}. Current status: ${serverTask.State}`
)
console.log(`Waiting for task ${serverTask.Id}. Current status: ${serverTask.State}`)
}
)
})
Expand Down
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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
"dependencies": {
"@actions/core": "^1.10.0",
"@octopusdeploy/api-client": "^3.0.7"
"@octopusdeploy/api-client": "^3.1.0"
},
"description": "GitHub Action to Create a Release in Octopus Deploy",
"devDependencies": {
Expand Down Expand Up @@ -85,4 +85,4 @@
"test:integration": "jest --ci --reporters=default --reporters=jest-junit --testPathPattern=__tests__/integration"
},
"version": "3.0.4"
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { createDeploymentFromInputs } from './api-wrapper'
userAgentApp: 'GitHubActions (release;deploy;v3)',
instanceURL: parameters.server,
apiKey: parameters.apiKey,
accessToken: parameters.accessToken,
logging: logger
}

Expand Down
18 changes: 12 additions & 6 deletions src/input-parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import { PromptedVariableValues } from '@octopusdeploy/api-client'
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 @@ -37,7 +40,8 @@ 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', { required: true }),
Expand All @@ -49,17 +53,19 @@ 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."
)
}

Expand Down

0 comments on commit a99a39a

Please sign in to comment.