mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-04 22:26:15 +00:00
misc: changed order of aws validate connection and creation
This commit is contained in:
@@ -73,12 +73,11 @@ export const externalKmsServiceFactory = ({
|
|||||||
case KmsProviders.Aws:
|
case KmsProviders.Aws:
|
||||||
{
|
{
|
||||||
const externalKms = await AwsKmsProviderFactory({ inputs: provider.inputs });
|
const externalKms = await AwsKmsProviderFactory({ inputs: provider.inputs });
|
||||||
if (provider.inputs.kmsKeyId) {
|
|
||||||
await externalKms.validateConnection();
|
|
||||||
}
|
|
||||||
// if missing kms key this generate a new kms key id and returns new provider input
|
// if missing kms key this generate a new kms key id and returns new provider input
|
||||||
const newProviderInput = await externalKms.generateInputKmsKey();
|
const newProviderInput = await externalKms.generateInputKmsKey();
|
||||||
sanitizedProviderInput = JSON.stringify(newProviderInput);
|
sanitizedProviderInput = JSON.stringify(newProviderInput);
|
||||||
|
|
||||||
|
await externalKms.validateConnection();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -50,17 +50,26 @@ type TAwsKmsProviderFactoryReturn = TExternalKmsProviderFns & {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const AwsKmsProviderFactory = async ({ inputs }: AwsKmsProviderArgs): Promise<TAwsKmsProviderFactoryReturn> => {
|
export const AwsKmsProviderFactory = async ({ inputs }: AwsKmsProviderArgs): Promise<TAwsKmsProviderFactoryReturn> => {
|
||||||
const providerInputs = await ExternalKmsAwsSchema.parseAsync(inputs);
|
let providerInputs = await ExternalKmsAwsSchema.parseAsync(inputs);
|
||||||
const awsClient = await getAwsKmsClient(providerInputs);
|
let awsClient = await getAwsKmsClient(providerInputs);
|
||||||
|
|
||||||
const generateInputKmsKey = async () => {
|
const generateInputKmsKey = async () => {
|
||||||
if (providerInputs.kmsKeyId) return providerInputs;
|
if (providerInputs.kmsKeyId) return providerInputs;
|
||||||
|
|
||||||
const command = new CreateKeyCommand({ Tags: [{ TagKey: "author", TagValue: "infisical" }] });
|
const command = new CreateKeyCommand({ Tags: [{ TagKey: "author", TagValue: "infisical" }] });
|
||||||
const kmsKey = await awsClient.send(command);
|
const kmsKey = await awsClient.send(command);
|
||||||
|
|
||||||
if (!kmsKey.KeyMetadata?.KeyId) throw new Error("Failed to generate kms key");
|
if (!kmsKey.KeyMetadata?.KeyId) throw new Error("Failed to generate kms key");
|
||||||
|
|
||||||
return { ...providerInputs, kmsKeyId: kmsKey.KeyMetadata?.KeyId };
|
const updatedProviderInputs = await ExternalKmsAwsSchema.parseAsync({
|
||||||
|
...providerInputs,
|
||||||
|
kmsKeyId: kmsKey.KeyMetadata?.KeyId
|
||||||
|
});
|
||||||
|
|
||||||
|
providerInputs = updatedProviderInputs;
|
||||||
|
awsClient = await getAwsKmsClient(providerInputs);
|
||||||
|
|
||||||
|
return updatedProviderInputs;
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateConnection = async () => {
|
const validateConnection = async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user