mirror of
https://github.com/Infisical/infisical.git
synced 2026-01-09 23:48:05 -05:00
fix: review suggestions
This commit is contained in:
@@ -7,7 +7,7 @@ import { BadRequestError } from "@app/lib/errors";
|
|||||||
import { logger } from "@app/lib/logger";
|
import { logger } from "@app/lib/logger";
|
||||||
import { UserAliasType } from "@app/services/user-alias/user-alias-types";
|
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 => {
|
export const isOfflineLicenseKey = (licenseKey: string): boolean => {
|
||||||
try {
|
try {
|
||||||
@@ -32,10 +32,10 @@ export const getLicenseKeyConfig = (
|
|||||||
|
|
||||||
if (licenseKey) {
|
if (licenseKey) {
|
||||||
if (isOfflineLicenseKey(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;
|
const offlineLicenseKey = cfg.LICENSE_KEY_OFFLINE;
|
||||||
@@ -43,7 +43,7 @@ export const getLicenseKeyConfig = (
|
|||||||
// backwards compatibility
|
// backwards compatibility
|
||||||
if (offlineLicenseKey) {
|
if (offlineLicenseKey) {
|
||||||
if (isOfflineLicenseKey(offlineLicenseKey)) {
|
if (isOfflineLicenseKey(offlineLicenseKey)) {
|
||||||
return { isValid: true, licenseKey: offlineLicenseKey, type: "offline" };
|
return { isValid: true, licenseKey: offlineLicenseKey, type: LicenseType.Offline };
|
||||||
}
|
}
|
||||||
|
|
||||||
return { isValid: false };
|
return { isValid: false };
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import { TLicenseDALFactory } from "./license-dal";
|
|||||||
import { getDefaultOnPremFeatures, getLicenseKeyConfig, setupLicenseRequestWithStore } from "./license-fns";
|
import { getDefaultOnPremFeatures, getLicenseKeyConfig, setupLicenseRequestWithStore } from "./license-fns";
|
||||||
import {
|
import {
|
||||||
InstanceType,
|
InstanceType,
|
||||||
|
LicenseType,
|
||||||
TAddOrgPmtMethodDTO,
|
TAddOrgPmtMethodDTO,
|
||||||
TAddOrgTaxIdDTO,
|
TAddOrgTaxIdDTO,
|
||||||
TCreateOrgPortalSession,
|
TCreateOrgPortalSession,
|
||||||
@@ -87,7 +88,7 @@ export const licenseServiceFactory = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const onlineLicenseKey =
|
const onlineLicenseKey =
|
||||||
licenseKeyConfig.isValid && licenseKeyConfig.type === "online" ? licenseKeyConfig.licenseKey : "";
|
licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Online ? licenseKeyConfig.licenseKey : "";
|
||||||
|
|
||||||
const licenseServerOnPremApi = setupLicenseRequestWithStore(
|
const licenseServerOnPremApi = setupLicenseRequestWithStore(
|
||||||
envConfig.LICENSE_SERVER_URL || "",
|
envConfig.LICENSE_SERVER_URL || "",
|
||||||
@@ -135,7 +136,7 @@ export const licenseServiceFactory = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (licenseKeyConfig.isValid && licenseKeyConfig.type === "online") {
|
if (licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Online) {
|
||||||
const token = await licenseServerOnPremApi.refreshLicense();
|
const token = await licenseServerOnPremApi.refreshLicense();
|
||||||
if (token) {
|
if (token) {
|
||||||
await syncLicenseKeyOnPremFeatures(true);
|
await syncLicenseKeyOnPremFeatures(true);
|
||||||
@@ -146,7 +147,7 @@ export const licenseServiceFactory = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (licenseKeyConfig.isValid && licenseKeyConfig.type === "offline") {
|
if (licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline) {
|
||||||
let isValidOfflineLicense = true;
|
let isValidOfflineLicense = true;
|
||||||
const contents: TOfflineLicenseContents = JSON.parse(
|
const contents: TOfflineLicenseContents = JSON.parse(
|
||||||
Buffer.from(licenseKeyConfig.licenseKey, "base64").toString("utf8")
|
Buffer.from(licenseKeyConfig.licenseKey, "base64").toString("utf8")
|
||||||
@@ -188,7 +189,7 @@ export const licenseServiceFactory = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const initializeBackgroundSync = async () => {
|
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");
|
logger.info("Setting up background sync process for refresh onPremFeatures");
|
||||||
const job = new CronJob("*/10 * * * *", syncLicenseKeyOnPremFeatures);
|
const job = new CronJob("*/10 * * * *", syncLicenseKeyOnPremFeatures);
|
||||||
job.start();
|
job.start();
|
||||||
|
|||||||
@@ -137,6 +137,11 @@ export type TOrgInvoiceDTO = TOrgPermission;
|
|||||||
|
|
||||||
export type TOrgLicensesDTO = TOrgPermission;
|
export type TOrgLicensesDTO = TOrgPermission;
|
||||||
|
|
||||||
|
export enum LicenseType {
|
||||||
|
Offline = "offline",
|
||||||
|
Online = "online"
|
||||||
|
}
|
||||||
|
|
||||||
export type TLicenseKeyConfig =
|
export type TLicenseKeyConfig =
|
||||||
| {
|
| {
|
||||||
isValid: false;
|
isValid: false;
|
||||||
@@ -144,5 +149,5 @@ export type TLicenseKeyConfig =
|
|||||||
| {
|
| {
|
||||||
isValid: true;
|
isValid: true;
|
||||||
licenseKey: string;
|
licenseKey: string;
|
||||||
type: "offline" | "online";
|
type: LicenseType;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
UsersSchema
|
UsersSchema
|
||||||
} from "@app/db/schemas";
|
} from "@app/db/schemas";
|
||||||
import { getLicenseKeyConfig } from "@app/ee/services/license/license-fns";
|
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 { getConfig, overridableKeys } from "@app/lib/config/env";
|
||||||
import { crypto } from "@app/lib/crypto/cryptography";
|
import { crypto } from "@app/lib/crypto/cryptography";
|
||||||
import { BadRequestError } from "@app/lib/errors";
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
@@ -67,7 +68,7 @@ export const registerAdminRouter = async (server: FastifyZodProvider) => {
|
|||||||
const serverEnvs = getConfig();
|
const serverEnvs = getConfig();
|
||||||
|
|
||||||
const licenseKeyConfig = getLicenseKeyConfig();
|
const licenseKeyConfig = getLicenseKeyConfig();
|
||||||
const hasOfflineLicense = licenseKeyConfig.isValid && licenseKeyConfig.type === "offline";
|
const hasOfflineLicense = licenseKeyConfig.isValid && licenseKeyConfig.type === LicenseType.Offline;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
config: {
|
config: {
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ export const offlineUsageReportServiceFactory = ({
|
|||||||
|
|
||||||
if (!hasOfflineLicense) {
|
if (!hasOfflineLicense) {
|
||||||
throw new BadRequestError({
|
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"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
Once purchased, you will be issued a license key.
|
||||||
</Step>
|
</Step>
|
||||||
<Step title="Activate the license">
|
<Step title="Activate the license">
|
||||||
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.
|
||||||
|
|
||||||
<Tabs>
|
<Tabs>
|
||||||
<Tab title="Regular License">
|
<Tab title="Regular License">
|
||||||
@@ -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.
|
- The system will automatically detect that it's an offline license based on the key format.
|
||||||
|
|
||||||
<Note>
|
<Note>
|
||||||
<b>Backwards Compatibility:</b> 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.
|
||||||
</Note>
|
</Note>
|
||||||
</Tab>
|
</Tab>
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
|||||||
Reference in New Issue
Block a user