-
Notifications
You must be signed in to change notification settings - Fork 11
New MCP Tool: AWS Replicator #27
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff94e26
first implementation
HarshCasper ae17f20
add proper preflights
HarshCasper 4792690
add new actions (list, list-resources) to the tool
HarshCasper 348ac16
final fixes
HarshCasper 08d2039
resolve @cloutierMat comments
HarshCasper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| import { | ||
| buildStartReplicationJobRequest, | ||
| formatReplicationJob, | ||
| formatReplicationJobs, | ||
| formatSupportedResources, | ||
| } from "../../tools/localstack-aws-replicator"; | ||
|
|
||
| describe("localstack-aws-replicator", () => { | ||
| const originalEnv = process.env; | ||
|
|
||
| beforeEach(() => { | ||
| process.env = { | ||
| ...originalEnv, | ||
| AWS_ACCESS_KEY_ID: "AKIA...", | ||
| AWS_SECRET_ACCESS_KEY: "secret", | ||
| AWS_DEFAULT_REGION: "us-east-1", | ||
| }; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| process.env = originalEnv; | ||
| }); | ||
|
|
||
| describe("buildStartReplicationJobRequest", () => { | ||
| it("builds a single-resource request from type and identifier using env credentials", () => { | ||
| const request = buildStartReplicationJobRequest({ | ||
| action: "start", | ||
| replication_type: "SINGLE_RESOURCE", | ||
| resource_type: "AWS::EC2::VPC", | ||
| resource_identifier: "vpc-123", | ||
| target_account_id: "111111111111", | ||
| target_region_name: "eu-central-1", | ||
| } as any); | ||
|
|
||
| expect(request).toEqual({ | ||
| replication_type: "SINGLE_RESOURCE", | ||
| replication_job_config: { | ||
| resource_type: "AWS::EC2::VPC", | ||
| resource_identifier: "vpc-123", | ||
| }, | ||
| source_aws_config: { | ||
| aws_access_key_id: "AKIA...", | ||
| aws_secret_access_key: "secret", | ||
| region_name: "us-east-1", | ||
| }, | ||
| target_aws_config: { | ||
| aws_access_key_id: "111111111111", | ||
| aws_secret_access_key: "test", | ||
| region_name: "eu-central-1", | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("builds a resource ARN request without requiring resource type using env credentials", () => { | ||
| process.env.AWS_SESSION_TOKEN = "token"; | ||
| process.env.AWS_ENDPOINT_URL = "https://example.com"; | ||
|
|
||
| const request = buildStartReplicationJobRequest({ | ||
| action: "start", | ||
| replication_type: "SINGLE_RESOURCE", | ||
| resource_arn: "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret", | ||
| } as any); | ||
|
|
||
| expect(request).toEqual({ | ||
| replication_type: "SINGLE_RESOURCE", | ||
| replication_job_config: { | ||
| resource_arn: "arn:aws:secretsmanager:us-east-1:123456789012:secret:my-secret", | ||
| }, | ||
| source_aws_config: { | ||
| aws_access_key_id: "AKIA...", | ||
| aws_secret_access_key: "secret", | ||
| aws_session_token: "token", | ||
| region_name: "us-east-1", | ||
| endpoint_url: "https://example.com", | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it("does not mix prefixed source credentials with generic AWS session values", () => { | ||
| process.env.AWS_REPLICATOR_SOURCE_AWS_ACCESS_KEY_ID = "replicator-key"; | ||
| process.env.AWS_REPLICATOR_SOURCE_AWS_SECRET_ACCESS_KEY = "replicator-secret"; | ||
| process.env.AWS_REPLICATOR_SOURCE_REGION_NAME = "eu-west-1"; | ||
| process.env.AWS_SESSION_TOKEN = "generic-token"; | ||
|
|
||
| const request = buildStartReplicationJobRequest({ | ||
| action: "start", | ||
| replication_type: "SINGLE_RESOURCE", | ||
| resource_type: "AWS::SSM::Parameter", | ||
| resource_identifier: "my-param", | ||
| } as any); | ||
|
|
||
| expect(request.source_aws_config).toEqual({ | ||
| aws_access_key_id: "replicator-key", | ||
| aws_secret_access_key: "replicator-secret", | ||
| region_name: "eu-west-1", | ||
| }); | ||
| }); | ||
|
|
||
| it("does not allow a target endpoint URL override", () => { | ||
| process.env.AWS_REPLICATOR_TARGET_ENDPOINT_URL = "https://not-localstack.example.com"; | ||
|
|
||
| const request = buildStartReplicationJobRequest({ | ||
| action: "start", | ||
| replication_type: "SINGLE_RESOURCE", | ||
| resource_type: "AWS::EC2::VPC", | ||
| resource_identifier: "vpc-123", | ||
| target_region_name: "eu-central-1", | ||
| } as any); | ||
|
|
||
| expect(request.target_aws_config).toEqual({ | ||
| aws_access_key_id: "test", | ||
| aws_secret_access_key: "test", | ||
| region_name: "eu-central-1", | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formatReplicationJob", () => { | ||
| it("includes batch result details", () => { | ||
| const formatted = formatReplicationJob("AWS Replicator Job Status", { | ||
| job_id: "job-123", | ||
| state: "SUCCEEDED", | ||
| type: "BATCH", | ||
| replication_config: { | ||
| resource_type: "AWS::SSM::Parameter", | ||
| identifier: "/dev/", | ||
| }, | ||
| result: { | ||
| resources_succeeded: 2, | ||
| resources_failed: 0, | ||
| }, | ||
| }); | ||
|
|
||
| expect(formatted).toContain("AWS Replicator Job Status"); | ||
| expect(formatted).toContain("`job-123`"); | ||
| expect(formatted).toContain("resources_succeeded"); | ||
| expect(formatted).toContain("AWS::SSM::Parameter"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formatReplicationJobs", () => { | ||
| it("summarizes listed jobs and includes the raw response", () => { | ||
| const formatted = formatReplicationJobs([ | ||
| { | ||
| job_id: "job-123", | ||
| state: "SUCCEEDED", | ||
| type: "SINGLE_RESOURCE", | ||
| replication_config: { | ||
| resource_type: "AWS::EC2::VPC", | ||
| resource_identifier: "vpc-123", | ||
| }, | ||
| }, | ||
| ]); | ||
|
|
||
| expect(formatted).toContain("AWS Replicator Jobs"); | ||
| expect(formatted).toContain("job-123"); | ||
| expect(formatted).toContain("SUCCEEDED"); | ||
| expect(formatted).toContain("Raw Response"); | ||
| }); | ||
| }); | ||
|
|
||
| describe("formatSupportedResources", () => { | ||
| it("summarizes supported resource types and identifiers", () => { | ||
| const formatted = formatSupportedResources([ | ||
| { | ||
| resource_type: "AWS::SSM::Parameter", | ||
| service: "ssm", | ||
| identifier: "Name", | ||
| }, | ||
| ]); | ||
|
|
||
| expect(formatted).toContain("AWS Replicator Supported Resources"); | ||
| expect(formatted).toContain("AWS::SSM::Parameter"); | ||
| expect(formatted).toContain("identifier: `Name`"); | ||
| expect(formatted).toContain("Raw Response"); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.