mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 00:27:30 +00:00
refactor: enhance license key handling and error management
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import axios, { AxiosError } from "axios";
|
import axios, { AxiosError } from "axios";
|
||||||
|
|
||||||
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
import { TLicenseServiceFactory } from "@app/ee/services/license/license-service";
|
||||||
import { getConfig } from "@app/lib/config/env";
|
import { getConfig, TEnvConfig } from "@app/lib/config/env";
|
||||||
import { request } from "@app/lib/config/request";
|
import { request } from "@app/lib/config/request";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
@@ -9,17 +9,24 @@ import { UserAliasType } from "@app/services/user-alias/user-alias-types";
|
|||||||
|
|
||||||
import { TFeatureSet, TLicenseKeyConfig, TOfflineLicenseContents } from "./license-types";
|
import { TFeatureSet, TLicenseKeyConfig, TOfflineLicenseContents } from "./license-types";
|
||||||
|
|
||||||
const getOfflineLicenseContents = (licenseKey: string): TOfflineLicenseContents => {
|
|
||||||
return JSON.parse(Buffer.from(licenseKey, "base64").toString("utf8")) as TOfflineLicenseContents;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const isOfflineLicenseKey = (licenseKey: string): boolean => {
|
export const isOfflineLicenseKey = (licenseKey: string): boolean => {
|
||||||
const contents = getOfflineLicenseContents(licenseKey);
|
try {
|
||||||
return "signature" in contents && "license" in contents;
|
const contents = JSON.parse(Buffer.from(licenseKey, "base64").toString("utf8")) as TOfflineLicenseContents;
|
||||||
|
|
||||||
|
return "signature" in contents && "license" in contents;
|
||||||
|
} catch (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getLicenseKeyConfig = (): TLicenseKeyConfig => {
|
export const getLicenseKeyConfig = (
|
||||||
const cfg = getConfig();
|
config?: Pick<TEnvConfig, "LICENSE_KEY" | "LICENSE_KEY_OFFLINE">
|
||||||
|
): TLicenseKeyConfig => {
|
||||||
|
const cfg = config || getConfig();
|
||||||
|
|
||||||
|
if (!cfg) {
|
||||||
|
return { isValid: false };
|
||||||
|
}
|
||||||
|
|
||||||
const licenseKey = cfg.LICENSE_KEY;
|
const licenseKey = cfg.LICENSE_KEY;
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export const licenseServiceFactory = ({
|
|||||||
let instanceType = InstanceType.OnPrem;
|
let instanceType = InstanceType.OnPrem;
|
||||||
let onPremFeatures: TFeatureSet = getDefaultOnPremFeatures();
|
let onPremFeatures: TFeatureSet = getDefaultOnPremFeatures();
|
||||||
let selfHostedLicense: TOfflineLicense | null = null;
|
let selfHostedLicense: TOfflineLicense | null = null;
|
||||||
const licenseKeyConfig = getLicenseKeyConfig();
|
const licenseKeyConfig = getLicenseKeyConfig(envConfig);
|
||||||
|
|
||||||
const licenseServerCloudApi = setupLicenseRequestWithStore(
|
const licenseServerCloudApi = setupLicenseRequestWithStore(
|
||||||
envConfig.LICENSE_SERVER_URL || "",
|
envConfig.LICENSE_SERVER_URL || "",
|
||||||
|
|||||||
Reference in New Issue
Block a user