Add support for pulling plan details from license server with LICENSE_KEY, LICENSE_SERVER_KEY

This commit is contained in:
Tuan Dang
2023-05-22 15:43:33 +03:00
parent 2f765600b1
commit 8341faddc5
24 changed files with 422 additions and 88 deletions
+39
View File
@@ -0,0 +1,39 @@
import { Types } from 'mongoose';
import * as Sentry from '@sentry/node';
import { Organization } from '../../models';
import { EELicenseService } from '../services';
import { getLicenseServerUrl } from '../../config';
import { licenseServerKeyRequest } from '../../config/request';
import { OrganizationNotFoundError } from '../../utils/errors';
export const getOrganizationPlanHelper = async ({
organizationId
}: {
organizationId: Types.ObjectId;
}) => {
try {
if (EELicenseService.instanceType === 'cloud') {
// instance of Infisical is a cloud instance
const organization = await Organization.findById(organizationId);
if (!organization) throw OrganizationNotFoundError();
const cachedPlan = EELicenseService.localFeatureSet.get(organizationId.toString());
if (cachedPlan) return cachedPlan;
const { data: { currentPlan } } = await licenseServerKeyRequest.get(
`${await getLicenseServerUrl()}/api/license-server/v1/customers/${organization.customerId}/cloud-plan`
);
// cache fetched plan for organization
EELicenseService.localFeatureSet.set(organizationId.toString(), currentPlan);
return currentPlan;
}
return EELicenseService.globalFeatureSet;
} catch (err) {
Sentry.setUser(null);
Sentry.captureException(err);
return EELicenseService.globalFeatureSet;
}
}