@@ -86,12 +86,6 @@ type STSCertificateIdentity struct {
86
86
// to the given STS endpoint with the given TLS certificate and retrieves and
87
87
// rotates S3 credentials.
88
88
func NewSTSCertificateIdentity (endpoint string , certificate tls.Certificate , options ... CertificateIdentityOption ) (* Credentials , error ) {
89
- if endpoint == "" {
90
- return nil , errors .New ("STS endpoint cannot be empty" )
91
- }
92
- if _ , err := url .Parse (endpoint ); err != nil {
93
- return nil , err
94
- }
95
89
identity := & STSCertificateIdentity {
96
90
STSEndpoint : endpoint ,
97
91
Certificate : certificate ,
@@ -102,8 +96,21 @@ func NewSTSCertificateIdentity(endpoint string, certificate tls.Certificate, opt
102
96
return New (identity ), nil
103
97
}
104
98
105
- func (i * STSCertificateIdentity ) retrieve (cc * CredContext ) (Value , error ) {
106
- endpointURL , err := url .Parse (i .STSEndpoint )
99
+ // RetrieveWithCredContext is Retrieve with cred context
100
+ func (i * STSCertificateIdentity ) RetrieveWithCredContext (cc * CredContext ) (Value , error ) {
101
+ if cc == nil {
102
+ cc = defaultCredContext
103
+ }
104
+
105
+ stsEndpoint := i .STSEndpoint
106
+ if stsEndpoint == "" {
107
+ stsEndpoint = cc .Endpoint
108
+ }
109
+ if stsEndpoint == "" {
110
+ return Value {}, errors .New ("STS endpoint unknown" )
111
+ }
112
+
113
+ endpointURL , err := url .Parse (stsEndpoint )
107
114
if err != nil {
108
115
return Value {}, err
109
116
}
@@ -130,6 +137,9 @@ func (i *STSCertificateIdentity) retrieve(cc *CredContext) (Value, error) {
130
137
if client == nil {
131
138
client = cc .Client
132
139
}
140
+ if client == nil {
141
+ client = defaultCredContext .Client
142
+ }
133
143
134
144
tr , ok := client .Transport .(* http.Transport )
135
145
if ! ok {
@@ -192,14 +202,9 @@ func (i *STSCertificateIdentity) retrieve(cc *CredContext) (Value, error) {
192
202
}, nil
193
203
}
194
204
195
- // RetrieveWithCredContext is Retrieve with cred context
196
- func (i * STSCertificateIdentity ) RetrieveWithCredContext (cc * CredContext ) (Value , error ) {
197
- return i .retrieve (cc )
198
- }
199
-
200
205
// Retrieve fetches a new set of S3 credentials from the configured STS API endpoint.
201
206
func (i * STSCertificateIdentity ) Retrieve () (Value , error ) {
202
- return i .retrieve (defaultCredContext )
207
+ return i .RetrieveWithCredContext (defaultCredContext )
203
208
}
204
209
205
210
// Expiration returns the expiration time of the current S3 credentials.
0 commit comments