mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ecr): support image scanning configuration updates (#4928)
* fix(ecr): support image scanning configuration updates * fix(ecr): validate scanning configuration booleans * fix(ecr): accept null scan-on-push values * docs(ecr): list the image scanning configuration actions Add PutImageScanningConfiguration and BatchGetRepositoryScanningConfiguration to the Supported Actions table. The table is not generated, so the docs check does not catch a missing row.
This commit is contained in:
1 parent
0260a42549
commit
543f01618f
5 files changed
+125
-11
No files matched your search
@@ -115,6 +115,29 @@ class EcrTest {
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
@DisplayName("PutImageScanningConfiguration supports enabling and disabling scan on push")
|
||||
void imageScanningConfigurationCanBeEnabledAndDisabled() {
|
||||
PutImageScanningConfigurationResponse enabled = ecr.putImageScanningConfiguration(builder -> builder
|
||||
.repositoryName(REPO_NAME)
|
||||
.imageScanningConfiguration(ImageScanningConfiguration.builder().scanOnPush(true).build()));
|
||||
assertThat(enabled.imageScanningConfiguration().scanOnPush()).isTrue();
|
||||
|
||||
BatchGetRepositoryScanningConfigurationResponse enabledReadback =
|
||||
ecr.batchGetRepositoryScanningConfiguration(builder -> builder.repositoryNames(REPO_NAME));
|
||||
assertThat(enabledReadback.scanningConfigurations().get(0).scanOnPush()).isTrue();
|
||||
|
||||
PutImageScanningConfigurationResponse disabled = ecr.putImageScanningConfiguration(builder -> builder
|
||||
.repositoryName(REPO_NAME)
|
||||
.imageScanningConfiguration(ImageScanningConfiguration.builder().scanOnPush(false).build()));
|
||||
assertThat(disabled.imageScanningConfiguration().scanOnPush()).isFalse();
|
||||
|
||||
BatchGetRepositoryScanningConfigurationResponse disabledReadback =
|
||||
ecr.batchGetRepositoryScanningConfiguration(builder -> builder.repositoryNames(REPO_NAME));
|
||||
assertThat(disabledReadback.scanningConfigurations().get(0).scanOnPush()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
@DisplayName("PutLifecyclePolicy round-trips the policy text")
|
||||
void lifecyclePolicyRoundTrip() {
|
||||
String policy = "{\"rules\":[{\"rulePriority\":1,\"selection\":{\"tagStatus\":\"untagged\",\"countType\":\"imageCountMoreThan\",\"countNumber\":5},\"action\":{\"type\":\"expire\"}}]}";
|
||||
@@ -124,7 +147,7 @@ class EcrTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
@Order(9)
|
||||
@DisplayName("SetRepositoryPolicy round-trips the policy text")
|
||||
void repositoryPolicyRoundTrip() {
|
||||
String policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"AllowAll\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"ecr:*\"}]}";
|
||||
@@ -134,7 +157,7 @@ class EcrTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
@Order(10)
|
||||
@DisplayName("DeleteRepository force=true removes the repository")
|
||||
void deleteRepositoryForce() {
|
||||
ecr.deleteRepository(b -> b.repositoryName(REPO_NAME).force(true));
|
||||
@@ -144,7 +167,7 @@ class EcrTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
@Order(11)
|
||||
@DisplayName("DescribeRepositories on a missing name returns RepositoryNotFoundException")
|
||||
void describeMissing() {
|
||||
assertThatThrownBy(() -> ecr.describeRepositories(
|
||||
@@ -153,7 +176,7 @@ class EcrTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
@Order(12)
|
||||
@DisplayName("Pull through cache rules round-trip through the AWS SDK")
|
||||
void pullThroughCacheRuleLifecycle() {
|
||||
String firstPrefix = "sdk-docker-hub";
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
| `BatchGetImage` | Fetch image manifests, honoring `acceptedMediaTypes` |
|
||||
| `BatchDeleteImage` | Delete images by tag or digest |
|
||||
| `PutImageTagMutability` | Set tag mutability and reject replacement pushes to immutable tags |
|
||||
| `PutImageScanningConfiguration` | Set a repository's `scanOnPush` flag and return the updated configuration; a non-boolean value is rejected |
|
||||
| `BatchGetRepositoryScanningConfiguration` | Report each repository's `scanOnPush` setting with a derived `scanFrequency` (`SCAN_ON_PUSH` or `MANUAL`); a missing repository fails the whole batch instead of appearing in `failures` |
|
||||
| `TagResource` / `UntagResource` / `ListTagsForResource` | Resource tagging |
|
||||
| `PutLifecyclePolicy` / `GetLifecyclePolicy` / `DeleteLifecyclePolicy` | Lifecycle policy round-trip (stored, not enforced) |
|
||||
| `SetRepositoryPolicy` / `GetRepositoryPolicy` / `DeleteRepositoryPolicy` | Repository policy round-trip (stored, not enforced) |
|
||||
|
||||
@@ -50,6 +50,7 @@ public class EcrJsonHandler {
|
||||
case "ValidatePullThroughCacheRule" -> handleValidatePullThroughCacheRule(request, region);
|
||||
case "DeletePullThroughCacheRule" -> handleDeletePullThroughCacheRule(request, region);
|
||||
case "DescribeRepositories" -> handleDescribeRepositories(request, region);
|
||||
case "PutImageScanningConfiguration" -> handlePutImageScanningConfiguration(request, region);
|
||||
case "BatchGetRepositoryScanningConfiguration" ->
|
||||
handleBatchGetRepositoryScanningConfiguration(request, region);
|
||||
case "DeleteRepository" -> handleDeleteRepository(request, region);
|
||||
@@ -226,6 +227,35 @@ public class EcrJsonHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handlePutImageScanningConfiguration(JsonNode request, String region) {
|
||||
JsonNode scanningConfiguration = request.path("imageScanningConfiguration");
|
||||
if (!scanningConfiguration.isObject()) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"imageScanningConfiguration is required", 400);
|
||||
}
|
||||
|
||||
String repositoryName = request.path("repositoryName").asText(null);
|
||||
String registryId = request.path("registryId").asText(null);
|
||||
JsonNode scanOnPushNode = scanningConfiguration.path("scanOnPush");
|
||||
if (!scanOnPushNode.isMissingNode()
|
||||
&& !scanOnPushNode.isNull()
|
||||
&& !scanOnPushNode.isBoolean()) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"scanOnPush must be a boolean", 400);
|
||||
}
|
||||
boolean scanOnPush = scanOnPushNode.asBoolean(false);
|
||||
Repository updated = service.putImageScanningConfiguration(
|
||||
repositoryName, registryId, scanOnPush, region);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("registryId", updated.getRegistryId());
|
||||
response.put("repositoryName", updated.getRepositoryName());
|
||||
ObjectNode imageScanningConfiguration = objectMapper.createObjectNode();
|
||||
imageScanningConfiguration.put("scanOnPush", updated.isScanOnPush());
|
||||
response.set("imageScanningConfiguration", imageScanningConfiguration);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteRepository(JsonNode request, String region) {
|
||||
String repositoryName = request.path("repositoryName").asText(null);
|
||||
String registryId = request.path("registryId").asText(null);
|
||||
|
||||
@@ -617,6 +617,14 @@ public class EcrService implements ResourceProvider {
|
||||
// Tag mutability + resource tags + policies (metadata round-trip)
|
||||
// ============================================================
|
||||
|
||||
public Repository putImageScanningConfiguration(String repositoryName, String registryId,
|
||||
boolean scanOnPush, String region) {
|
||||
Repository repo = requireRepo(repositoryName, registryId, region);
|
||||
repo.setScanOnPush(scanOnPush);
|
||||
repoStore.put(key(region, repo.getRegistryId(), repositoryName), repo);
|
||||
return repo;
|
||||
}
|
||||
|
||||
public Repository putImageTagMutability(String repositoryName, String registryId,
|
||||
String mutability, String region) {
|
||||
if (mutability == null
|
||||
|
||||
@@ -163,6 +163,57 @@ class EcrIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void putImageScanningConfiguration() {
|
||||
given()
|
||||
.header("X-Amz-Target", PREFIX + "PutImageScanningConfiguration")
|
||||
.contentType(CT)
|
||||
.body("""
|
||||
{
|
||||
"repositoryName": "%s",
|
||||
"imageScanningConfiguration": { "scanOnPush": true }
|
||||
}
|
||||
""".formatted(REPO))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("registryId", not(emptyString()))
|
||||
.body("repositoryName", equalTo(REPO))
|
||||
.body("imageScanningConfiguration.scanOnPush", equalTo(true));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", PREFIX + "PutImageScanningConfiguration")
|
||||
.contentType(CT)
|
||||
.body("""
|
||||
{
|
||||
"repositoryName": "%s",
|
||||
"imageScanningConfiguration": { "scanOnPush": "yes" }
|
||||
}
|
||||
""".formatted(REPO))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("InvalidParameterException"));
|
||||
|
||||
given()
|
||||
.header("X-Amz-Target", PREFIX + "PutImageScanningConfiguration")
|
||||
.contentType(CT)
|
||||
.body("""
|
||||
{
|
||||
"repositoryName": "%s",
|
||||
"imageScanningConfiguration": { "scanOnPush": null }
|
||||
}
|
||||
""".formatted(REPO))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("imageScanningConfiguration.scanOnPush", equalTo(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void batchGetRepositoryScanningConfiguration() {
|
||||
given()
|
||||
.header("X-Amz-Target", PREFIX + "BatchGetRepositoryScanningConfiguration")
|
||||
@@ -183,7 +234,7 @@ class EcrIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
@Order(10)
|
||||
void deleteRepositoryForce() {
|
||||
given()
|
||||
.header("X-Amz-Target", PREFIX + "DeleteRepository")
|
||||
@@ -216,7 +267,7 @@ class EcrIntegrationTest {
|
||||
* call rather than the emulator's configured default.
|
||||
*/
|
||||
@Test
|
||||
@Order(10)
|
||||
@Order(11)
|
||||
void getAuthorizationToken_nonDefaultRegionRequest_returnsProxyEndpointForThatRegion() {
|
||||
String repository = "floci-it/region-scoped";
|
||||
String repositoryUri = given()
|
||||
@@ -264,7 +315,7 @@ class EcrIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
@Order(12)
|
||||
void createPullThroughCacheRule() {
|
||||
given()
|
||||
.header("X-Amz-Target", PREFIX + "CreatePullThroughCacheRule")
|
||||
@@ -306,7 +357,7 @@ class EcrIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(12)
|
||||
@Order(13)
|
||||
void updateAndValidatePullThroughCacheRule() {
|
||||
String updatedCredential =
|
||||
"arn:aws:secretsmanager:us-east-1:000000000000:secret:ecr-pullthroughcache/updated";
|
||||
@@ -353,7 +404,7 @@ class EcrIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(13)
|
||||
@Order(14)
|
||||
void describePullThroughCacheRulesFiltersAndPaginates() {
|
||||
String nextToken = given()
|
||||
.header("X-Amz-Target", PREFIX + "DescribePullThroughCacheRules")
|
||||
@@ -396,7 +447,7 @@ class EcrIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(14)
|
||||
@Order(15)
|
||||
void createPullThroughCacheRuleDuplicateFails() {
|
||||
given()
|
||||
.header("X-Amz-Target", PREFIX + "CreatePullThroughCacheRule")
|
||||
@@ -425,7 +476,7 @@ class EcrIntegrationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(15)
|
||||
@Order(16)
|
||||
void deletePullThroughCacheRules() {
|
||||
for (String prefix : new String[] {CACHE_PREFIX, SECOND_CACHE_PREFIX}) {
|
||||
given()
|
||||
|
||||
Reference in new issue
Block a user