-
Notifications
You must be signed in to change notification settings - Fork 62
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
programmatic generate client config starter #43
Conversation
/** | ||
* Gets Amplify backend outputs from stack metadata and outputs | ||
*/ | ||
export class StackMetadataOutputRetrievalStrategy | ||
implements OutputRetrievalStrategy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type and factory should either go to backend-engine or "that long name for package that hosts metadata strategy logic"
Apart from still needing more tests, this is ready for another review. What changed:
|
* This key is shared between stack creation in \@aws-amplify/backend and stack discovery during client config generation. | ||
* It is the "breadcrumb" that enables client config generation to discover the stack outputs for a given project environment | ||
*/ | ||
export const getProjectEnvironmentMainStackSSMParameterKey = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to expose SSM
in the name of this method as it's just an internal detail. It could just be getMainStackIdentifierKey
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep this one as-is. It should be super clear this key is for something very specific, ie using SSM to identify a stack name given a project environment. It shouldn't be used for anything else
packages/backend-engine/src/backend-output/stack_metadata_output_retrieval_strategy.ts
Outdated
Show resolved
Hide resolved
packages/backend-engine/src/backend-output/stack_metadata_output_retrieval_strategy.ts
Show resolved
Hide resolved
packages/backend-engine/src/generate-client-config/stack_name_backend_stack_resolver.ts
Outdated
Show resolved
Hide resolved
...ages/backend-engine/src/generate-client-config/project_environment_backend_stack_resolver.ts
Outdated
Show resolved
Hide resolved
packages/backend/src/project_environment_backend_stack_creator.ts
Outdated
Show resolved
Hide resolved
packages/backend-engine/src/backend-output/stack_metadata_output_retrieval_strategy.ts
Show resolved
Hide resolved
packages/backend-engine/src/generate-client-config/client_config_generator_factory.ts
Outdated
Show resolved
Hide resolved
packages/backend-engine/src/generate-client-config/stack_name_backend_stack_resolver.ts
Outdated
Show resolved
Hide resolved
packages/backend-engine/src/generate-client-config/stack_name_backend_stack_resolver.ts
Outdated
Show resolved
Hide resolved
packages/backend-engine/API.md
Outdated
// @public | ||
export const getProjectEnvironmentMainStackSSMParameterKey: (projectEnvironmentIdentifier: ProjectEnvironmentIdentifier) => string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After giving it more thoughts I think we should think about duplicating this logic in both packages and perhaps enforce that both implementations stay in sync in other ways.
Reason is - how do we roll major version bump if the identifier convention changes in a breaking way.
If we keep it here I suggest to wrap it in namespace since this is kind of leaking implementation details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicating is probably okay here as this is something that will likely never change / would be a huge breaking change if we did
packages/backend-engine/src/backend-output/stack_metadata_output_storage_strategy.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
packages/backend-engine/src/backend-output/stack_metadata_output_retrieval_strategy.ts
Outdated
Show resolved
Hide resolved
packages/backend-engine/src/client-config-generator/client_config_generator.ts
Outdated
Show resolved
Hide resolved
packages/backend-engine/src/client-config-generator/generate_client_config.ts
Show resolved
Hide resolved
...ine/src/client-config-generator/get_project_environment_main_stack_ssm_parameter_key.test.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work, thanks @edwardfoyle
Issue #, if available:
fixes #40
Description of changes:
Needs tests but it's ready for eyes on the overall approach
Starting point for fetching stack output and reconstructing into objects that can be passed to the construct plugins for parsing to frontend config. Only the output fetching and reconstruction is implemented here.
I refactored the ProjectEnvironmentIdentifier class into a new
primitives
package. This allows both the reader and writer of the SSM stack pointer to use the sameProjectEnvironmentIdentifier.toOutputStackSSMParameterName
when resolving the ssm key nameI also added a zod schema for the metadata object that is stored in the stack. This allows the writer and reader to validate against the schema
The generate package introduces several new classes:
backend-engine
. It uses the shared schemas from theprimitives
package to load and validate the stack metadata and outputSome open questions:
BackendIdentificationStrategy
in addition to theOutputStorageStrategy
. TheBackendIdentificationStrategy
should perhaps go in theprimitives
package so thatbackend-engine
can call something likebackendIdStrat.setIdentifier(stack)
and frontend generation can callbackendIdStrat.resolveStackName()
EDIT:
Another idea is instead of a "primitives" package (which could become a dumping ground for "stuff that needs to be shared between different packages"), introduce a "backend-metadata" package that is responsible for reading/writing metadata for a backend. The backend-engine can use this package for writing and the generate package can use it for reading. Essentially the "backend-metadata" package becomes the wrapper around our data layer (which is CFN metadata and outputs)
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.