Skip to content

Commit

Permalink
breakfix: convert public access block config fields to nilable like s3 (
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws authored Nov 21, 2023
1 parent fa3ee1a commit 57f3065
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .changelog/08c84fb2c6644d8b983c9986c770cfda.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "08c84fb2-c664-4d8b-983c-9986c770cfda",
"type": "feature",
"description": "**BREAK FIX**: Convert S3Control PublicAccessBlock field types to nilable. See #2384, #2162.",
"modules": [
"service/s3control"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package software.amazon.smithy.aws.go.codegen.customization;

import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.AbstractShapeBuilder;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.traits.DefaultTrait;
import software.amazon.smithy.model.transform.ModelTransformer;
import software.amazon.smithy.utils.MapUtils;
import software.amazon.smithy.utils.SetUtils;
import software.amazon.smithy.utils.ToSmithyBuilder;

import java.util.Map;
import java.util.Set;

public class RemoveDefaults implements GoIntegration {
private static final Map<ShapeId, Set<ShapeId>> toRemove = MapUtils.of(
ShapeId.from("com.amazonaws.s3control#AWSS3ControlServiceV20180820"), SetUtils.of(
ShapeId.from("com.amazonaws.s3control#PublicAccessBlockConfiguration$BlockPublicAcls"),
ShapeId.from("com.amazonaws.s3control#PublicAccessBlockConfiguration$IgnorePublicAcls"),
ShapeId.from("com.amazonaws.s3control#PublicAccessBlockConfiguration$BlockPublicPolicy"),
ShapeId.from("com.amazonaws.s3control#PublicAccessBlockConfiguration$RestrictPublicBuckets")
)
);

private boolean mustPreprocess(ShapeId service) {
return toRemove.containsKey(service);
}

@Override
public Model preprocessModel(Model model, GoSettings settings) {
var serviceId = settings.getService();
return mustPreprocess(serviceId)
? removeDefaults(model, toRemove.get(serviceId))
: model;
}

private Model removeDefaults(Model model, Set<ShapeId> fromShapes) {
return ModelTransformer.create().mapShapes(model, it ->
fromShapes.contains(it.getId())
? withoutDefault(it)
: it
);
}

private Shape withoutDefault(Shape shape) {
return Shape.shapeToBuilder(shape)
.removeTrait(DefaultTrait.ID)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ software.amazon.smithy.aws.go.codegen.customization.auth.EndpointAuthResolution
software.amazon.smithy.aws.go.codegen.customization.auth.AwsSigV4aAuthScheme
software.amazon.smithy.aws.go.codegen.customization.auth.LegacyAuthContextOverride
software.amazon.smithy.aws.go.codegen.customization.auth.IgnoreAnonymousCredentials
software.amazon.smithy.aws.go.codegen.customization.RemoveDefaults
8 changes: 4 additions & 4 deletions service/s3control/deserializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions service/s3control/serializers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions service/s3control/types/types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 57f3065

Please sign in to comment.