-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Internal] Move package credentials in config (#1115)
## What changes are proposed in this pull request? This PR moves the `credentials` package in `config`, thus centralizing the credentials logic in a single place. The goal of this change is to prepare the current SDK-Beta to facilitate migration to the new SDK that is currently being developed. This PR introduces a breaking change by changing the import paths to `CredentialsProvider`. However, we believe that the impact is fairly contained as (i) `CredentialsProvider` is mostly internally, and (ii) the breaking change can be addressed by updating the import path. ## How is this tested? Through normal unit test and integration tests.
- Loading branch information
1 parent
adc94ca
commit 23d9c1e
Showing
20 changed files
with
84 additions
and
90 deletions.
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package credentials | ||
|
||
import ( | ||
"net/http" | ||
|
||
"golang.org/x/oauth2" | ||
) | ||
|
||
// CredentialsProvider is an interface for providing credentials to the client. | ||
// Implementations of this interface should set the necessary headers on the request. | ||
type CredentialsProvider interface { | ||
// SetHeaders sets the necessary headers on the request. | ||
SetHeaders(r *http.Request) error | ||
} | ||
|
||
type credentialsProvider struct { | ||
setHeaders func(r *http.Request) error | ||
} | ||
|
||
func (c *credentialsProvider) SetHeaders(r *http.Request) error { | ||
return c.setHeaders(r) | ||
} | ||
|
||
func NewCredentialsProvider(visitor func(r *http.Request) error) CredentialsProvider { | ||
return &credentialsProvider{ | ||
setHeaders: visitor, | ||
} | ||
} | ||
|
||
// OAuthCredentialsProvider is a specialized CredentialsProvider uses and provides an OAuth token. | ||
type OAuthCredentialsProvider interface { | ||
CredentialsProvider | ||
// Token returns the OAuth token generated by the provider. | ||
Token() (*oauth2.Token, error) | ||
} | ||
|
||
type oauthCredentialsProvider struct { | ||
setHeaders func(r *http.Request) error | ||
token func() (*oauth2.Token, error) | ||
} | ||
|
||
func (c *oauthCredentialsProvider) SetHeaders(r *http.Request) error { | ||
return c.setHeaders(r) | ||
} | ||
|
||
func (c *oauthCredentialsProvider) Token() (*oauth2.Token, error) { | ||
return c.token() | ||
} | ||
|
||
func NewOAuthCredentialsProvider(visitor func(r *http.Request) error, tokenProvider func() (*oauth2.Token, error)) OAuthCredentialsProvider { | ||
return &oauthCredentialsProvider{ | ||
setHeaders: visitor, | ||
token: tokenProvider, | ||
} | ||
} | ||
|
||
// OAuthToken represents an OAuth token as defined by the OAuth 2.0 Authorization Framework. | ||
// https://datatracker.ietf.org/doc/html/rfc6749 | ||
type OAuthToken struct { | ||
// The access token issued by the authorization server. This is the token that will be used to authenticate requests. | ||
AccessToken string `json:"access_token" auth:",sensitive"` | ||
// Time in seconds until the token expires. | ||
ExpiresIn int `json:"expires_in"` | ||
// The scope of the token. This is a space-separated list of strings that represent the permissions granted by the token. | ||
Scope string `json:"scope"` | ||
// The type of token that was issued. | ||
TokenType string `json:"token_type"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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