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
Adding UDK/UDC to service client #19141
Merged
siminsavani-msft
merged 24 commits into
Azure:main
from
siminsavani-msft:siminsavani/userdelegationsas
Sep 23, 2022
Merged
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8d9f52f
Adding UDK/UDC to service client
siminsavani-msft 548a3e0
Adding GetUDKSASURL
siminsavani-msft bb9abb7
Merge siminsavani/userdelegationsas with main branch
siminsavani-msft 361c25a
Removing changes as requested
siminsavani-msft 3e8904c
Additional changes to remove
siminsavani-msft 1a62866
Addressing comments, cleaning up code, adding wip test
siminsavani-msft dfca65d
Modifications to test
siminsavani-msft 4f6ad3f
Clean up
siminsavani-msft aef324f
Addressing comments in PR
siminsavani-msft 632381d
Adding helper methods to only allow SDK calls
siminsavani-msft a35f7a6
Adding to example_test and making udc immutable
siminsavani-msft a9a1508
Adding helper method for GetAccountName
siminsavani-msft 95f0746
Additional clean up
siminsavani-msft 4da22d1
Merge branch 'main' into siminsavani/userdelegationsas
siminsavani-msft 46287c7
Minor changes & commenting out test
siminsavani-msft 17310e5
Renaming of opts
siminsavani-msft cdd17c5
Changing option name for GetUserDelegationCredential
siminsavani-msft 73bb439
Minor type renaming
siminsavani-msft 1c8a6c3
Putting GetUserDelegationCredential on service.client
siminsavani-msft b8d57dd
Adding doc comment
siminsavani-msft f1d110a
Updating doc comment for KeyInfo
siminsavani-msft 0a046e5
Fixing example test with handle error
siminsavani-msft 07c039f
Fixing GetUserDelegationCredential and examples - Service.Client
siminsavani-msft 702a7d0
Removing NewUserDelegationCredential from models.go
siminsavani-msft File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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
64 changes: 64 additions & 0 deletions
64
sdk/storage/azblob/internal/exported/user_delegation_credential.go
This file contains 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,64 @@ | ||
//go:build go1.18 | ||
// +build go1.18 | ||
|
||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package exported | ||
|
||
import ( | ||
"crypto/hmac" | ||
"crypto/sha256" | ||
"encoding/base64" | ||
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/internal/generated" | ||
) | ||
|
||
// NewUserDelegationCredential creates a new UserDelegationCredential using a Storage account's Name and a user delegation Key from it | ||
func NewUserDelegationCredential(accountName string, udk UserDelegationKey) *UserDelegationCredential { | ||
return &UserDelegationCredential{ | ||
accountName: accountName, | ||
userDelegationKey: udk, | ||
} | ||
} | ||
|
||
// UserDelegationKey contains UserDelegationKey. | ||
type UserDelegationKey = generated.UserDelegationKey | ||
|
||
// UserDelegationCredential contains an account's name and its user delegation key. | ||
type UserDelegationCredential struct { | ||
accountName string | ||
userDelegationKey UserDelegationKey | ||
} | ||
|
||
// AccountName returns the Storage account's Name | ||
func (f *UserDelegationCredential) getAccountName() string { | ||
return f.accountName | ||
jhendrixMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// GetUDKParams is a helper method for accessing the user delegation key parameters outside of this package. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment isn't right |
||
func GetAccountName(udc *UserDelegationCredential) string { | ||
jhendrixMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return udc.getAccountName() | ||
} | ||
|
||
// computeHMACSHA256 generates a hash signature for an HTTP request or for a SAS. | ||
func (f *UserDelegationCredential) computeHMACSHA256(message string) (string, error) { | ||
jhendrixMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bytes, _ := base64.StdEncoding.DecodeString(*f.userDelegationKey.Value) | ||
h := hmac.New(sha256.New, bytes) | ||
_, err := h.Write([]byte(message)) | ||
return base64.StdEncoding.EncodeToString(h.Sum(nil)), err | ||
} | ||
|
||
// ComputeUDCHMACSHA256 is a helper method for computing the signed string outside of this package. | ||
func ComputeUDCHMACSHA256(udc *UserDelegationCredential, message string) (string, error) { | ||
jhendrixMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return udc.computeHMACSHA256(message) | ||
jhendrixMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
// GetUDKParams returns UserDelegationKey | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment isn't right |
||
func (f *UserDelegationCredential) getUDKParams() *UserDelegationKey { | ||
return &f.userDelegationKey | ||
} | ||
|
||
// GetUDKParams is a helper method for accessing the user delegation key parameters outside of this package. | ||
func GetUDKParams(udc *UserDelegationCredential) *UserDelegationKey { | ||
return udc.getUDKParams() | ||
jhendrixMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment isn't right