Refactor EE secret versioning/snapshot access

This commit is contained in:
Tuan Dang
2022-12-25 20:04:27 -05:00
parent 8f765cba57
commit 9f724b5ede
7 changed files with 68 additions and 30 deletions
+12 -15
View File
@@ -1,22 +1,19 @@
import { LICENSE_KEY } from '../../config';
/**
* Class to handle Enterprise Edition license actions
*/
class EELicenseService {
/**
* Check if license key [licenseKey] corresponds to a
* valid Infisical Enterprise Edition license.
* @param {Object} obj
* @param {Object} obj.licenseKey
* @returns {Boolean}
*/
static async checkLicense({
licenseKey
}: {
licenseKey: string;
}) {
// TODO
return true;
private readonly _isLicenseValid: boolean;
constructor(licenseKey: string) {
this._isLicenseValid = true;
}
public get isLicenseValid(): boolean {
return this._isLicenseValid;
}
}
export default EELicenseService;
export default new EELicenseService(LICENSE_KEY);
+22 -2
View File
@@ -1,4 +1,8 @@
import { takeSecretSnapshotHelper } from '../helpers/secret';
import { ISecretVersion } from '../models';
import {
takeSecretSnapshotHelper,
addSecretVersionsHelper
} from '../helpers/secret';
import EELicenseService from './EELicenseService';
/**
@@ -21,9 +25,25 @@ class EESecretService {
licenseKey: string;
workspaceId: string;
}) {
EELicenseService.checkLicense({ licenseKey });
if (!EELicenseService.isLicenseValid) return;
await takeSecretSnapshotHelper({ workspaceId });
}
/**
* Adds secret versions [secretVersions] to the SecretVersion collection.
* @param {Object} obj
* @param {SecretVersion} obj.secretVersions
*/
static async addSecretVersions({
secretVersions
}: {
secretVersions: ISecretVersion[];
}) {
if (!EELicenseService.isLicenseValid) return;
await addSecretVersionsHelper({
secretVersions
});
}
}
export default EESecretService;