Skip to content
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

breakfix: convert public access block config fields to nilable like s3 #2385

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading