-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
16 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { Construct } from 'constructs'; | ||
import { BackendSecretFetcherProviderFactory } from './backend_secret_fetcher_provider_factory.js'; | ||
import { CustomResource } from 'aws-cdk-lib'; | ||
import { CustomResource, Lazy } from 'aws-cdk-lib'; | ||
import { BackendIdentifier } from '@aws-amplify/plugin-types'; | ||
import { SecretResourceProps } from './lambda/backend_secret_fetcher_types.js'; | ||
|
||
|
@@ -18,7 +18,7 @@ const SECRET_RESOURCE_TYPE = `Custom::SecretFetcherResource`; | |
* The factory to create backend secret-fetcher resource. | ||
*/ | ||
export class BackendSecretFetcherFactory { | ||
static secretNames: Set<string> = new Set<string>(); | ||
private readonly secretNames: Set<string> = new Set<string>(); | ||
|
||
/** | ||
* Creates a backend secret-fetcher resource factory. | ||
|
@@ -27,29 +27,16 @@ export class BackendSecretFetcherFactory { | |
private readonly secretProviderFactory: BackendSecretFetcherProviderFactory | ||
) {} | ||
|
||
/** | ||
* Register secrets that to be fetched by the BackendSecretFetcher custom resource.\ | ||
* @param secretName the name of the secret | ||
*/ | ||
static registerSecret = (secretName: string): void => { | ||
BackendSecretFetcherFactory.secretNames.add(secretName); | ||
}; | ||
|
||
/** | ||
* Clear registered secrets that will be fetched by the BackendSecretFetcher custom resource. | ||
*/ | ||
static clearRegisteredSecrets = (): void => { | ||
BackendSecretFetcherFactory.secretNames.clear(); | ||
}; | ||
|
||
/** | ||
* Returns a resource if it exists in the input scope. Otherwise, | ||
* creates a new one. | ||
*/ | ||
getOrCreate = ( | ||
scope: Construct, | ||
backendIdentifier: BackendIdentifier | ||
backendIdentifier: BackendIdentifier, | ||
secretName: string | ||
): CustomResource => { | ||
this.secretNames.add(secretName); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sobolk
Author
Member
|
||
const secretResourceId = `SecretFetcherResource`; | ||
const existingResource = scope.node.tryFindChild( | ||
secretResourceId | ||
|
@@ -75,7 +62,9 @@ export class BackendSecretFetcherFactory { | |
namespace: backendIdentifier.namespace, | ||
name: backendIdentifier.name, | ||
type: backendIdentifier.type, | ||
secretNames: Array.from(BackendSecretFetcherFactory.secretNames), | ||
secretNames: Lazy.list({ | ||
produce: () => Array.from(this.secretNames), | ||
}), | ||
}; | ||
|
||
return new CustomResource(scope, secretResourceId, { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this is effectively the same thing as using a static, but now it more unclear that this is global, because to know it's global requires knowing we initialize the BackendSecretFetcherFactory exactly once in secret.ts