Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds support for authenticating with access token #20

Merged
merged 10 commits into from
Aug 23, 2023
Merged
98 changes: 68 additions & 30 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.5",
"@octopusdeploy/api-client": "^3.1.0",
"tmp": "^0.2.1"
},
"description": "GitHub Action to Create a Release in Octopus Deploy",
Expand Down Expand Up @@ -85,4 +85,4 @@
"test:integration": "jest --ci --reporters=default --reporters=jest-junit --testPathPattern=__tests__/integration"
},
"version": "3.0.0"
}
}
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 { waitForTask } from './api-wrapper'
userAgentApp: 'GitHubActions await-task-action',
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 @@ -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 Down Expand Up @@ -47,7 +50,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] || '',
serverTaskId: getInput('server_task_id', { required: true }),
pollingInterval,
Expand All @@ -58,17 +62,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