Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(secretsmanager): Remove unused secretName attribute #10410

Merged
merged 2 commits into from
Sep 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions packages/@aws-cdk/aws-secretsmanager/lib/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,6 @@ export interface SecretAttributes {
* The ARN of the secret in SecretsManager.
*/
readonly secretArn: string;

/**
* The name of the secret in SecretsManager.
*
* @default - the name is derived from the secretArn.
*/
readonly secretName?: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would argue that a better DX is to only support secretName, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to only support secretName

We can't stop supporting secretArn as an attribute, no.

You mean make secretArn optional, and add back in secretName as optional, then a validation in fromSecretAttributes that at least one is present? We can do that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to only support secretName

We can't stop supporting secretArn as an attribute, no.

You mean make secretArn optional, and add back in secretName as optional, then a validation in fromSecretAttributes that at least one is present? We can do that.

I guess that could work although generally against our api guidelines (normally in such cases we prefer something like union-like classes). I am okay with how it is now

}

/**
Expand Down Expand Up @@ -286,7 +279,7 @@ export class Secret extends SecretBase {
class Import extends SecretBase {
public readonly encryptionKey = attrs.encryptionKey;
public readonly secretArn = attrs.secretArn;
public readonly secretName = parseSecretName(scope, attrs.secretArn, attrs.secretName);
public readonly secretName = parseSecretName(scope, attrs.secretArn);
protected readonly autoCreatePolicy = false;
}

Expand Down Expand Up @@ -601,9 +594,8 @@ export interface SecretStringGenerator {
readonly generateStringKey?: string;
}

/** Returns the secret name if defined, otherwise attempts to parse it from the ARN. */
export function parseSecretName(construct: IConstruct, secretArn: string, secretName?: string) {
if (secretName) { return secretName; }
/** Parses the secret name from the ARN. */
function parseSecretName(construct: IConstruct, secretArn: string) {
const resourceName = Stack.of(construct).parseArn(secretArn).resourceName;
if (resourceName) {
// Secret resource names are in the format `${secretName}-${SecretsManager suffix}`
Expand Down