Skip to content
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

rename sts credentials provider #82

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion credentials/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func NewCredential(config *Config) (credential Credential, err error) {
if err != nil {
return
}
credential = newStsTokenCredential(
credential = NewStaticSTSCredentialsProvider(
tea.StringValue(config.AccessKeyId),
tea.StringValue(config.AccessKeySecret),
tea.StringValue(config.SecurityToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package credentials

import "github.com/alibabacloud-go/tea/tea"

// StsTokenCredential is a kind of credentials
type StsTokenCredential struct {
// StsTokenCredential is a kind of credentials provider
type StaticSTSCredentialsProvider struct {
AccessKeyId string
AccessKeySecret string
SecurityToken string
}

func newStsTokenCredential(accessKeyId, accessKeySecret, securityToken string) *StsTokenCredential {
return &StsTokenCredential{
func NewStaticSTSCredentialsProvider(accessKeyId, accessKeySecret, securityToken string) *StaticSTSCredentialsProvider {
return &StaticSTSCredentialsProvider{
AccessKeyId: accessKeyId,
AccessKeySecret: accessKeySecret,
SecurityToken: securityToken,
}
}

func (s *StsTokenCredential) GetCredential() (*CredentialModel, error) {
func (s *StaticSTSCredentialsProvider) GetCredential() (*CredentialModel, error) {
credential := &CredentialModel{
AccessKeyId: tea.String(s.AccessKeyId),
AccessKeySecret: tea.String(s.AccessKeySecret),
Expand All @@ -28,26 +28,26 @@ func (s *StsTokenCredential) GetCredential() (*CredentialModel, error) {
}

// GetAccessKeyId reutrns StsTokenCredential's AccessKeyId
func (s *StsTokenCredential) GetAccessKeyId() (*string, error) {
func (s *StaticSTSCredentialsProvider) GetAccessKeyId() (*string, error) {
return tea.String(s.AccessKeyId), nil
}

// GetAccessSecret reutrns StsTokenCredential's AccessKeySecret
func (s *StsTokenCredential) GetAccessKeySecret() (*string, error) {
func (s *StaticSTSCredentialsProvider) GetAccessKeySecret() (*string, error) {
return tea.String(s.AccessKeySecret), nil
}

// GetSecurityToken reutrns StsTokenCredential's SecurityToken
func (s *StsTokenCredential) GetSecurityToken() (*string, error) {
func (s *StaticSTSCredentialsProvider) GetSecurityToken() (*string, error) {
return tea.String(s.SecurityToken), nil
}

// GetBearerToken is useless StsTokenCredential
func (s *StsTokenCredential) GetBearerToken() *string {
func (s *StaticSTSCredentialsProvider) GetBearerToken() *string {
return tea.String("")
}

// GetType reutrns StsTokenCredential's type
func (s *StsTokenCredential) GetType() *string {
func (s *StaticSTSCredentialsProvider) GetType() *string {
return tea.String("sts")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func Test_StsCredential(t *testing.T) {
auth := newStsTokenCredential("accessKeyId", "accessKeySecret", "securityToken")
auth := NewStaticSTSCredentialsProvider("accessKeyId", "accessKeySecret", "securityToken")
accessKeyId, err := auth.GetAccessKeyId()
assert.Nil(t, err)
assert.Equal(t, "accessKeyId", *accessKeyId)
Expand Down
Loading