From beff0a2f354eac9dd38506e0e1a2b12ea0af7faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Pluta?= Date: Sun, 17 Nov 2024 14:41:14 +0100 Subject: [PATCH] Add support to ignoreSSL config option --- src/openhab/index.ts | 10 ++++++++-- src/types/openhab.ts | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/openhab/index.ts b/src/openhab/index.ts index 93a16a9..9cec4f4 100644 --- a/src/openhab/index.ts +++ b/src/openhab/index.ts @@ -1,16 +1,22 @@ -import { OpenHABConfig, Thing } from "@types"; +import { Agent } from "https"; import axios, { AxiosInstance } from "axios"; +import { OpenHABConfig, Thing } from "@types"; import { enhancedStringConfig } from "../utils/config"; export class OpenHAB { #api: AxiosInstance; - constructor({ baseURL, token }: Partial) { + constructor({ baseURL, token, ignoreSSL }: Partial) { if (!baseURL || !token) { throw new Error(`Both 'baseURL' and 'token' properties are required on OpenHAB configuration.`); } + const httpsAgent = new Agent({ + rejectUnauthorized: !ignoreSSL + }); + this.#api = axios.create({ + httpsAgent, baseURL: `${baseURL}/rest`, headers: { Authorization: `Bearer ${enhancedStringConfig(token)}` diff --git a/src/types/openhab.ts b/src/types/openhab.ts index 57eea43..db8b199 100644 --- a/src/types/openhab.ts +++ b/src/types/openhab.ts @@ -1,6 +1,7 @@ export type OpenHABConfig = { baseURL: string; token: string; + ignoreSSL?: boolean; }; export type Thing = {