-
Notifications
You must be signed in to change notification settings - Fork 244
Added scheme property to HttpApiKeyAuth trait #893
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
926f656
Added scheme property to HttpApiKeyAuth trait.
DavidOgunsAWS e81db2a
Add scheme property to HttpApiKeyAuth trait
DavidOgunsAWS 8658c70
Add documentation with snippet.
DavidOgunsAWS 2e1ae76
Merge branch 'apikeyscheme' of github.com:awslabs/smithy into apikeys…
DavidOgunsAWS 622eca1
Add better documentation comment for validation
DavidOgunsAWS bbcce08
Adding back license year to copyright header.
DavidOgunsAWS ef13b4a
Update smithy-model/src/main/resources/software/amazon/smithy/model/l…
DavidOgunsAWS e112ef0
Add OpenAPI converstion for scheme enabled HttpApiKeyAuthTrait.
DavidOgunsAWS fd89542
Add test resource for ApiKey scheme conversion.
DavidOgunsAWS 8971a0e
Merge branch 'apikeyscheme' of github.com:awslabs/smithy into apikeys…
DavidOgunsAWS 499254d
Improve error location and message clarity, and addressed formatting …
DavidOgunsAWS febbc7a
Move validation error test resources and re-word error message.
DavidOgunsAWS 850bf43
Add lead in sentence for example.
DavidOgunsAWS fdcc568
Re-order field setting in constructor
DavidOgunsAWS db27e58
Adjust and synchronize documentation and prelude for scheme property.
DavidOgunsAWS b337354
Adjust assertThat(..., false) to assertFalse()
DavidOgunsAWS 0764253
Add EOL
DavidOgunsAWS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...java/software/amazon/smithy/model/validation/validators/HttpApiKeyAuthTraitValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| /* | ||
| * Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.smithy.model.validation.validators; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import software.amazon.smithy.model.Model; | ||
| import software.amazon.smithy.model.shapes.ServiceShape; | ||
| import software.amazon.smithy.model.traits.HttpApiKeyAuthTrait; | ||
| import software.amazon.smithy.model.validation.AbstractValidator; | ||
| import software.amazon.smithy.model.validation.ValidationEvent; | ||
|
|
||
| /** | ||
| * Validates that if an HttpApiKeyAuth trait's scheme field is present then | ||
| * the 'in' field must specify "header". Scheme should only be used with the | ||
| * "Authorization" http header. | ||
| */ | ||
| public final class HttpApiKeyAuthTraitValidator extends AbstractValidator { | ||
| @Override | ||
| public List<ValidationEvent> validate(Model model) { | ||
| Set<ServiceShape> serviceShapesWithTrait = model.getServiceShapesWithTrait(HttpApiKeyAuthTrait.class); | ||
| List<ValidationEvent> events = new ArrayList<>(); | ||
|
|
||
| for (ServiceShape serviceShape : serviceShapesWithTrait) { | ||
| HttpApiKeyAuthTrait trait = serviceShape.expectTrait(HttpApiKeyAuthTrait.class); | ||
| trait.getScheme().ifPresent(scheme -> { | ||
| if (trait.getIn() != HttpApiKeyAuthTrait.Location.HEADER) { | ||
| events.add(error(serviceShape, trait, | ||
| String.format("The httpApiKeyAuth trait must have an `in` value of `header` when a `scheme`" | ||
| + " is provided, found: %s", trait.getIn()))); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| return events; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
...amazon/smithy/model/errorfiles/validators/http-api-key-scheme-trait-validator-test.errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| [ERROR] ns.foo#MyService: The httpApiKeyAuth trait must have an `in` value of `header` when a `scheme` is provided, found: query | HttpApiKeyAuthTrait | ||
DavidOgunsAWS marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
39 changes: 39 additions & 0 deletions
39
...e/amazon/smithy/model/errorfiles/validators/http-api-key-scheme-trait-validator-test.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| { | ||
| "smithy": "1.0", | ||
| "shapes": { | ||
| "ns.foo#MyService": { | ||
| "type": "service", | ||
| "version": "2017-01-17", | ||
| "operations": [ | ||
| { | ||
| "target": "ns.foo#A" | ||
| } | ||
| ], | ||
| "traits": { | ||
| "smithy.api#httpApiKeyAuth": { | ||
| "scheme": "Baz", | ||
| "name": "ApiKeyName", | ||
| "in": "query" | ||
| } | ||
| } | ||
| }, | ||
| "ns.foo#A": { | ||
| "type": "operation", | ||
| "input": { | ||
| "target": "ns.foo#AInput" | ||
| }, | ||
| "output": { | ||
| "target": "ns.foo#AOutput" | ||
| }, | ||
| "traits": { | ||
| "smithy.api#readonly": { } | ||
| } | ||
| }, | ||
| "ns.foo#AInput": { | ||
| "type": "structure" | ||
| }, | ||
| "ns.foo#AOutput": { | ||
| "type": "structure" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...rces/software/amazon/smithy/openapi/fromsmithy/security/http-api-key-bearer-security.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "smithy": "1.0", | ||
| "shapes": { | ||
| "smithy.example#Service": { | ||
| "type": "service", | ||
| "version": "2006-03-01", | ||
| "operations": [ | ||
| { | ||
| "target": "smithy.example#Operation" | ||
| } | ||
| ], | ||
| "traits": { | ||
| "aws.protocols#restJson1": {}, | ||
| "smithy.api#httpApiKeyAuth": { | ||
| "name": "Authorization", | ||
| "in": "header", | ||
| "scheme": "ApiKey" | ||
| } | ||
| } | ||
| }, | ||
| "smithy.example#Operation": { | ||
| "type": "operation", | ||
| "traits": { | ||
| "smithy.api#http": { | ||
| "uri": "/", | ||
| "method": "GET" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
...tware/amazon/smithy/openapi/fromsmithy/security/http-api-key-bearer-security.openapi.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "openapi": "3.0.2", | ||
| "info": { | ||
| "title": "Service", | ||
| "version": "2006-03-01" | ||
| }, | ||
| "paths": { | ||
| "/": { | ||
| "get": { | ||
| "operationId": "Operation", | ||
| "responses": { | ||
| "200": { | ||
| "description": "Operation response" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "components": { | ||
| "securitySchemes": { | ||
| "smithy.api.httpApiKeyAuth": { | ||
| "type": "http", | ||
| "description": "ApiKey authentication semantics via 'Authorization' header", | ||
| "name": "Authorization", | ||
| "in": "header", | ||
| "scheme": "ApiKey" | ||
| } | ||
| } | ||
| }, | ||
| "security": [ | ||
| { | ||
| "smithy.api.httpApiKeyAuth": [ ] | ||
DavidOgunsAWS marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| ] | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.