Skip to content

Commit

Permalink
Allow skipping the tls check for webhooks (#197)
Browse files Browse the repository at this point in the history
* fix: throw if configuration is undefined

* feat: add skipTlsCheck option to Webhooks Module
  • Loading branch information
jkoenig134 authored Jul 1, 2024
1 parent 746dc3d commit a3b9b6b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ export abstract class MessageBrokerConnector<TConfiguration> {
public constructor(
protected readonly configuration: TConfiguration,
protected readonly logger: ILogger
) {}
) {
if (!this.configuration) throw new Error("Cannot start the broker, the 'configuration' is not defined.");
}

public abstract init(): void | Promise<void>;
public abstract publish(namespace: string, data: Buffer): void | Promise<void>;
Expand Down
5 changes: 4 additions & 1 deletion src/modules/webhooks/ConfigModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Result } from "@js-soft/ts-utils";
import { WebhooksModuleApplicationErrors } from "./WebhooksModuleApplicationErrors";

export class ConfigModel {
public constructor(public readonly webhooks: Webhook[]) {}
public constructor(
public readonly webhooks: Webhook[],
public readonly skipTlsCheck: boolean
) {}
}

export class Webhook {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/webhooks/ConfigParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ConfigParser {
return Result.fail(webhooks.error);
}

const configModel = new ConfigModel(webhooks.value);
const configModel = new ConfigModel(webhooks.value, configJson.skipTlsCheck ?? false);
return Result.ok(configModel);
}

Expand Down
6 changes: 3 additions & 3 deletions src/modules/webhooks/WebhooksModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export default class WebhooksModule extends ConnectorRuntimeModule<WebhooksModul
private configModel: ConfigModel;

public init(): void {
this.configModel = ConfigParser.parse(this.configuration).value;

this.axios = axios.create({
httpAgent: new agentKeepAlive(),
httpsAgent: new AgentKeepAliveHttps(),
httpsAgent: new AgentKeepAliveHttps({ rejectUnauthorized: !this.configModel.skipTlsCheck }),
validateStatus: () => true,
maxRedirects: 0
});

this.configModel = ConfigParser.parse(this.configuration).value;
}

public start(): void {
Expand Down
1 change: 1 addition & 0 deletions src/modules/webhooks/WebhooksModuleConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ConnectorRuntimeModuleConfiguration } from "../../ConnectorRuntimeModul
export interface WebhooksModuleConfiguration extends ConnectorRuntimeModuleConfiguration {
targets?: Record<string, WebhooksModuleConfigurationTarget>;
webhooks?: WebhooksModuleConfigurationWebhook[];
skipTlsCheck?: boolean;
}

export interface WebhooksModuleConfigurationTarget {
Expand Down

0 comments on commit a3b9b6b

Please sign in to comment.