mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-12 00:29:04 +00:00
Merge branch 'main' of https://github.com/Infisical/infisical into feat/adds-PAT-to-github-integration
This commit is contained in:
@@ -40,6 +40,7 @@ import {
|
||||
TOrgPlanDTO,
|
||||
TOrgPlansTableDTO,
|
||||
TOrgPmtMethodsDTO,
|
||||
TPlanBillingInfo,
|
||||
TStartOrgTrialDTO,
|
||||
TUpdateOrgBillingDetailsDTO
|
||||
} from "./license-types";
|
||||
@@ -465,6 +466,21 @@ export const licenseServiceFactory = ({
|
||||
return { url };
|
||||
};
|
||||
|
||||
const getUsageMetrics = async (orgId: string) => {
|
||||
const [orgMembersUsed, identityUsed, projectCount] = await Promise.all([
|
||||
orgDAL.countAllOrgMembers(orgId),
|
||||
licenseDAL.countOfOrgIdentities(orgId),
|
||||
projectDAL.countOfOrgProjects(orgId)
|
||||
]);
|
||||
|
||||
return {
|
||||
orgMembersUsed,
|
||||
identityUsed,
|
||||
projectCount,
|
||||
totalIdentities: identityUsed + orgMembersUsed
|
||||
};
|
||||
};
|
||||
|
||||
const getOrgBillingInfo = async ({ orgId, actor, actorId, actorAuthMethod, actorOrgId }: TGetOrgBillInfoDTO) => {
|
||||
const { permission } = await permissionService.getOrgPermission({
|
||||
actorId,
|
||||
@@ -483,10 +499,16 @@ export const licenseServiceFactory = ({
|
||||
});
|
||||
}
|
||||
if (instanceType === InstanceType.Cloud) {
|
||||
const { data } = await licenseServerCloudApi.request.get(
|
||||
const { data } = await licenseServerCloudApi.request.get<TPlanBillingInfo>(
|
||||
`/api/license-server/v1/customers/${organization.customerId}/cloud-plan/billing`
|
||||
);
|
||||
return data;
|
||||
const { identityUsed, orgMembersUsed } = await getUsageMetrics(orgId);
|
||||
|
||||
return {
|
||||
...data,
|
||||
users: orgMembersUsed,
|
||||
identities: identityUsed
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -495,7 +517,9 @@ export const licenseServiceFactory = ({
|
||||
interval: "month",
|
||||
intervalCount: 1,
|
||||
amount: 0,
|
||||
quantity: 1
|
||||
quantity: 1,
|
||||
users: 0,
|
||||
identities: 0
|
||||
};
|
||||
};
|
||||
|
||||
@@ -539,21 +563,6 @@ export const licenseServiceFactory = ({
|
||||
throw new Error(`Unsupported instance type for server-based plan table: ${instanceType}`);
|
||||
};
|
||||
|
||||
const getUsageMetrics = async (orgId: string) => {
|
||||
const [orgMembersUsed, identityUsed, projectCount] = await Promise.all([
|
||||
orgDAL.countAllOrgMembers(orgId),
|
||||
licenseDAL.countOfOrgIdentities(orgId),
|
||||
projectDAL.countOfOrgProjects(orgId)
|
||||
]);
|
||||
|
||||
return {
|
||||
orgMembersUsed,
|
||||
identityUsed,
|
||||
projectCount,
|
||||
totalIdentities: identityUsed + orgMembersUsed
|
||||
};
|
||||
};
|
||||
|
||||
// returns org current plan feature table
|
||||
const getOrgPlanTable = async ({ orgId, actor, actorId, actorAuthMethod, actorOrgId }: TGetOrgBillInfoDTO) => {
|
||||
const { permission } = await permissionService.getOrgPermission({
|
||||
|
||||
@@ -22,6 +22,15 @@ export type TOfflineLicense = {
|
||||
features: TFeatureSet;
|
||||
};
|
||||
|
||||
export type TPlanBillingInfo = {
|
||||
currentPeriodStart: number;
|
||||
currentPeriodEnd: number;
|
||||
interval: "month" | "year";
|
||||
intervalCount: number;
|
||||
amount: number;
|
||||
quantity: number;
|
||||
};
|
||||
|
||||
export type TFeatureSet = {
|
||||
_id: null;
|
||||
slug: string | null;
|
||||
|
||||
@@ -83,9 +83,11 @@ export const extractPrincipalArnEntity = (arn: string, formatAsIamRole: boolean
|
||||
* Extracts the identity ARN from the GetCallerIdentity response to one of the following formats:
|
||||
* - arn:aws:iam::123456789012:user/MyUserName
|
||||
* - arn:aws:iam::123456789012:role/MyRoleName
|
||||
* - arn:aws-us-gov:iam::123456789012:user/MyUserName (GovCloud)
|
||||
* - arn:aws-us-gov:iam::123456789012:role/MyRoleName (GovCloud)
|
||||
*/
|
||||
export const extractPrincipalArn = (arn: string, formatAsIamRole: boolean = false) => {
|
||||
const entity = extractPrincipalArnEntity(arn, formatAsIamRole);
|
||||
|
||||
return `arn:aws:${formatAsIamRole ? "iam" : entity.Service}::${entity.AccountNumber}:${entity.Type}/${entity.FriendlyName}`;
|
||||
return `arn:${entity.Partition}:${formatAsIamRole ? "iam" : entity.Service}::${entity.AccountNumber}:${entity.Type}/${entity.FriendlyName}`;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ const twelveDigitRegex = new RE2(/^\d{12}$/);
|
||||
// akhilmhdh: change this to a normal function later. Checked no redosable at the moment
|
||||
|
||||
const arnRegex = new RE2(
|
||||
/^arn:aws:(iam|sts)::\d{12}:(user\/[a-zA-Z0-9_.@+*/-]+|role\/[a-zA-Z0-9_.@+*/-]+|assumed-role\/[a-zA-Z0-9_.@+*/-]+|\*)$/
|
||||
/^arn:aws(?:-us-gov)?:(iam|sts)::\d{12}:(user\/[a-zA-Z0-9_.@+*/-]+|role\/[a-zA-Z0-9_.@+*/-]+|assumed-role\/[a-zA-Z0-9_.@+*/-]+|\*)$/
|
||||
);
|
||||
|
||||
export const validateAccountIds = z
|
||||
@@ -55,7 +55,7 @@ export const validatePrincipalArns = z
|
||||
},
|
||||
{
|
||||
message:
|
||||
"Each ARN must be in the format of 'arn:aws:iam::123456789012:user/UserName', 'arn:aws:iam::123456789012:role/RoleName', or 'arn:aws:iam::123456789012:*', 'arn:aws:sts::123456789012:assumed-role/RoleName'."
|
||||
"Each ARN must be in the format of 'arn:aws:iam::123456789012:user/UserName', 'arn:aws:iam::123456789012:role/RoleName', or 'arn:aws:iam::123456789012:*', 'arn:aws:sts::123456789012:assumed-role/RoleName'. GovCloud ARNs (arn:aws-us-gov:...) are also supported."
|
||||
}
|
||||
)
|
||||
// Transform to normalize the spaces around commas
|
||||
|
||||
Reference in New Issue
Block a user