mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 20:27:12 +00:00
add secretApproval to globalFeatureSet
This commit is contained in:
committed by
Akhil Mohan
parent
faacb75034
commit
aafd7f0884
@@ -1,12 +1,12 @@
|
|||||||
import { Types } from "mongoose";
|
import { Types } from "mongoose";
|
||||||
import * as Sentry from "@sentry/node";
|
import * as Sentry from "@sentry/node";
|
||||||
import NodeCache from "node-cache";
|
import NodeCache from "node-cache";
|
||||||
import {
|
import {
|
||||||
getLicenseKey,
|
getLicenseKey,
|
||||||
getLicenseServerKey,
|
getLicenseServerKey,
|
||||||
getLicenseServerUrl,
|
getLicenseServerUrl,
|
||||||
} from "../../config";
|
} from "../../config";
|
||||||
import {
|
import {
|
||||||
licenseKeyRequest,
|
licenseKeyRequest,
|
||||||
licenseServerKeyRequest,
|
licenseServerKeyRequest,
|
||||||
refreshLicenseKeyToken,
|
refreshLicenseKeyToken,
|
||||||
@@ -37,6 +37,7 @@ interface FeatureSet {
|
|||||||
status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "canceled" | "unpaid" | null;
|
status: "incomplete" | "incomplete_expired" | "trialing" | "active" | "past_due" | "canceled" | "unpaid" | null;
|
||||||
trial_end: number | null;
|
trial_end: number | null;
|
||||||
has_used_trial: boolean;
|
has_used_trial: boolean;
|
||||||
|
secretApproval: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +47,7 @@ interface FeatureSet {
|
|||||||
* - Self-hosted enterprise: Fetch and update global feature set
|
* - Self-hosted enterprise: Fetch and update global feature set
|
||||||
*/
|
*/
|
||||||
class EELicenseService {
|
class EELicenseService {
|
||||||
|
|
||||||
private readonly _isLicenseValid: boolean; // TODO: deprecate
|
private readonly _isLicenseValid: boolean; // TODO: deprecate
|
||||||
|
|
||||||
public instanceType: "self-hosted" | "enterprise-self-hosted" | "cloud" = "self-hosted";
|
public instanceType: "self-hosted" | "enterprise-self-hosted" | "cloud" = "self-hosted";
|
||||||
@@ -72,18 +73,19 @@ class EELicenseService {
|
|||||||
samlSSO: false,
|
samlSSO: false,
|
||||||
status: null,
|
status: null,
|
||||||
trial_end: null,
|
trial_end: null,
|
||||||
has_used_trial: true
|
has_used_trial: true,
|
||||||
|
secretApproval: false
|
||||||
}
|
}
|
||||||
|
|
||||||
public localFeatureSet: NodeCache;
|
public localFeatureSet: NodeCache;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._isLicenseValid = true;
|
this._isLicenseValid = true;
|
||||||
this.localFeatureSet = new NodeCache({
|
this.localFeatureSet = new NodeCache({
|
||||||
stdTTL: 60,
|
stdTTL: 60,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getPlan(organizationId: Types.ObjectId, workspaceId?: Types.ObjectId): Promise<FeatureSet> {
|
public async getPlan(organizationId: Types.ObjectId, workspaceId?: Types.ObjectId): Promise<FeatureSet> {
|
||||||
try {
|
try {
|
||||||
if (this.instanceType === "cloud") {
|
if (this.instanceType === "cloud") {
|
||||||
@@ -96,7 +98,7 @@ class EELicenseService {
|
|||||||
if (!organization) throw OrganizationNotFoundError();
|
if (!organization) throw OrganizationNotFoundError();
|
||||||
|
|
||||||
let url = `${await getLicenseServerUrl()}/api/license-server/v1/customers/${organization.customerId}/cloud-plan`;
|
let url = `${await getLicenseServerUrl()}/api/license-server/v1/customers/${organization.customerId}/cloud-plan`;
|
||||||
|
|
||||||
if (workspaceId) {
|
if (workspaceId) {
|
||||||
url += `?workspaceId=${workspaceId}`;
|
url += `?workspaceId=${workspaceId}`;
|
||||||
}
|
}
|
||||||
@@ -114,14 +116,14 @@ class EELicenseService {
|
|||||||
|
|
||||||
return this.globalFeatureSet;
|
return this.globalFeatureSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async refreshPlan(organizationId: Types.ObjectId, workspaceId?: Types.ObjectId) {
|
public async refreshPlan(organizationId: Types.ObjectId, workspaceId?: Types.ObjectId) {
|
||||||
if (this.instanceType === "cloud") {
|
if (this.instanceType === "cloud") {
|
||||||
this.localFeatureSet.del(`${organizationId.toString()}-${workspaceId?.toString() ?? ""}`);
|
this.localFeatureSet.del(`${organizationId.toString()}-${workspaceId?.toString() ?? ""}`);
|
||||||
await this.getPlan(organizationId, workspaceId);
|
await this.getPlan(organizationId, workspaceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async delPlan(organizationId: Types.ObjectId) {
|
public async delPlan(organizationId: Types.ObjectId) {
|
||||||
if (this.instanceType === "cloud") {
|
if (this.instanceType === "cloud") {
|
||||||
this.localFeatureSet.del(`${organizationId.toString()}-`);
|
this.localFeatureSet.del(`${organizationId.toString()}-`);
|
||||||
@@ -136,23 +138,23 @@ class EELicenseService {
|
|||||||
if (licenseServerKey) {
|
if (licenseServerKey) {
|
||||||
// license server key is present -> validate it
|
// license server key is present -> validate it
|
||||||
const token = await refreshLicenseServerKeyToken()
|
const token = await refreshLicenseServerKeyToken()
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
this.instanceType = "cloud";
|
this.instanceType = "cloud";
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (licenseKey) {
|
if (licenseKey) {
|
||||||
// license key is present -> validate it
|
// license key is present -> validate it
|
||||||
const token = await refreshLicenseKeyToken();
|
const token = await refreshLicenseKeyToken();
|
||||||
|
|
||||||
if (token) {
|
if (token) {
|
||||||
const { data: { currentPlan } } = await licenseKeyRequest.get(
|
const { data: { currentPlan } } = await licenseKeyRequest.get(
|
||||||
`${await getLicenseServerUrl()}/api/license/v1/plan`
|
`${await getLicenseServerUrl()}/api/license/v1/plan`
|
||||||
);
|
);
|
||||||
|
|
||||||
this.globalFeatureSet = currentPlan;
|
this.globalFeatureSet = currentPlan;
|
||||||
this.instanceType = "enterprise-self-hosted";
|
this.instanceType = "enterprise-self-hosted";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user