mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 21:37:59 +00:00
Add support for pulling plan details from license server with LICENSE_KEY, LICENSE_SERVER_KEY
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user