-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Testing for Tables Autorest Code #12512
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 all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
576d2be
apply old
eboyd23 dea2498
apply old
eboyd23 081200a
testing works on this commit
eboyd23 f6ea265
stashing
eboyd23 1e1efd8
additional testing
eboyd23 2397b88
stashing
eboyd23 c2e8eb7
stashing
eboyd23 b2ebec7
adding tests
eboyd23 d54ae25
fixing format and POM
eboyd23 ac21a3d
arrange-act-assert formatting
eboyd23 5086d4a
stashing
eboyd23 68f0cea
adding tests
eboyd23 f13cca6
reformat
eboyd23 d4c187a
remove system prints
eboyd23 335d646
adding playback jsons
eboyd23 7133df8
recent changes
eboyd23 2281563
fix pom
eboyd23 ba399fe
playback mode
eboyd23 ca8b84c
fix incorrect changes in readme
eboyd23 e849c5e
fix pom
eboyd23 0216fde
fixing pom
eboyd23 8b9e906
fixing version
eboyd23 3558d0f
fix impl
eboyd23 5f24375
fixing checkstyles
eboyd23 229116a
fixing checkstyles p2
eboyd23 06e255a
connie edits
eboyd23 8cb259d
connie edits 2
eboyd23 9b19368
forgot in last commit
eboyd23 cef9820
add changelog
eboyd23 1315b59
connie comments
eboyd23 74c33b5
fixing pipeline issues
eboyd23 1351fbe
assertion for setup
eboyd23 b7f8400
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
eboyd23 767bfdf
fix impl
eboyd23 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # Release History | ||
|
|
||
| ## 1.0.0-beta.1 (Unreleased) |
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
113 changes: 113 additions & 0 deletions
113
...bles/azure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredential.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,113 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.data.tables; | ||
|
|
||
| import com.azure.storage.common.implementation.StorageImplUtils; | ||
|
|
||
| import java.net.URL; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| /** | ||
| * A Class which helps generate the shared key credentials for a given storage account to create a Http requests to | ||
| * access Azure Tables | ||
| */ | ||
| public class TablesSharedKeyCredential { | ||
| private static final String AUTHORIZATION_HEADER_FORMAT = "SharedKeyLite %s:%s"; | ||
| private final String accountName; | ||
| private final String accountKey; | ||
|
|
||
| /** | ||
| * Constructor for TableSharedKeyCredential Class | ||
| * | ||
| * @param accountName name of the storage account | ||
| * @param accountKey key to the storage account | ||
| */ | ||
| public TablesSharedKeyCredential(String accountName, String accountKey) { | ||
| this.accountName = Objects.requireNonNull(accountName, "'accountName' cannot be null."); | ||
| this.accountKey = Objects.requireNonNull(accountKey, "'accountKey' cannot be null."); | ||
| } | ||
|
|
||
| /** | ||
| * Generates the Auth Headers | ||
| * | ||
| * @param requestUrl the URL which the request is going to | ||
| * @param headers the headers of the request | ||
| * @return the auth header | ||
| */ | ||
| public String generateAuthorizationHeader(URL requestUrl, Map<String, String> headers) { | ||
| String signature = StorageImplUtils.computeHMac256(accountKey, buildStringToSign(requestUrl, | ||
| headers)); | ||
| return String.format(AUTHORIZATION_HEADER_FORMAT, accountName, signature); | ||
| } | ||
|
|
||
| /** | ||
| * creates the String to Sign | ||
| * | ||
| * @param requestUrl the Url which the request is going to | ||
| * @param headers the headers of the request | ||
| * @return a string to sign for the request | ||
| */ | ||
| private String buildStringToSign(URL requestUrl, Map<String, String> headers) { | ||
| String dateHeader = headers.containsKey("x-ms-date") | ||
| ? "" | ||
| : this.getStandardHeaderValue(headers, "Date"); | ||
| return String.join("\n", | ||
| dateHeader, //date | ||
| getCanonicalizedResource(requestUrl)); //Canonicalized resource | ||
| } | ||
|
|
||
| /** | ||
| * gets necessary headers if the request does not already contain them | ||
| * | ||
| * @param headers a map of the headers which the request has | ||
| * @param headerName the name of the header to get the standard header for | ||
| * @return the standard header for the given name | ||
| */ | ||
| private String getStandardHeaderValue(Map<String, String> headers, String headerName) { | ||
| String headerValue = headers.get(headerName); | ||
| return headerValue == null ? "" : headerValue; | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * returns the canonicalized resource needed for a request | ||
| * | ||
| * @param requestUrl the url of the request | ||
| * @return the string that is the canonicalized resource | ||
| */ | ||
| private String getCanonicalizedResource(URL requestUrl) { | ||
| StringBuilder canonicalizedResource = new StringBuilder("/").append(accountName); | ||
| if (requestUrl.getPath().length() > 0) { | ||
| canonicalizedResource.append(requestUrl.getPath()); | ||
| } else { | ||
| canonicalizedResource.append('/'); | ||
| } | ||
|
|
||
| if (requestUrl.getQuery() != null) { | ||
| Map<String, String[]> queryParams = StorageImplUtils.parseQueryStringSplitValues(requestUrl.getQuery()); | ||
| ArrayList<String> queryParamNames = new ArrayList<>(queryParams.keySet()); | ||
|
|
||
| Collections.sort(queryParamNames); | ||
|
|
||
| for (String queryParamName : queryParamNames) { | ||
| String[] queryParamValues = queryParams.get(queryParamName); | ||
|
|
||
| Arrays.sort(queryParamValues); | ||
|
|
||
| String queryParamValuesStr = String.join(",", queryParamValues); | ||
|
|
||
| if (queryParamName.equalsIgnoreCase("comp")) { | ||
| canonicalizedResource.append("?").append(queryParamName.toLowerCase(Locale.ROOT)).append("=") | ||
| .append(queryParamValuesStr); | ||
| } | ||
| } | ||
| } | ||
| return canonicalizedResource.toString(); | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...zure-data-tables/src/main/java/com/azure/data/tables/TablesSharedKeyCredentialPolicy.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,41 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package com.azure.data.tables; | ||
|
|
||
| import com.azure.core.http.HttpPipelineCallContext; | ||
| import com.azure.core.http.HttpPipelineNextPolicy; | ||
| import com.azure.core.http.HttpResponse; | ||
| import com.azure.core.http.policy.HttpPipelinePolicy; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| /** | ||
| * This class helps authenticate an Http request for the Tables service | ||
| */ | ||
| public final class TablesSharedKeyCredentialPolicy implements HttpPipelinePolicy { | ||
|
|
||
| private final TablesSharedKeyCredential credential; | ||
|
|
||
| /** | ||
| * constructor for the TablesSharedKeyCredentialPolicy class | ||
| * | ||
| * @param credential the credentials of the account | ||
| */ | ||
| public TablesSharedKeyCredentialPolicy(TablesSharedKeyCredential credential) { | ||
| this.credential = credential; | ||
| } | ||
|
|
||
| /** | ||
| * creates an Http response | ||
| * | ||
| * @param context the context of the http pipeline | ||
| * @param next the next Http pipeline policy | ||
| * @return an Http response | ||
| */ | ||
| public Mono<HttpResponse> process(HttpPipelineCallContext context, HttpPipelineNextPolicy next) { | ||
| String authorizationValue = credential.generateAuthorizationHeader(context.getHttpRequest().getUrl(), | ||
| context.getHttpRequest().getHeaders().toMap()); | ||
| context.getHttpRequest().setHeader("Authorization", authorizationValue); | ||
| return next.process(); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/package-info.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,5 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| /** Package containing the inner classes for Azure Tables SDK. */ | ||
| package com.azure.data.tables; |
Oops, something went wrong.
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.