Skip to content

Commit

Permalink
Add S3Control builtin + EndpointRuleset toBuilder (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods authored Sep 2, 2022
1 parent 279aac8 commit 6784d75
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static software.amazon.smithy.rulesengine.language.error.RuleError.ctx;
import static software.amazon.smithy.rulesengine.language.util.StringUtils.indent;

import java.util.Collection;
import java.util.List;
import java.util.Objects;
import software.amazon.smithy.model.FromSourceLocation;
Expand Down Expand Up @@ -119,6 +120,13 @@ public Node toNode() {
.build();
}

public Builder toBuilder() {
return builder()
.sourceLocation(sourceLocation)
.parameters(parameters)
.addRules(getRules());
}

private Node rulesNode() {
ArrayNode.Builder node = ArrayNode.builder();
rules.forEach(node::withValue);
Expand Down Expand Up @@ -190,6 +198,29 @@ public Builder addRule(Rule rule) {
return this;
}

/**
* Inserts a rule into the ruleset.
*
* @param index the position to add the rule at.
* @param rule The {@link Rule} to add
* @return the {@link Builder}
*/
public Builder addRule(int index, Rule rule) {
this.rules.get().add(index, rule);
return this;
}

/**
* Add rules to this ruleset. The rules be evaluated if all previous rules do not match.
*
* @param rules The Collection of {@link Rule} to add
* @return the {@link Builder}
*/
public Builder rules(Collection<Rule> rules) {
this.rules.get().addAll(rules);
return this;
}

/**
* Set the parameters for this {@link EndpointRuleset}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public final class Builtins {
.build();

/**
* This MUST only be used by the S3 and S3Control rules.
* This MUST only be used by the S3 rules.
*/
public static final Parameter S3_USE_ARN_REGION =
Parameter.builder()
Expand All @@ -116,6 +116,20 @@ public final class Builtins {
+ " of the client's configured region.")
.build();

/**
* This MUST only be used by the S3Control rules.
*/
public static final Parameter S3_CONTROL_USE_ARN_REGION =
Parameter.builder()
.type(ParameterType.BOOLEAN)
.name("UseArnRegion")
.builtIn("AWS::S3Control::UseArnRegion")
.documentation(
"When an Access Point ARN is provided and this flag is enabled, the SDK MUST"
+ " use the ARN's region when constructing the endpoint instead"
+ " of the client's configured region.")
.build();

/**
* This MUST only be used by the S3 rules.
*/
Expand Down Expand Up @@ -159,7 +173,7 @@ public final class Builtins {

public static final List<Parameter> ALL_BUILTINS = ListUtils.of(
SDK_ENDPOINT, REGION, FIPS, DUALSTACK, S3_ACCELERATE, S3_FORCE_PATH_STYLE, S3_USE_ARN_REGION,
S3_USE_GLOBAL_ENDPOINT, STS_USE_GLOBAL_ENDPOINT, S3_DISABLE_MRAP);
S3_USE_GLOBAL_ENDPOINT, S3_CONTROL_USE_ARN_REGION, STS_USE_GLOBAL_ENDPOINT, S3_DISABLE_MRAP);

private Builtins() {
}
Expand Down

0 comments on commit 6784d75

Please sign in to comment.