feat(dynamic-secret): Minor improvements on usernameTemplate

This commit is contained in:
carlosmonastyrski
2025-06-05 17:18:56 -03:00
parent 5367d1ac2e
commit ac5bfbb6c9
33 changed files with 138 additions and 145 deletions
@@ -24,14 +24,14 @@ import { alphaNumericNanoId } from "@app/lib/nanoid";
import { DynamicSecretAwsIamSchema, TDynamicProviderFns } from "./models";
import { compileUsernameTemplate } from "./templateUtils";
const generateUsername = (usernameTemplate?: string | null, identityName?: string) => {
const generateUsername = (usernameTemplate?: string | null, identity?: { name: string }) => {
const randomUsername = alphaNumericNanoId(32);
if (!usernameTemplate) return randomUsername;
return compileUsernameTemplate({
usernameTemplate,
randomUsername,
identityName
identity
});
};
@@ -65,14 +65,16 @@ export const AwsIamProvider = (): TDynamicProviderFns => {
inputs: unknown;
expireAt: number;
usernameTemplate?: string | null;
identityName?: string;
identity?: {
name: string;
};
}) => {
const { inputs, usernameTemplate, identityName } = data;
const { inputs, usernameTemplate, identity } = data;
const providerInputs = await validateProviderInputs(inputs);
const client = await $getClient(providerInputs);
const username = generateUsername(usernameTemplate, identityName);
const username = generateUsername(usernameTemplate, identity);
const { policyArns, userGroups, policyDocument, awsPath, permissionBoundaryPolicyArn } = providerInputs;
const createUserRes = await client.send(
new CreateUserCommand({