diff --git a/backend/src/ee/services/license/license-fns.ts b/backend/src/ee/services/license/license-fns.ts index 4231ba3c23..09ff9e1081 100644 --- a/backend/src/ee/services/license/license-fns.ts +++ b/backend/src/ee/services/license/license-fns.ts @@ -7,7 +7,7 @@ import { BadRequestError } from "@app/lib/errors"; import { logger } from "@app/lib/logger"; import { UserAliasType } from "@app/services/user-alias/user-alias-types"; -import { TFeatureSet, TLicenseKeyConfig, TOfflineLicenseContents } from "./license-types"; +import { LicenseType, TFeatureSet, TLicenseKeyConfig, TOfflineLicenseContents } from "./license-types"; export const isOfflineLicenseKey = (licenseKey: string): boolean => { try { @@ -32,10 +32,10 @@ export const getLicenseKeyConfig = ( if (licenseKey) { if (isOfflineLicenseKey(licenseKey)) { - return { isValid: true, licenseKey, type: "offline" }; + return { isValid: true, licenseKey, type: LicenseType.Offline }; } - return { isValid: true, licenseKey, type: "online" }; + return { isValid: true, licenseKey, type: LicenseType.Online }; } const offlineLicenseKey = cfg.LICENSE_KEY_OFFLINE; @@ -43,7 +43,7 @@ export const getLicenseKeyConfig = ( // backwards compatibility if (offlineLicenseKey) { if (isOfflineLicenseKey(offlineLicenseKey)) { - return { isValid: true, licenseKey: offlineLicenseKey, type: "offline" }; + return { isValid: true, licenseKey: offlineLicenseKey, type: LicenseType.Offline }; } return { isValid: false }; diff --git a/backend/src/ee/services/license/license-service.ts b/backend/src/ee/services/license/license-service.ts index 080556ca57..3bbd58831a 100644 --- a/backend/src/ee/services/license/license-service.ts +++ b/backend/src/ee/services/license/license-service.ts @@ -25,6 +25,7 @@ import { TLicenseDALFactory } from "./license-dal"; import { getDefaultOnPremFeatures, getLicenseKeyConfig, setupLicenseRequestWithStore } from "./license-fns"; import { InstanceType, + LicenseType, TAddOrgPmtMethodDTO, TAddOrgTaxIdDTO, TCreateOrgPortalSession, @@ -87,7 +88,7 @@ export const licenseServiceFactory = ({ ); const onlineLicenseKey = - licenseKeyConfig.isValid && licenseKeyConfig.type === "online" ? licenseKeyConfig.licenseKey : ""; + licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Online ? licenseKeyConfig.licenseKey : ""; const licenseServerOnPremApi = setupLicenseRequestWithStore( envConfig.LICENSE_SERVER_URL || "", @@ -135,7 +136,7 @@ export const licenseServiceFactory = ({ return; } - if (licenseKeyConfig.isValid && licenseKeyConfig.type === "online") { + if (licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Online) { const token = await licenseServerOnPremApi.refreshLicense(); if (token) { await syncLicenseKeyOnPremFeatures(true); @@ -146,7 +147,7 @@ export const licenseServiceFactory = ({ return; } - if (licenseKeyConfig.isValid && licenseKeyConfig.type === "offline") { + if (licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline) { let isValidOfflineLicense = true; const contents: TOfflineLicenseContents = JSON.parse( Buffer.from(licenseKeyConfig.licenseKey, "base64").toString("utf8") @@ -188,7 +189,7 @@ export const licenseServiceFactory = ({ }; const initializeBackgroundSync = async () => { - if (licenseKeyConfig?.isValid && licenseKeyConfig?.type === "online") { + if (licenseKeyConfig?.isValid && licenseKeyConfig?.type === LicenseType.Online) { logger.info("Setting up background sync process for refresh onPremFeatures"); const job = new CronJob("*/10 * * * *", syncLicenseKeyOnPremFeatures); job.start(); diff --git a/backend/src/ee/services/license/license-types.ts b/backend/src/ee/services/license/license-types.ts index 1fd11fabf4..8897eaabcf 100644 --- a/backend/src/ee/services/license/license-types.ts +++ b/backend/src/ee/services/license/license-types.ts @@ -137,6 +137,11 @@ export type TOrgInvoiceDTO = TOrgPermission; export type TOrgLicensesDTO = TOrgPermission; +export enum LicenseType { + Offline = "offline", + Online = "online" +} + export type TLicenseKeyConfig = | { isValid: false; @@ -144,5 +149,5 @@ export type TLicenseKeyConfig = | { isValid: true; licenseKey: string; - type: "offline" | "online"; + type: LicenseType; }; diff --git a/backend/src/server/routes/v1/admin-router.ts b/backend/src/server/routes/v1/admin-router.ts index 8586336429..f6ec36f6f0 100644 --- a/backend/src/server/routes/v1/admin-router.ts +++ b/backend/src/server/routes/v1/admin-router.ts @@ -10,6 +10,7 @@ import { UsersSchema } from "@app/db/schemas"; import { getLicenseKeyConfig } from "@app/ee/services/license/license-fns"; +import { LicenseType } from "@app/ee/services/license/license-types"; import { getConfig, overridableKeys } from "@app/lib/config/env"; import { crypto } from "@app/lib/crypto/cryptography"; import { BadRequestError } from "@app/lib/errors"; @@ -67,7 +68,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => { const serverEnvs = getConfig(); const licenseKeyConfig = getLicenseKeyConfig(); - const hasOfflineLicense = licenseKeyConfig.isValid && licenseKeyConfig.type === "offline"; + const hasOfflineLicense = licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline; return { config: { diff --git a/backend/src/services/offline-usage-report/offline-usage-report-service.ts b/backend/src/services/offline-usage-report/offline-usage-report-service.ts index 92360ca52d..f05c734c15 100644 --- a/backend/src/services/offline-usage-report/offline-usage-report-service.ts +++ b/backend/src/services/offline-usage-report/offline-usage-report-service.ts @@ -35,7 +35,8 @@ export const offlineUsageReportServiceFactory = ({ if (!hasOfflineLicense) { throw new BadRequestError({ - message: "Offline usage reports are not enabled. An offline license must be configured in LICENSE_KEY." + message: + "Offline usage reports are not enabled. Usage reports are only available for self-hosted offline instances" }); } diff --git a/docs/self-hosting/ee.mdx b/docs/self-hosting/ee.mdx index ea32c416ce..9c3e7d644c 100644 --- a/docs/self-hosting/ee.mdx +++ b/docs/self-hosting/ee.mdx @@ -14,7 +14,7 @@ This guide walks through how you can use these paid features on a self-hosted in Once purchased, you will be issued a license key. - Assign the issued license key to the `LICENSE_KEY` environment variable in your Infisical instance. The system will automatically detect whether the license is online or offline. + Set your license key as the value of the **LICENSE_KEY** environment variable within your Infisical instance. @@ -33,7 +33,7 @@ This guide walks through how you can use these paid features on a self-hosted in - The system will automatically detect that it's an offline license based on the key format. - Backwards Compatibility: The `LICENSE_KEY_OFFLINE` environment variable is still supported for backwards compatibility, but we recommend using `LICENSE_KEY` for all license types going forward. + While the LICENSE_KEY_OFFLINE environment variable continues to be supported for compatibility with existing configurations, we recommend transitioning to LICENSE_KEY for all license types going forward.