|
3 | 3 | * SPDX-License-Identifier: BUSL-1.1 |
4 | 4 | */ |
5 | 5 |
|
6 | | -import Form from 'vault/forms/form'; |
7 | 6 | import FormField from 'vault/utils/forms/field'; |
8 | 7 | import FormFieldGroup from 'vault/utils/forms/field-group'; |
9 | | -import { commonFields, getPayload } from './shared'; |
| 8 | +import { regions } from 'vault/helpers/aws-regions'; |
| 9 | +import { CredentialType, DestinationType } from 'sync/utils/constants'; |
| 10 | +import CreateDestinationForm from './create-destination'; |
10 | 11 |
|
11 | 12 | import type { SystemWriteSyncDestinationsAwsSmNameRequest } from '@hashicorp/vault-client-typescript'; |
12 | 13 |
|
13 | 14 | type AwsSmFormData = SystemWriteSyncDestinationsAwsSmNameRequest & { |
14 | 15 | name: string; |
| 16 | + credential_type: CredentialType; |
15 | 17 | }; |
16 | 18 |
|
17 | | -export default class AwsSmForm extends Form<AwsSmFormData> { |
18 | | - formFieldGroups = [ |
19 | | - new FormFieldGroup('default', [ |
20 | | - commonFields.name, |
21 | | - new FormField('region', 'string', { |
22 | | - subText: |
23 | | - 'For AWS secrets manager, the name of the region must be supplied, something like “us-west-1.” If empty, Vault will use the AWS_REGION environment variable if configured.', |
24 | | - editDisabled: true, |
25 | | - }), |
26 | | - new FormField('role_arn', 'string', { |
27 | | - label: 'Role ARN', |
28 | | - subText: |
29 | | - 'Specifies a role to assume when connecting to AWS. When assuming a role, Vault uses temporary STS credentials to authenticate.', |
30 | | - }), |
31 | | - new FormField('external_id', 'string', { |
32 | | - label: 'External ID', |
33 | | - subText: |
34 | | - 'Optional extra protection that must match the trust policy granting access to the AWS IAM role ARN. We recommend using a different random UUID per destination.', |
35 | | - }), |
36 | | - ]), |
37 | | - new FormFieldGroup('Credentials', [ |
38 | | - new FormField('access_key_id', 'string', { |
39 | | - label: 'Access key ID', |
40 | | - subText: |
41 | | - 'Access key ID to authenticate against the secrets manager. If empty, Vault will use the AWS_ACCESS_KEY_ID environment variable if configured.', |
42 | | - sensitive: true, |
43 | | - noCopy: true, |
44 | | - }), |
45 | | - new FormField('secret_access_key', 'string', { |
46 | | - label: 'Secret access key', |
47 | | - subText: |
48 | | - 'Secret access key to authenticate against the secrets manager. If empty, Vault will use the AWS_SECRET_ACCESS_KEY environment variable if configured.', |
49 | | - sensitive: true, |
50 | | - noCopy: true, |
51 | | - }), |
52 | | - ]), |
53 | | - new FormFieldGroup('Advanced configuration', [ |
54 | | - commonFields.granularity, |
55 | | - commonFields.secretNameTemplate, |
56 | | - commonFields.customTags, |
57 | | - ]), |
58 | | - ]; |
| 19 | +export default class AwsSmForm extends CreateDestinationForm<AwsSmFormData> { |
| 20 | + get isAccountPluginConfigured() { |
| 21 | + return !!this.data.access_key_id; |
| 22 | + } |
| 23 | + |
| 24 | + get isWifPluginConfigured() { |
| 25 | + const { identity_token_audience, identity_token_ttl, role_arn } = this.data; |
| 26 | + return !!identity_token_audience || !!identity_token_ttl || !!role_arn; |
| 27 | + } |
| 28 | + |
| 29 | + accountCredentialGroup = new FormFieldGroup('IAM credentials', [ |
| 30 | + new FormField('access_key_id', 'string', { |
| 31 | + label: 'Access key ID', |
| 32 | + subText: |
| 33 | + 'Access key ID to authenticate against the secrets manager. If empty, Vault will use the AWS_ACCESS_KEY_ID environment variable if configured.', |
| 34 | + sensitive: true, |
| 35 | + noCopy: true, |
| 36 | + }), |
| 37 | + new FormField('secret_access_key', 'string', { |
| 38 | + label: 'Secret access key', |
| 39 | + subText: |
| 40 | + 'Secret access key to authenticate against the secrets manager. If empty, Vault will use the AWS_SECRET_ACCESS_KEY environment variable if configured.', |
| 41 | + sensitive: true, |
| 42 | + noCopy: true, |
| 43 | + }), |
| 44 | + ]); |
| 45 | + |
| 46 | + get wifCredentialGroup() { |
| 47 | + return this.createWifCredentialGroup(); |
| 48 | + } |
| 49 | + |
| 50 | + get formFieldGroups() { |
| 51 | + const credentialGroup = |
| 52 | + this.credentialType === CredentialType.ACCOUNT ? this.accountCredentialGroup : this.wifCredentialGroup; |
| 53 | + return [ |
| 54 | + new FormFieldGroup('Destination details', [ |
| 55 | + this.commonFields.name, |
| 56 | + new FormField('region', 'string', { |
| 57 | + possibleValues: regions(), |
| 58 | + noDefault: true, |
| 59 | + subText: |
| 60 | + 'For AWS secrets manager, the name of the region must be supplied, something like “us-west-1.” If empty, Vault will use the AWS_REGION environment variable if configured.', |
| 61 | + editDisabled: true, |
| 62 | + }), |
| 63 | + new FormField('role_arn', 'string', { |
| 64 | + label: 'Role ARN', |
| 65 | + subText: |
| 66 | + 'Specifies a role to assume when connecting to AWS. When assuming a role, Vault uses temporary STS credentials to authenticate.', |
| 67 | + }), |
| 68 | + new FormField('external_id', 'string', { |
| 69 | + label: 'External ID', |
| 70 | + subText: |
| 71 | + 'Optional extra protection that must match the trust policy granting access to the AWS IAM role ARN. We recommend using a different random UUID per destination.', |
| 72 | + }), |
| 73 | + ]), |
| 74 | + credentialGroup, |
| 75 | + new FormFieldGroup('Advanced configuration', [ |
| 76 | + this.commonFields.granularity, |
| 77 | + this.commonFields.secretNameTemplate, |
| 78 | + this.commonFields.customTags, |
| 79 | + ]), |
| 80 | + ]; |
| 81 | + } |
59 | 82 |
|
60 | 83 | toJSON() { |
61 | 84 | const formState = super.toJSON(); |
62 | | - const data = getPayload<AwsSmFormData>('aws-sm', this.data, this.isNew); |
| 85 | + const data = this.getPayload<AwsSmFormData>(DestinationType.AwsSm, this.data, this.isNew); |
63 | 86 | return { ...formState, data }; |
64 | 87 | } |
65 | 88 | } |
0 commit comments