Skip to content

Commit c7b3239

Browse files
authored
support ignoring ssl errors for self signed instances (#308)
consolidate client creation
1 parent dc40a70 commit c7b3239

File tree

7 files changed

+36
-71
lines changed

7 files changed

+36
-71
lines changed

source/tasks/BuildInformation/BuildInformationV6/buildInformation.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
import { OctoServerConnectionDetails } from "../../Utils/connection";
22
import { createCommandFromInputs } from "./inputCommandBuilder";
3-
import { BuildInformationRepository, Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
3+
import { BuildInformationRepository, Logger } from "@octopusdeploy/api-client";
44
import { TaskWrapper } from "tasks/Utils/taskInput";
55
import { getOverwriteMode } from "./overwriteMode";
66
import { IVstsHelper } from "./vsts";
7-
import { getUserAgentApp } from "../../Utils/pluginInformation";
7+
import { getClient } from "../../Utils/client";
88

99
export class BuildInformation {
1010
constructor(readonly connection: OctoServerConnectionDetails, readonly logger: Logger, readonly task: TaskWrapper, readonly vsts: IVstsHelper) {}
1111

1212
public async run() {
1313
const command = await createCommandFromInputs(this.logger, this.task, this.vsts);
14-
15-
const config: ClientConfiguration = {
16-
userAgentApp: getUserAgentApp("build-information", "push", 6),
17-
instanceURL: this.connection.url,
18-
apiKey: this.connection.apiKey,
19-
logging: this.logger,
20-
};
21-
const client = await Client.create(config);
14+
const client = await getClient(this.connection, this.logger, "build-information", "push", 6)
2215

2316
const overwriteMode = await getOverwriteMode(this.logger, this.task);
2417
this.logger.debug?.(`Build Information:\n${JSON.stringify(command, null, 2)}`);

source/tasks/CreateOctopusRelease/CreateOctopusReleaseV6/release.ts

+3-20
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,22 @@
1-
import {
2-
Client,
3-
ClientConfiguration,
4-
CreateReleaseCommandV1,
5-
Logger,
6-
Project,
7-
ProjectRepository,
8-
Space,
9-
SpaceRepository
10-
} from "@octopusdeploy/api-client";
1+
import { Client, CreateReleaseCommandV1, Logger, Project, ProjectRepository, Space, SpaceRepository } from "@octopusdeploy/api-client";
112
import { OctoServerConnectionDetails } from "../../Utils/connection";
123
import { createReleaseFromInputs } from "./createRelease";
134
import { createCommandFromInputs } from "./inputCommandBuilder";
145
import os from "os";
156
import { TaskWrapper } from "tasks/Utils/taskInput";
16-
import { getUserAgentApp } from "../../Utils/pluginInformation";
177
import path from "path";
188
import { getVstsEnvironmentVariables } from "../../../tasksLegacy/Utils/environment";
199
import { v4 as uuidv4 } from "uuid";
2010
import * as tasks from "azure-pipelines-task-lib";
11+
import { getClient } from "../../Utils/client";
2112

2213
export class Release {
2314
constructor(readonly connection: OctoServerConnectionDetails, readonly task: TaskWrapper, readonly logger: Logger) {}
2415

2516
public async run() {
2617
try {
2718
const command = createCommandFromInputs(this.logger, this.task);
28-
29-
const config: ClientConfiguration = {
30-
userAgentApp: getUserAgentApp("release", "create", 6),
31-
instanceURL: this.connection.url,
32-
apiKey: this.connection.apiKey,
33-
logging: this.logger,
34-
};
35-
const client = await Client.create(config);
36-
19+
const client = await getClient(this.connection, this.logger, "release", "create", 6);
3720
const version = await createReleaseFromInputs(client, command, this.task, this.logger);
3821

3922
await this.tryCreateSummary(client, command, version);

source/tasks/Deploy/DeployV6/deploy.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
1+
import { Logger } from "@octopusdeploy/api-client";
22
import { OctoServerConnectionDetails } from "../../Utils/connection";
33
import { createDeploymentFromInputs } from "./createDeployment";
44
import { createCommandFromInputs } from "./inputCommandBuilder";
55
import os from "os";
66
import { TaskWrapper } from "tasks/Utils/taskInput";
7-
import { getUserAgentApp } from "../../Utils/pluginInformation";
7+
import { getClient } from "../../Utils/client";
88

99
export class Deploy {
1010
constructor(readonly connection: OctoServerConnectionDetails, readonly task: TaskWrapper, readonly logger: Logger) {}
1111

1212
public async run() {
1313
try {
1414
const command = createCommandFromInputs(this.logger, this.task);
15-
16-
const config: ClientConfiguration = {
17-
userAgentApp: getUserAgentApp("release", "deploy", 6),
18-
instanceURL: this.connection.url,
19-
apiKey: this.connection.apiKey,
20-
logging: this.logger,
21-
};
22-
const client = await Client.create(config);
15+
const client = await getClient(this.connection, this.logger, "release", "deploy", 6);
2316

2417
createDeploymentFromInputs(client, command, this.task, this.logger);
2518

source/tasks/DeployTenant/TenantedDeployV6/deploy.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
1+
import { Logger } from "@octopusdeploy/api-client";
22
import { OctoServerConnectionDetails } from "../../Utils/connection";
33
import { createDeploymentFromInputs } from "./createDeployment";
44
import { createCommandFromInputs } from "./inputCommandBuilder";
55
import os from "os";
66
import { TaskWrapper } from "tasks/Utils/taskInput";
7-
import { getUserAgentApp } from "../../Utils/pluginInformation";
7+
import { getClient } from "../../Utils/client";
88

99
export class Deploy {
1010
constructor(readonly connection: OctoServerConnectionDetails, readonly task: TaskWrapper, readonly logger: Logger) {}
1111

1212
public async run() {
1313
try {
1414
const command = createCommandFromInputs(this.logger, this.task);
15-
16-
const config: ClientConfiguration = {
17-
userAgentApp: getUserAgentApp("release", "deploy-tenanted", 6),
18-
instanceURL: this.connection.url,
19-
apiKey: this.connection.apiKey,
20-
logging: this.logger,
21-
};
22-
const client = await Client.create(config);
15+
const client = await getClient(this.connection, this.logger, "release", "deploy-tenanted", 6);
2316

2417
createDeploymentFromInputs(client, command, this.task, this.logger);
2518

source/tasks/Push/PushV6/index.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
1+
import { Logger } from "@octopusdeploy/api-client";
22
import * as tasks from "azure-pipelines-task-lib/task";
33
import { getDefaultOctopusConnectionDetailsOrThrow } from "../../Utils/connection";
44
import { getLineSeparatedItems, getOverwriteModeFromReplaceInput, getRequiredInput } from "../../Utils/inputs";
55
import { Push } from "./push";
66
import os from "os";
7-
import { getUserAgentApp } from "../../Utils/pluginInformation";
7+
import { getClient } from "../../Utils/client";
88

99
async function run() {
1010
try {
@@ -29,15 +29,7 @@ async function run() {
2929
},
3030
};
3131

32-
const config: ClientConfiguration = {
33-
userAgentApp: getUserAgentApp("package", "push", 6),
34-
instanceURL: connection.url,
35-
apiKey: connection.apiKey,
36-
logging: logger,
37-
};
38-
39-
const client: Client = await Client.create(config);
40-
32+
const client = await getClient(connection, logger, "package", "push", 6);
4133
await new Push(client).run(spaceName, packages, overwriteMode);
4234
} catch (error: unknown) {
4335
if (error instanceof Error) {

source/tasks/RunRunbook/RunRunbookV6/runbookRun.ts

+3-10
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,18 @@
1-
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
1+
import { Logger } from "@octopusdeploy/api-client";
22
import { OctoServerConnectionDetails } from "../../Utils/connection";
33
import { createRunbookRunFromInputs } from "./runRunbook";
44
import { createCommandFromInputs } from "./inputCommandBuilder";
55
import os from "os";
66
import { TaskWrapper } from "tasks/Utils/taskInput";
7-
import { getUserAgentApp } from "../../Utils/pluginInformation";
7+
import { getClient } from "../../Utils/client";
88

99
export class RunbookRun {
1010
constructor(readonly connection: OctoServerConnectionDetails, readonly task: TaskWrapper, readonly logger: Logger) {}
1111

1212
public async run() {
1313
try {
1414
const command = createCommandFromInputs(this.logger, this.task);
15-
16-
const config: ClientConfiguration = {
17-
userAgentApp: getUserAgentApp("runbook", "run", 6),
18-
instanceURL: this.connection.url,
19-
apiKey: this.connection.apiKey,
20-
logging: this.logger,
21-
};
22-
const client = await Client.create(config);
15+
const client = await getClient(this.connection, this.logger, "runbook", "run", 6);
2316

2417
createRunbookRunFromInputs(client, command, this.task, this.logger);
2518

source/tasks/Utils/client.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
2+
import { getUserAgentApp } from "./pluginInformation";
3+
import https from "https";
4+
import { OctoServerConnectionDetails } from "./connection";
5+
6+
export async function getClient(connection: OctoServerConnectionDetails, logger: Logger, stepNoun: string, stepVerb: string, stepVersion: number) {
7+
const config: ClientConfiguration = {
8+
userAgentApp: getUserAgentApp(stepNoun, stepVerb, stepVersion),
9+
instanceURL: connection.url,
10+
apiKey: connection.apiKey,
11+
logging: logger,
12+
};
13+
if (connection.ignoreSslErrors) {
14+
config.httpsAgent = new https.Agent({ rejectUnauthorized: false });
15+
}
16+
17+
return await Client.create(config);
18+
}

0 commit comments

Comments
 (0)