diff --git a/dist/index.js b/dist/index.js index 68e0d02b..866664a4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1829,11 +1829,12 @@ Object.defineProperty(exports, "__esModule", ({ value: true })); exports.AxiosAdapter = void 0; var axios_1 = __importDefault(__nccwpck_require__(8757)); var adapter_1 = __nccwpck_require__(937); +var createRequestHeaders_1 = __nccwpck_require__(7843); var AxiosAdapter = /** @class */ (function () { function AxiosAdapter() { } AxiosAdapter.prototype.execute = function (options) { - var _a, _b; + var _a; return __awaiter(this, void 0, void 0, function () { function formatError(response) { if (!response.data) { @@ -1841,6 +1842,7 @@ var AxiosAdapter = /** @class */ (function () { } var message = response.data.ErrorMessage; if (response.data.Errors) { + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions var errors = response.data.Errors; for (var i = 0; i < errors.length; i++) { message += "\n".concat(errors[i]); @@ -1849,21 +1851,19 @@ var AxiosAdapter = /** @class */ (function () { return message; } var config, userAgent, response, error_1; - return __generator(this, function (_c) { - switch (_c.label) { + return __generator(this, function (_b) { + switch (_b.label) { case 0: - _c.trys.push([0, 2, , 3]); + _b.trys.push([0, 2, , 3]); config = { httpsAgent: options.configuration.httpsAgent, url: options.url, maxContentLength: Infinity, maxBodyLength: Infinity, + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions method: options.method, data: options.requestBody, - headers: { - "Accept-Encoding": "gzip,deflate,compress", - "X-Octopus-ApiKey": (_a = options.configuration.apiKey) !== null && _a !== void 0 ? _a : "", - }, + headers: (0, createRequestHeaders_1.createRequestHeaders)(options.configuration), responseType: "json", }; if (typeof XMLHttpRequest === "undefined") { @@ -1877,15 +1877,15 @@ var AxiosAdapter = /** @class */ (function () { } return [4 /*yield*/, axios_1.default.request(config)]; case 1: - response = _c.sent(); + response = _b.sent(); return [2 /*return*/, { data: response.data, statusCode: response.status, }]; case 2: - error_1 = _c.sent(); + error_1 = _b.sent(); if (axios_1.default.isAxiosError(error_1) && error_1.response) { - throw new adapter_1.AdapterError(error_1.response.status, (_b = formatError(error_1.response)) !== null && _b !== void 0 ? _b : error_1.message); + throw new adapter_1.AdapterError(error_1.response.status, (_a = formatError(error_1.response)) !== null && _a !== void 0 ? _a : error_1.message); } else { throw error_1; @@ -1901,6 +1901,34 @@ var AxiosAdapter = /** @class */ (function () { exports.AxiosAdapter = AxiosAdapter; +/***/ }), + +/***/ 7843: +/***/ ((__unused_webpack_module, exports) => { + +"use strict"; + +Object.defineProperty(exports, "__esModule", ({ value: true })); +exports.createRequestHeaders = void 0; +function createRequestHeaders(configuration) { + var headers = { + "Accept-Encoding": "gzip,deflate,compress", // HACK: required for https://github.com/axios/axios/issues/5346 -- this line can be removed once this bug has been fixed + }; + if (configuration.apiKey) { + headers["X-Octopus-ApiKey"] = configuration.apiKey; + } + if (configuration.accessToken) { + headers["Authorization"] = "Bearer ".concat(configuration.accessToken); + } + if (!configuration.accessToken && !configuration.apiKey) { + // Backward compatibility: Add the api key header in with a blank value + headers["X-Octopus-ApiKey"] = ""; + } + return headers; +} +exports.createRequestHeaders = createRequestHeaders; + + /***/ }), /***/ 1542: @@ -5210,14 +5238,13 @@ var DeploymentRepository = /** @class */ (function () { DeploymentRepository.prototype.create = function (command) { var _a, _b; return __awaiter(this, void 0, void 0, function () { - var serverInformation, serverVersion, response, mappedTasks; + var serverInformation, response, mappedTasks; return __generator(this, function (_c) { switch (_c.label) { case 0: return [4 /*yield*/, this.client.getServerInformation()]; case 1: serverInformation = _c.sent(); - serverVersion = new semver_1.SemVer(serverInformation.version); - if (serverVersion < new semver_1.SemVer("2022.3.5512")) { + if ((0, semver_1.lt)(serverInformation.version, "2022.3.5512")) { (_b = (_a = this.client).error) === null || _b === void 0 ? void 0 : _b.call(_a, "The Octopus instance doesn't support deploying releases using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); throw new Error("The Octopus instance doesn't support deploying releases using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); } @@ -5245,14 +5272,13 @@ var DeploymentRepository = /** @class */ (function () { DeploymentRepository.prototype.createTenanted = function (command) { var _a, _b; return __awaiter(this, void 0, void 0, function () { - var serverInformation, serverVersion, response, mappedTasks; + var serverInformation, response, mappedTasks; return __generator(this, function (_c) { switch (_c.label) { case 0: return [4 /*yield*/, this.client.getServerInformation()]; case 1: serverInformation = _c.sent(); - serverVersion = new semver_1.SemVer(serverInformation.version); - if (serverVersion < new semver_1.SemVer("2022.3.5512")) { + if ((0, semver_1.lt)(serverInformation.version, "2022.3.5512")) { (_b = (_a = this.client).error) === null || _b === void 0 ? void 0 : _b.call(_a, "The Octopus instance doesn't support deploying tenanted releases using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); throw new Error("The Octopus instance doesn't support deploying tenanted releases using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); } @@ -5426,14 +5452,13 @@ var ReleaseRepository = /** @class */ (function () { ReleaseRepository.prototype.create = function (command) { var _a, _b; return __awaiter(this, void 0, void 0, function () { - var serverInformation, serverVersion, response; + var serverInformation, response; return __generator(this, function (_c) { switch (_c.label) { case 0: return [4 /*yield*/, this.client.getServerInformation()]; case 1: serverInformation = _c.sent(); - serverVersion = new semver_1.SemVer(serverInformation.version); - if (serverVersion < new semver_1.SemVer("2022.3.5512")) { + if ((0, semver_1.lt)(serverInformation.version, "2022.3.5512")) { (_b = (_a = this.client).error) === null || _b === void 0 ? void 0 : _b.call(_a, "The Octopus instance doesn't support creating releases using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); throw new Error("The Octopus instance doesn't support creating releases using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); } @@ -5888,14 +5913,13 @@ var RunbookRunRepository = /** @class */ (function () { RunbookRunRepository.prototype.create = function (command) { var _a, _b; return __awaiter(this, void 0, void 0, function () { - var serverInformation, serverVersion, response, mappedTasks; + var serverInformation, response, mappedTasks; return __generator(this, function (_c) { switch (_c.label) { case 0: return [4 /*yield*/, this.client.getServerInformation()]; case 1: serverInformation = _c.sent(); - serverVersion = new semver_1.SemVer(serverInformation.version); - if (serverVersion < new semver_1.SemVer("2022.3.5512")) { + if ((0, semver_1.lt)(serverInformation.version, "2022.3.5512")) { (_b = (_a = this.client).error) === null || _b === void 0 ? void 0 : _b.call(_a, "The Octopus instance doesn't support running runbooks using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); throw new Error("The Octopus instance doesn't support running runbooks using the Executions API, it will need to be upgraded to at least 2022.3.5512 in order to access this API."); } @@ -6705,18 +6729,29 @@ var TenantRepository = /** @class */ (function (_super) { return _super.call(this, client, spaceName, "".concat(__1.spaceScopedRoutePrefix, "/tenants"), "skip,projectId,tags,take,ids,clone,partialName,clonedFromTenantId") || this; } TenantRepository.prototype.tagTest = function (tenantIds, tags) { - return this.client.request("".concat(__1.spaceScopedRoutePrefix, "/tenants/tag-test{?tenantIds,tags}"), { tenantIds: tenantIds, tags: tags }); + return this.client.request("".concat(__1.spaceScopedRoutePrefix, "/tenants/tag-test{?tenantIds,tags}"), { + spaceName: this.spaceName, + tenantIds: tenantIds, + tags: tags, + }); }; TenantRepository.prototype.getVariables = function (tenant) { - return this.client.request("".concat(__1.spaceScopedRoutePrefix, "/tenants/{id}/variables")); + return this.client.request("".concat(__1.spaceScopedRoutePrefix, "/tenants/{id}/variables"), { + spaceName: this.spaceName, + id: tenant.Id, + }); }; TenantRepository.prototype.setVariables = function (tenant, variables) { - return this.client.doUpdate("".concat(__1.spaceScopedRoutePrefix, "/tenants/{id}/variables"), variables); + return this.client.doUpdate("".concat(__1.spaceScopedRoutePrefix, "/tenants/{id}/variables"), variables, { + spaceName: this.spaceName, + id: tenant.Id, + }); }; TenantRepository.prototype.missingVariables = function (filterOptions, includeDetails) { if (filterOptions === void 0) { filterOptions = {}; } if (includeDetails === void 0) { includeDetails = false; } var payload = { + spaceName: this.spaceName, environmentId: filterOptions.environmentId, includeDetails: includeDetails, projectId: filterOptions.projectId, @@ -42315,6 +42350,7 @@ const api_wrapper_1 = __nccwpck_require__(4636); userAgentApp: 'GitHubActions await-task-action', instanceURL: parameters.server, apiKey: parameters.apiKey, + accessToken: parameters.accessToken, logging: logger }; const client = yield api_client_1.Client.create(config); @@ -42357,6 +42393,7 @@ const core_1 = __nccwpck_require__(2186); const EnvironmentVariables = { URL: 'OCTOPUS_URL', ApiKey: 'OCTOPUS_API_KEY', + AccessToken: 'OCTOPUS_ACCESS_TOKEN', Space: 'OCTOPUS_SPACE' }; function getInputParameters() { @@ -42381,7 +42418,8 @@ function getInputParameters() { } const parameters = { server: (0, core_1.getInput)('server') || process.env[EnvironmentVariables.URL] || '', - apiKey: (0, core_1.getInput)('api_key') || process.env[EnvironmentVariables.ApiKey] || '', + apiKey: (0, core_1.getInput)('api_key') || process.env[EnvironmentVariables.ApiKey], + accessToken: process.env[EnvironmentVariables.AccessToken], space: (0, core_1.getInput)('space') || process.env[EnvironmentVariables.Space] || '', serverTaskId: (0, core_1.getInput)('server_task_id', { required: true }), pollingInterval, @@ -42390,13 +42428,13 @@ function getInputParameters() { }; const errors = []; 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."); + errors.push("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."); } 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."); + errors.push("The Octopus space name is required, please specify explicitly through the 'space' input or set the OCTOPUS_SPACE environment variable."); } if (errors.length > 0) { throw new Error(errors.join('\n')); diff --git a/package-lock.json b/package-lock.json index 4efb5267..663dff12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "Apache-2.0", "dependencies": { "@actions/core": "^1.10.0", - "@octopusdeploy/api-client": "^3.0.5", + "@octopusdeploy/api-client": "^3.1.0", "tmp": "^0.2.1" }, "devDependencies": { @@ -1226,9 +1226,9 @@ } }, "node_modules/@octopusdeploy/api-client": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@octopusdeploy/api-client/-/api-client-3.0.5.tgz", - "integrity": "sha512-65TJ2H1iyqlipDEvSCSsGi2BtcifSpLQ7pTbpGjSLvjymjaOVV5IxAeP+OHemNkMthyzPHEUNAyKffy3XqaZhg==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@octopusdeploy/api-client/-/api-client-3.1.0.tgz", + "integrity": "sha512-n/HtwCExJdTYOHdFb47+y2bN7MOPIDayNAXZZtWqKMTxHmXN2sqYNq5NS/SVHvFYsbxFi/hpNlrwpLufg8mOWQ==", "dependencies": { "adm-zip": "^0.5.9", "axios": "^1.2.1", @@ -7420,9 +7420,9 @@ } }, "@octopusdeploy/api-client": { - "version": "3.0.5", - "resolved": "https://registry.npmjs.org/@octopusdeploy/api-client/-/api-client-3.0.5.tgz", - "integrity": "sha512-65TJ2H1iyqlipDEvSCSsGi2BtcifSpLQ7pTbpGjSLvjymjaOVV5IxAeP+OHemNkMthyzPHEUNAyKffy3XqaZhg==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@octopusdeploy/api-client/-/api-client-3.1.0.tgz", + "integrity": "sha512-n/HtwCExJdTYOHdFb47+y2bN7MOPIDayNAXZZtWqKMTxHmXN2sqYNq5NS/SVHvFYsbxFi/hpNlrwpLufg8mOWQ==", "requires": { "adm-zip": "^0.5.9", "axios": "^1.2.1", diff --git a/package.json b/package.json index 18bab75f..94828ecb 100644 --- a/package.json +++ b/package.json @@ -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", @@ -85,4 +85,4 @@ "test:integration": "jest --ci --reporters=default --reporters=jest-junit --testPathPattern=__tests__/integration" }, "version": "3.0.0" -} \ No newline at end of file +} diff --git a/src/index.ts b/src/index.ts index 5ea94f4a..bc44a6bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 } diff --git a/src/input-parameters.ts b/src/input-parameters.ts index 92491891..a7f47bea 100644 --- a/src/input-parameters.ts +++ b/src/input-parameters.ts @@ -3,6 +3,7 @@ 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 @@ -10,7 +11,9 @@ 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 @@ -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, @@ -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." ) }