MCPcopy
hub / github.com/minio/minio-go / RetrieveWithCredContext

Method RetrieveWithCredContext

pkg/credentials/sts_ldap_identity.go:139–229  ·  view source on GitHub ↗

RetrieveWithCredContext gets the credential by calling the MinIO STS API for LDAP on the configured stsEndpoint.

(cc *CredContext)

Source from the content-addressed store, hash-verified

137// RetrieveWithCredContext gets the credential by calling the MinIO STS API for
138// LDAP on the configured stsEndpoint.
139func (k *LDAPIdentity) RetrieveWithCredContext(cc *CredContext) (value Value, err error) {
140 if cc == nil {
141 cc = defaultCredContext
142 }
143
144 stsEndpoint := k.STSEndpoint
145 if stsEndpoint == "" {
146 stsEndpoint = cc.Endpoint
147 }
148 if stsEndpoint == "" {
149 return Value{}, errors.New("STS endpoint unknown")
150 }
151
152 u, err := url.Parse(stsEndpoint)
153 if err != nil {
154 return value, err
155 }
156
157 v := url.Values{}
158 v.Set("Action", "AssumeRoleWithLDAPIdentity")
159 v.Set("Version", STSVersion)
160 v.Set("LDAPUsername", k.LDAPUsername)
161 v.Set("LDAPPassword", k.LDAPPassword)
162 if k.Policy != "" {
163 v.Set("Policy", k.Policy)
164 }
165 if k.RequestedExpiry != 0 {
166 v.Set("DurationSeconds", fmt.Sprintf("%d", int(k.RequestedExpiry.Seconds())))
167 }
168 if k.TokenRevokeType != "" {
169 v.Set("TokenRevokeType", k.TokenRevokeType)
170 }
171 if k.ConfigName != "" {
172 v.Set("ConfigName", k.ConfigName)
173 }
174
175 req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
176 if err != nil {
177 return value, err
178 }
179
180 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
181
182 client := k.Client
183 if client == nil {
184 client = cc.Client
185 }
186 if client == nil {
187 client = defaultCredContext.Client
188 }
189
190 resp, err := client.Do(req)
191 if err != nil {
192 return value, err
193 }
194
195 defer resp.Body.Close()
196 if resp.StatusCode != http.StatusOK {

Callers 1

RetrieveMethod · 0.95

Calls 6

DoMethod · 0.80
SetExpirationMethod · 0.80
xmlDecodeAndBodyFunction · 0.70
SetMethod · 0.45
StringMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected