mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 14:10:49 -05:00
* feat(redshift): implement snapshot copy grant lifecycle Terraform's aws_redshift_snapshot_copy_grant needs the full CRUD, and all three actions returned InvalidAction. Add CreateSnapshotCopyGrant, DescribeSnapshotCopyGrants and DeleteSnapshotCopyGrant to the Query handler, backed by a new storage map on RedshiftService. The grant name is the key: a duplicate create raises SnapshotCopyGrantAlreadyExistsFault, and describe-by-name or delete of a missing grant raises SnapshotCopyGrantNotFoundFault. Describe without a name returns every grant. KmsKeyId is optional and defaults to the account's AWS-managed Redshift key alias ARN, mirroring how Ec2EbsEncryptionService stands in for a default key. Tags ride along on create, since the CLI sends them inline as Tags.Tag.N.Key/.Value on this action rather than via CreateTags, and snapshotcopygrant ARNs now resolve in the tagging operations alongside the other Redshift resource types. * test(redshift): cover snapshot copy grants through the real SDK * fix(redshift): paginate DescribeSnapshotCopyGrants The action returned every grant in one page and ignored MaxRecords and Marker, so a client with more grants than fit in a page had no way to walk them. Page through the shared Pagination helper, which sorts by the grant name and encodes the last returned name as an opaque base64 cursor, so ordering is stable and a marker stays resumable when grants are created or deleted between pages. Marker is emitted only while further pages remain, which is what tells a paginating client to stop. MaxRecords follows the Redshift model: default 100, and a value outside 20 to 100 is rejected with InvalidParameterValue rather than clamped. The model documents SnapshotCopyGrantName and Marker as mutually exclusive but declares no error for sending both, so this filters by name and then paginates instead of rejecting the pair. A name matches at most one grant, which fits in any page. * fix(redshift): enforce the SnapshotCopyGrantName contract AWS validates SnapshotCopyGrantName as 1-63 characters, first a lowercase letter, then lowercase letters, digits or single hyphens with no trailing or doubled hyphen. Create accepted anything non-blank, so names Redshift rejects (1grant, Grant, grant--copy, grant-, 64 characters) persisted locally and diverged from AWS. Validate in RedshiftService before persistence, matching the existing snapshot identifier check, and answer InvalidParameterValue as the rest of the handler does. * fix(redshift): return 400 for SnapshotCopyGrantNotFoundFault on Describe and Delete AWS documents SnapshotCopyGrantNotFoundFault as HTTP 400 in the error tables for both DescribeSnapshotCopyGrants and DeleteSnapshotCopyGrant; we returned 404. Two existing wire-level assertions in RedshiftOperationsTest pinned the wrong status, so they move with the code, and the unit tests now assert the status alongside the error code. The third throw site, in the tagging helper, deliberately stays 404: the status belongs to the action rather than the fault code, and that path is reached only from CreateTags/DeleteTags/DescribeTags, whose documented missing-resource error is ResourceNotFoundFault at 404. A regression pins that, and a comment says why the two differ. Refs: https://docs.aws.amazon.com/redshift/latest/APIReference/API_DescribeSnapshotCopyGrants.html https://docs.aws.amazon.com/redshift/latest/APIReference/API_DeleteSnapshotCopyGrant.html https://docs.aws.amazon.com/redshift/latest/APIReference/API_CreateTags.html * fix(redshift): serialize grant create/delete, and use ResourceNotFoundFault on the tag path Two findings from the latest review round. createSnapshotCopyGrant checked the name was free and then wrote, with nothing between the two steps, so two concurrent creates of one name could both succeed and the second would overwrite the first. create and delete are now synchronized, as createCluster and modifyCluster already are. The new wire-level test holds two threads on a latch and releases them into the same name: it fails on every run without the keyword (3/3 locally) and passes with it, so it pins the lock rather than describing it. The tagging path threw SnapshotCopyGrantNotFoundFault with HTTP 404. Both halves of that pairing cannot be right at once: botocore's Redshift model gives that shape httpStatusCode 400, and an error shape's status is a property of the shape, not of the calling action. But 404 is the correct status here, because CreateTags/DeleteTags/DescribeTags do not list that fault at all -- they document ResourceNotFoundFault, modelled at 404, for any missing resource. So the status stays and the code changes. That also explains why the three sibling cases in the same switch are already consistent: ClusterNotFound, ClusterSnapshotNotFound and ClusterParameterGroupNotFound are each modelled at 404 themselves. Describe and Delete still return SnapshotCopyGrantNotFoundFault at 400, which is what those two actions document. Docs gain a short section on the grant surface: the alias-ARN KmsKeyId default, the unvalidated tag limits, and why a missing grant reports two different faults depending on which action you reach it through. * style(test): name the new snapshot copy grant tests without the testX prefix AGENTS.md: "Name test methods either as a camelCase sentence or as method_scenario_expectation. Both are established. testX names are common in older tests and are not the pattern to copy." The 31 tests this PR adds to src/test all used testX because the three Redshift files they landed in are unusually full of it -- 7/7, 30/50 and 69/104 -- but that is the local exception, not the repo convention, and the rule is explicit about not copying it. Renames only; no test body changes. The two new tests in compatibility-tests/sdk-test-java keep testX: that module has the opposite idiom and AGENTS.md says to follow the module you are in, and all five methods in that file, three of them pre-existing, are named that way.