Skip to content

Commit

Permalink
support ignoring ssl errors for self signed instances (#308)
Browse files Browse the repository at this point in the history
consolidate client creation
  • Loading branch information
benPearce1 authored Apr 20, 2023
1 parent dc40a70 commit c7b3239
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import { OctoServerConnectionDetails } from "../../Utils/connection";
import { createCommandFromInputs } from "./inputCommandBuilder";
import { BuildInformationRepository, Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
import { BuildInformationRepository, Logger } from "@octopusdeploy/api-client";
import { TaskWrapper } from "tasks/Utils/taskInput";
import { getOverwriteMode } from "./overwriteMode";
import { IVstsHelper } from "./vsts";
import { getUserAgentApp } from "../../Utils/pluginInformation";
import { getClient } from "../../Utils/client";

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

public async run() {
const command = await createCommandFromInputs(this.logger, this.task, this.vsts);

const config: ClientConfiguration = {
userAgentApp: getUserAgentApp("build-information", "push", 6),
instanceURL: this.connection.url,
apiKey: this.connection.apiKey,
logging: this.logger,
};
const client = await Client.create(config);
const client = await getClient(this.connection, this.logger, "build-information", "push", 6)

const overwriteMode = await getOverwriteMode(this.logger, this.task);
this.logger.debug?.(`Build Information:\n${JSON.stringify(command, null, 2)}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,22 @@
import {
Client,
ClientConfiguration,
CreateReleaseCommandV1,
Logger,
Project,
ProjectRepository,
Space,
SpaceRepository
} from "@octopusdeploy/api-client";
import { Client, CreateReleaseCommandV1, Logger, Project, ProjectRepository, Space, SpaceRepository } from "@octopusdeploy/api-client";
import { OctoServerConnectionDetails } from "../../Utils/connection";
import { createReleaseFromInputs } from "./createRelease";
import { createCommandFromInputs } from "./inputCommandBuilder";
import os from "os";
import { TaskWrapper } from "tasks/Utils/taskInput";
import { getUserAgentApp } from "../../Utils/pluginInformation";
import path from "path";
import { getVstsEnvironmentVariables } from "../../../tasksLegacy/Utils/environment";
import { v4 as uuidv4 } from "uuid";
import * as tasks from "azure-pipelines-task-lib";
import { getClient } from "../../Utils/client";

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

public async run() {
try {
const command = createCommandFromInputs(this.logger, this.task);

const config: ClientConfiguration = {
userAgentApp: getUserAgentApp("release", "create", 6),
instanceURL: this.connection.url,
apiKey: this.connection.apiKey,
logging: this.logger,
};
const client = await Client.create(config);

const client = await getClient(this.connection, this.logger, "release", "create", 6);
const version = await createReleaseFromInputs(client, command, this.task, this.logger);

await this.tryCreateSummary(client, command, version);
Expand Down
13 changes: 3 additions & 10 deletions source/tasks/Deploy/DeployV6/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
import { Logger } from "@octopusdeploy/api-client";
import { OctoServerConnectionDetails } from "../../Utils/connection";
import { createDeploymentFromInputs } from "./createDeployment";
import { createCommandFromInputs } from "./inputCommandBuilder";
import os from "os";
import { TaskWrapper } from "tasks/Utils/taskInput";
import { getUserAgentApp } from "../../Utils/pluginInformation";
import { getClient } from "../../Utils/client";

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

public async run() {
try {
const command = createCommandFromInputs(this.logger, this.task);

const config: ClientConfiguration = {
userAgentApp: getUserAgentApp("release", "deploy", 6),
instanceURL: this.connection.url,
apiKey: this.connection.apiKey,
logging: this.logger,
};
const client = await Client.create(config);
const client = await getClient(this.connection, this.logger, "release", "deploy", 6);

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

Expand Down
13 changes: 3 additions & 10 deletions source/tasks/DeployTenant/TenantedDeployV6/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
import { Logger } from "@octopusdeploy/api-client";
import { OctoServerConnectionDetails } from "../../Utils/connection";
import { createDeploymentFromInputs } from "./createDeployment";
import { createCommandFromInputs } from "./inputCommandBuilder";
import os from "os";
import { TaskWrapper } from "tasks/Utils/taskInput";
import { getUserAgentApp } from "../../Utils/pluginInformation";
import { getClient } from "../../Utils/client";

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

public async run() {
try {
const command = createCommandFromInputs(this.logger, this.task);

const config: ClientConfiguration = {
userAgentApp: getUserAgentApp("release", "deploy-tenanted", 6),
instanceURL: this.connection.url,
apiKey: this.connection.apiKey,
logging: this.logger,
};
const client = await Client.create(config);
const client = await getClient(this.connection, this.logger, "release", "deploy-tenanted", 6);

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

Expand Down
14 changes: 3 additions & 11 deletions source/tasks/Push/PushV6/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
import { Logger } from "@octopusdeploy/api-client";
import * as tasks from "azure-pipelines-task-lib/task";
import { getDefaultOctopusConnectionDetailsOrThrow } from "../../Utils/connection";
import { getLineSeparatedItems, getOverwriteModeFromReplaceInput, getRequiredInput } from "../../Utils/inputs";
import { Push } from "./push";
import os from "os";
import { getUserAgentApp } from "../../Utils/pluginInformation";
import { getClient } from "../../Utils/client";

async function run() {
try {
Expand All @@ -29,15 +29,7 @@ async function run() {
},
};

const config: ClientConfiguration = {
userAgentApp: getUserAgentApp("package", "push", 6),
instanceURL: connection.url,
apiKey: connection.apiKey,
logging: logger,
};

const client: Client = await Client.create(config);

const client = await getClient(connection, logger, "package", "push", 6);
await new Push(client).run(spaceName, packages, overwriteMode);
} catch (error: unknown) {
if (error instanceof Error) {
Expand Down
13 changes: 3 additions & 10 deletions source/tasks/RunRunbook/RunRunbookV6/runbookRun.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
import { Logger } from "@octopusdeploy/api-client";
import { OctoServerConnectionDetails } from "../../Utils/connection";
import { createRunbookRunFromInputs } from "./runRunbook";
import { createCommandFromInputs } from "./inputCommandBuilder";
import os from "os";
import { TaskWrapper } from "tasks/Utils/taskInput";
import { getUserAgentApp } from "../../Utils/pluginInformation";
import { getClient } from "../../Utils/client";

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

public async run() {
try {
const command = createCommandFromInputs(this.logger, this.task);

const config: ClientConfiguration = {
userAgentApp: getUserAgentApp("runbook", "run", 6),
instanceURL: this.connection.url,
apiKey: this.connection.apiKey,
logging: this.logger,
};
const client = await Client.create(config);
const client = await getClient(this.connection, this.logger, "runbook", "run", 6);

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

Expand Down
18 changes: 18 additions & 0 deletions source/tasks/Utils/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Client, ClientConfiguration, Logger } from "@octopusdeploy/api-client";
import { getUserAgentApp } from "./pluginInformation";
import https from "https";
import { OctoServerConnectionDetails } from "./connection";

export async function getClient(connection: OctoServerConnectionDetails, logger: Logger, stepNoun: string, stepVerb: string, stepVersion: number) {
const config: ClientConfiguration = {
userAgentApp: getUserAgentApp(stepNoun, stepVerb, stepVersion),
instanceURL: connection.url,
apiKey: connection.apiKey,
logging: logger,
};
if (connection.ignoreSslErrors) {
config.httpsAgent = new https.Agent({ rejectUnauthorized: false });
}

return await Client.create(config);
}

0 comments on commit c7b3239

Please sign in to comment.