mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-09 07:28:21 +00:00
added boolean flag for the plan in posthog logging
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import to from 'await-to-js';
|
import to from 'await-to-js';
|
||||||
import { Types } from 'mongoose';
|
import { Types } from 'mongoose';
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
import { ISecret, Secret } from '../../models';
|
import { ISecret, Secret, Workspace } from '../../models';
|
||||||
import { IAction, SecretVersion } from '../../ee/models';
|
import { IAction, SecretVersion } from '../../ee/models';
|
||||||
import {
|
import {
|
||||||
SECRET_PERSONAL,
|
SECRET_PERSONAL,
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
import { UnauthorizedRequestError, ValidationError } from '../../utils/errors';
|
import { UnauthorizedRequestError, ValidationError } from '../../utils/errors';
|
||||||
import { EventService } from '../../services';
|
import { EventService } from '../../services';
|
||||||
import { eventPushSecrets } from '../../events';
|
import { eventPushSecrets } from '../../events';
|
||||||
import { EESecretService, EELogService } from '../../ee/services';
|
import { EESecretService, EELogService, EELicenseService } from '../../ee/services';
|
||||||
import { TelemetryService, SecretService } from '../../services';
|
import { TelemetryService, SecretService } from '../../services';
|
||||||
import { getChannelFromUserAgent } from '../../utils/posthog';
|
import { getChannelFromUserAgent } from '../../utils/posthog';
|
||||||
import { PERMISSION_WRITE_SECRETS } from '../../variables';
|
import { PERMISSION_WRITE_SECRETS } from '../../variables';
|
||||||
@@ -48,6 +48,14 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
environment: string;
|
environment: string;
|
||||||
requests: BatchSecretRequest[];
|
requests: BatchSecretRequest[];
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
|
const organizationId = (
|
||||||
|
await Workspace.findOne({
|
||||||
|
_id: workspaceId
|
||||||
|
})
|
||||||
|
)?.organization?.toString();
|
||||||
|
const orgPlan = await EELicenseService.getOrganizationPlan(organizationId || '');
|
||||||
|
const isPaid = orgPlan.slug != 'starter';
|
||||||
|
|
||||||
const createSecrets: BatchSecret[] = [];
|
const createSecrets: BatchSecret[] = [];
|
||||||
const updateSecrets: BatchSecret[] = [];
|
const updateSecrets: BatchSecret[] = [];
|
||||||
@@ -139,7 +147,8 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
environment,
|
environment,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
channel,
|
channel,
|
||||||
userAgent: req.headers?.['user-agent']
|
userAgent: req.headers?.['user-agent'],
|
||||||
|
isPaid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -226,7 +235,8 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
environment,
|
environment,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
channel,
|
channel,
|
||||||
userAgent: req.headers?.['user-agent']
|
userAgent: req.headers?.['user-agent'],
|
||||||
|
isPaid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -261,7 +271,8 @@ export const batchSecrets = async (req: Request, res: Response) => {
|
|||||||
environment,
|
environment,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
userAgent: req.headers?.['user-agent']
|
userAgent: req.headers?.['user-agent'],
|
||||||
|
isPaid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -376,6 +387,14 @@ export const createSecrets = async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const organizationId = (
|
||||||
|
await Workspace.findOne({
|
||||||
|
_id: workspaceId
|
||||||
|
})
|
||||||
|
)?.organization?.toString();
|
||||||
|
const orgPlan = await EELicenseService.getOrganizationPlan(organizationId || '');
|
||||||
|
const isPaid = orgPlan.slug != 'starter';
|
||||||
|
|
||||||
let listOfSecretsToCreate;
|
let listOfSecretsToCreate;
|
||||||
if (Array.isArray(req.body.secrets)) {
|
if (Array.isArray(req.body.secrets)) {
|
||||||
// case: create multiple secrets
|
// case: create multiple secrets
|
||||||
@@ -531,7 +550,8 @@ export const createSecrets = async (req: Request, res: Response) => {
|
|||||||
environment,
|
environment,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
userAgent: req.headers?.['user-agent']
|
userAgent: req.headers?.['user-agent'],
|
||||||
|
isPaid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -595,6 +615,14 @@ export const getSecrets = async (req: Request, res: Response) => {
|
|||||||
const normalizedPath = normalizePath(secretsPath as string)
|
const normalizedPath = normalizePath(secretsPath as string)
|
||||||
const folders = await getFoldersInDirectory(workspaceId as string, environment as string, normalizedPath)
|
const folders = await getFoldersInDirectory(workspaceId as string, environment as string, normalizedPath)
|
||||||
|
|
||||||
|
const organizationId = (
|
||||||
|
await Workspace.findOne({
|
||||||
|
_id: workspaceId
|
||||||
|
})
|
||||||
|
)?.organization?.toString();
|
||||||
|
const orgPlan = await EELicenseService.getOrganizationPlan(organizationId || '');
|
||||||
|
const isPaid = orgPlan.slug != 'starter';
|
||||||
|
|
||||||
// secrets to return
|
// secrets to return
|
||||||
let secrets: ISecret[] = [];
|
let secrets: ISecret[] = [];
|
||||||
|
|
||||||
@@ -727,7 +755,8 @@ export const getSecrets = async (req: Request, res: Response) => {
|
|||||||
environment,
|
environment,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
channel,
|
channel,
|
||||||
userAgent: req.headers?.['user-agent']
|
userAgent: req.headers?.['user-agent'],
|
||||||
|
isPaid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -938,6 +967,14 @@ export const updateSecrets = async (req: Request, res: Response) => {
|
|||||||
workspaceId: new Types.ObjectId(key)
|
workspaceId: new Types.ObjectId(key)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const organizationId = (
|
||||||
|
await Workspace.findOne({
|
||||||
|
_id: key
|
||||||
|
})
|
||||||
|
)?.organization?.toString();
|
||||||
|
const orgPlan = await EELicenseService.getOrganizationPlan(organizationId || '');
|
||||||
|
const isPaid = orgPlan.slug != 'starter';
|
||||||
|
|
||||||
const postHogClient = await TelemetryService.getPostHogClient();
|
const postHogClient = await TelemetryService.getPostHogClient();
|
||||||
if (postHogClient) {
|
if (postHogClient) {
|
||||||
postHogClient.capture({
|
postHogClient.capture({
|
||||||
@@ -950,7 +987,8 @@ export const updateSecrets = async (req: Request, res: Response) => {
|
|||||||
environment: workspaceSecretObj[key][0].environment,
|
environment: workspaceSecretObj[key][0].environment,
|
||||||
workspaceId: key,
|
workspaceId: key,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
userAgent: req.headers?.['user-agent']
|
userAgent: req.headers?.['user-agent'],
|
||||||
|
isPaid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1072,6 +1110,14 @@ export const deleteSecrets = async (req: Request, res: Response) => {
|
|||||||
workspaceId: new Types.ObjectId(key)
|
workspaceId: new Types.ObjectId(key)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const organizationId = (
|
||||||
|
await Workspace.findOne({
|
||||||
|
_id: key
|
||||||
|
})
|
||||||
|
)?.organization?.toString();
|
||||||
|
const orgPlan = await EELicenseService.getOrganizationPlan(organizationId || '');
|
||||||
|
const isPaid = orgPlan.slug != 'starter';
|
||||||
|
|
||||||
const postHogClient = await TelemetryService.getPostHogClient();
|
const postHogClient = await TelemetryService.getPostHogClient();
|
||||||
if (postHogClient) {
|
if (postHogClient) {
|
||||||
postHogClient.capture({
|
postHogClient.capture({
|
||||||
@@ -1084,7 +1130,8 @@ export const deleteSecrets = async (req: Request, res: Response) => {
|
|||||||
environment: workspaceSecretObj[key][0].environment,
|
environment: workspaceSecretObj[key][0].environment,
|
||||||
workspaceId: key,
|
workspaceId: key,
|
||||||
channel: channel,
|
channel: channel,
|
||||||
userAgent: req.headers?.['user-agent']
|
userAgent: req.headers?.['user-agent'],
|
||||||
|
isPaid
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user