@@ -86,12 +86,6 @@ type STSCertificateIdentity struct {
8686// to the given STS endpoint with the given TLS certificate and retrieves and
8787// rotates S3 credentials.
8888func 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- }
9589 identity := & STSCertificateIdentity {
9690 STSEndpoint : endpoint ,
9791 Certificate : certificate ,
@@ -102,8 +96,21 @@ func NewSTSCertificateIdentity(endpoint string, certificate tls.Certificate, opt
10296 return New (identity ), nil
10397}
10498
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 )
107114 if err != nil {
108115 return Value {}, err
109116 }
@@ -130,6 +137,9 @@ func (i *STSCertificateIdentity) retrieve(cc *CredContext) (Value, error) {
130137 if client == nil {
131138 client = cc .Client
132139 }
140+ if client == nil {
141+ client = defaultCredContext .Client
142+ }
133143
134144 tr , ok := client .Transport .(* http.Transport )
135145 if ! ok {
@@ -192,14 +202,9 @@ func (i *STSCertificateIdentity) retrieve(cc *CredContext) (Value, error) {
192202 }, nil
193203}
194204
195- // RetrieveWithCredContext is Retrieve with cred context
196- func (i * STSCertificateIdentity ) RetrieveWithCredContext (cc * CredContext ) (Value , error ) {
197- return i .retrieve (cc )
198- }
199-
200205// Retrieve fetches a new set of S3 credentials from the configured STS API endpoint.
201206func (i * STSCertificateIdentity ) Retrieve () (Value , error ) {
202- return i .retrieve (defaultCredContext )
207+ return i .RetrieveWithCredContext (defaultCredContext )
203208}
204209
205210// Expiration returns the expiration time of the current S3 credentials.
0 commit comments