Skip to content

Commit

Permalink
Lock down APIs with final, unstable, and internal
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed May 4, 2020
1 parent d6c002a commit eeea998
Show file tree
Hide file tree
Showing 90 changed files with 164 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/**
* API Gateway does not allow characters like "_".
*/
public final class AddDefaultConfigSettings implements ApiGatewayMapper {
final class AddDefaultConfigSettings implements ApiGatewayMapper {
@Override
public List<ApiGatewayConfig.ApiType> getApiTypes() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* operation has the authorizer trait, then the resource an operation
* is bound to, then the service.
*/
public class AuthorizerIndex implements KnowledgeIndex {
public final class AuthorizerIndex implements KnowledgeIndex {

private static final Selector SELECTOR = Selector.parse("operation");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
import software.amazon.smithy.model.validation.ValidationEvent;
import software.amazon.smithy.model.validation.ValidationUtils;
import software.amazon.smithy.utils.OptionalUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
* Each authorizer resolved within a service must use a scheme that
* matches one of the schemes of the protocols of the service.
*/
public class AuthorizersTraitValidator extends AbstractValidator {
@SmithyInternalApi
public final class AuthorizersTraitValidator extends AbstractValidator {
@Override
public List<ValidationEvent> validate(Model model) {
return model.shapes(ServiceShape.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Computes the API Gateway integration for each operation,
* resource, and service shape in a model.
*/
public class IntegrationTraitIndex implements KnowledgeIndex {
public final class IntegrationTraitIndex implements KnowledgeIndex {
private Map<ShapeId, Map<ShapeId, Trait>> traits = new HashMap<>();

public IntegrationTraitIndex(Model model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import software.amazon.smithy.model.validation.AbstractValidator;
import software.amazon.smithy.model.validation.ValidationEvent;
import software.amazon.smithy.model.validation.ValidationUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
* Ensures that condition keys referenced by operations bound within the
Expand All @@ -37,7 +38,8 @@
* <p>Condition keys that refer to global "aws:*" keys are allowed to not
* be defined on the service.
*/
public class ConditionKeysValidator extends AbstractValidator {
@SmithyInternalApi
public final class ConditionKeysValidator extends AbstractValidator {
@Override
public List<ValidationEvent> validate(Model model) {
ConditionKeysIndex conditionIndex = model.getKnowledge(ConditionKeysIndex.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@
import software.amazon.smithy.model.validation.ValidationEvent;
import software.amazon.smithy.utils.OptionalUtils;
import software.amazon.smithy.utils.Pair;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
* Ensures that all arn traits for a service are valid and that their templates
* only reference valid resource identifiers.
*/
@SmithyInternalApi
public final class ArnTemplateValidator extends AbstractValidator {
private static final Pattern EXPRESSION_PATTERN = Pattern.compile("^[!|+]?[a-zA-Z_][a-zA-Z0-9_]*$");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import software.amazon.smithy.model.validation.ValidationUtils;
import software.amazon.smithy.utils.OptionalUtils;
import software.amazon.smithy.utils.SetUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
* Validates that SDK service IDs are correct and do not match any
Expand All @@ -42,6 +43,7 @@
* <li>Must not case-insensitively end with "Service", "Client", or "API".</li>
* </ul>
*/
@SmithyInternalApi
public final class SdkServiceIdValidator extends AbstractValidator {
private static final Set<String> COMPANY_NAMES = SetUtils.of("AWS", "Aws", "Amazon");
private static final Set<String> DISALLOWED_ENDINGS = SetUtils.of("service", "client", "api");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import software.amazon.smithy.model.traits.Trait;
import software.amazon.smithy.model.transform.ModelTransformer;
import software.amazon.smithy.model.transform.ModelTransformerPlugin;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
* Removes the endpoint discovery trait from a service if the referenced operation or error are removed.
*/
public class CleanClientDiscoveryTraitTransformer implements ModelTransformerPlugin {
@SmithyInternalApi
public final class CleanClientDiscoveryTraitTransformer implements ModelTransformerPlugin {
@Override
public Model onRemove(ModelTransformer transformer, Collection<Shape> shapes, Model model) {
Set<ShapeId> removedOperations = shapes.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
import software.amazon.smithy.model.validation.ValidationEvent;
import software.amazon.smithy.utils.Pair;
import software.amazon.smithy.utils.SetUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

public class ClientEndpointDiscoveryValidator extends AbstractValidator {
@SmithyInternalApi
public final class ClientEndpointDiscoveryValidator extends AbstractValidator {
private static final Set<String> VALID_INPUT_MEMBERS = SetUtils.of("Operation", "Identifiers");

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Indicates the serialized name of a structure member when that structure is
* serialized for the input of an EC2 operation.
*/
public class Ec2QueryNameTrait extends StringTrait {
public final class Ec2QueryNameTrait extends StringTrait {
public static final ShapeId ID = ShapeId.from("aws.protocols#ec2QueryName");

public Ec2QueryNameTrait(String value, SourceLocation sourceLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import software.amazon.smithy.model.traits.Trait;
import software.amazon.smithy.model.validation.AbstractValidator;
import software.amazon.smithy.model.validation.ValidationEvent;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
* Ensures that every entry in {@code eventStreamHttp} also appears in
* the {@code http} property of a protocol trait.
*/
@SmithyInternalApi
public final class ProtocolHttpValidator extends AbstractValidator {
@Override
public List<ValidationEvent> validate(Model model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* transform needs this functionality. We could *maybe* address
* this later if we really care that much.
*/
public class Apply extends BackwardCompatHelper<Apply.Config> {
public final class Apply extends BackwardCompatHelper<Apply.Config> {

/**
* {@code apply} configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import software.amazon.smithy.utils.SmithyUnstableApi;

/**
* Container for parsed command line arguments meant to be queried by Commands.
Expand All @@ -28,6 +29,7 @@
* with a short name of "-h" and a long name of "--help" would be made
* available in an {@code Arguments} instance as "--help" and not "-h".
*/
@SmithyUnstableApi
public final class Arguments {
private final Map<String, List<String>> arguments;
private final List<String> positionalArguments;
Expand Down
2 changes: 2 additions & 0 deletions smithy-cli/src/main/java/software/amazon/smithy/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import software.amazon.smithy.utils.SmithyUnstableApi;

/**
* This class provides a very basic CLI abstraction.
Expand All @@ -54,6 +55,7 @@
* CLI features are supported in case we want to migrate to a library or
* event a different language.
*/
@SmithyUnstableApi
public final class Cli {
public static final String HELP = "--help";
public static final String NO_COLOR = "--no-color";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

package software.amazon.smithy.cli;

import software.amazon.smithy.utils.SmithyUnstableApi;

/**
* Provides an abstraction for printing with ANSI colors if it is supported.
*/
@SmithyUnstableApi
public enum Colors {
BLACK(30),
RED(31),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@

package software.amazon.smithy.cli;

import software.amazon.smithy.utils.SmithyUnstableApi;

/**
* Represents a CLI command.
*/
@SmithyUnstableApi
public interface Command {
/**
* Gets the name of the command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import java.util.Optional;
import java.util.stream.Collectors;
import software.amazon.smithy.utils.SmithyBuilder;
import software.amazon.smithy.utils.SmithyUnstableApi;

/**
* Defines the CLI argument parser of a {@link Command}.
*/
@SmithyUnstableApi
public final class Parser {
private String positionalName;
private String positionalHelp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
import software.amazon.smithy.model.loader.ModelAssembler;
import software.amazon.smithy.model.validation.Severity;
import software.amazon.smithy.model.validation.ValidatedResult;
import software.amazon.smithy.utils.SmithyInternalApi;

@SmithyInternalApi
public final class BuildCommand implements Command {
private static final Logger LOGGER = Logger.getLogger(BuildCommand.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import software.amazon.smithy.model.validation.Severity;
import software.amazon.smithy.model.validation.ValidatedResult;
import software.amazon.smithy.model.validation.ValidationEvent;
import software.amazon.smithy.utils.SmithyInternalApi;

@SmithyInternalApi
public final class DiffCommand implements Command {
private static final Logger LOGGER = Logger.getLogger(DiffCommand.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.loader.ModelAssembler;
import software.amazon.smithy.model.validation.ValidatedResult;
import software.amazon.smithy.utils.SmithyInternalApi;

@SmithyInternalApi
public final class ValidateCommand implements Command {
@Override
public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* Builds a {@link ReservedWords} implementation from explicit
* mappings and from line-delimited files that contain reserved words.
*/
public class ReservedWordsBuilder {
public final class ReservedWordsBuilder {

private final Map<String, String> mappings = new HashMap<>();
private final List<ReservedWords> delegates = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* added, and an "AddedResourceBinding" eventId is used when a
* resource is added.
*/
public class AddedEntityBinding extends AbstractDiffEvaluator {
public final class AddedEntityBinding extends AbstractDiffEvaluator {
private static final String ADDED_RESOURCE = "AddedResourceBinding";
private static final String ADDED_OPERATION = "AddedOperationBinding";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Creates a NOTE event when metadata is added.
*/
public class AddedMetadata extends AbstractDiffEvaluator {
public final class AddedMetadata extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.addedMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* Emits a warning when an error is added to an operation.
*/
public class AddedOperationError extends AbstractDiffEvaluator {
public final class AddedOperationError extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes(OperationShape.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*
* <p>TODO: Also check for the addition of streaming and event streams.
*/
public class AddedOperationInputOutput implements DiffEvaluator {
public final class AddedOperationInputOutput implements DiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes(OperationShape.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Creates a NOTE event when a shape is added.
*/
public class AddedShape extends AbstractDiffEvaluator {
public final class AddedShape extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.addedShapes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Creates a NOTE event when a trait definition is added.
*/
public class AddedTraitDefinition extends AbstractDiffEvaluator {
public final class AddedTraitDefinition extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.addedShapes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* Emits a NOTE when a new enum value is added, emits an ERROR when an
* enum value is removed, and emits an ERROR when an enum name changes.
*/
public class ChangedEnumTrait extends AbstractDiffEvaluator {
public final class ChangedEnumTrait extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Detects when the Length trait is made more restrictive by either
* raising the min or lowering the max.
*/
public class ChangedLengthTrait extends AbstractLengthAndRangeValidator<LengthTrait> {
public final class ChangedLengthTrait extends AbstractLengthAndRangeValidator<LengthTrait> {
@Override
protected Class<LengthTrait> getTraitType() {
return LengthTrait.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
* a simple shape of the same type with the same traits, then the emitted
* event is a WARNING. All other changes are ERROR events.
*/
public class ChangedMemberTarget extends AbstractDiffEvaluator {
public final class ChangedMemberTarget extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes(MemberShape.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* Creates a WARNING event when metadata is changed.
*/
public class ChangedMetadata extends AbstractDiffEvaluator {
public final class ChangedMetadata extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedMetadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Emits an ERROR when the input shape of an operation is changed to
* another shape.
*/
public class ChangedOperationInput extends AbstractDiffEvaluator {
public final class ChangedOperationInput extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes(OperationShape.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* Emits an ERROR when the output shape of an operation is changed to
* another shape.
*/
public class ChangedOperationOutput extends AbstractDiffEvaluator {
public final class ChangedOperationOutput extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes(OperationShape.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Detects when the Range trait is made more restrictive by either
* raising the min or lowering the max.
*/
public class ChangedRangeTrait extends AbstractLengthAndRangeValidator<RangeTrait> {
public final class ChangedRangeTrait extends AbstractLengthAndRangeValidator<RangeTrait> {
@Override
protected Class<RangeTrait> getTraitType() {
return RangeTrait.class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Creates an ERROR event when the identifiers of a resource changes.
*/
public class ChangedResourceIdentifiers extends AbstractDiffEvaluator {
public final class ChangedResourceIdentifiers extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes(ResourceShape.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* Creates an ERROR event when the type of a shape changes.
*/
public class ChangedShapeType extends AbstractDiffEvaluator {
public final class ChangedShapeType extends AbstractDiffEvaluator {
@Override
public List<ValidationEvent> evaluate(Differences differences) {
return differences.changedShapes()
Expand Down
Loading

0 comments on commit eeea998

Please sign in to comment.