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

Method getBucketLocationRequest

bucket-cache.go:133–219  ·  view source on GitHub ↗

getBucketLocationRequest - Wrapper creates a new getBucketLocation request.

(ctx context.Context, bucketName string)

Source from the content-addressed store, hash-verified

131
132// getBucketLocationRequest - Wrapper creates a new getBucketLocation request.
133func (c *Client) getBucketLocationRequest(ctx context.Context, bucketName string) (*http.Request, error) {
134 // Set location query.
135 urlValues := make(url.Values)
136 urlValues.Set("location", "")
137
138 // Set get bucket location always as path style.
139 targetURL := *c.endpointURL
140
141 // as it works in makeTargetURL method from api.go file
142 if h, p, err := net.SplitHostPort(targetURL.Host); err == nil {
143 if targetURL.Scheme == "http" && p == "80" || targetURL.Scheme == "https" && p == "443" {
144 targetURL.Host = h
145 if ip := net.ParseIP(h); ip != nil && ip.To4() == nil {
146 targetURL.Host = "[" + h + "]"
147 }
148 }
149 }
150
151 isVirtualStyle := c.isVirtualHostStyleRequest(targetURL, bucketName)
152
153 var urlStr string
154
155 if isVirtualStyle {
156 urlStr = c.endpointURL.Scheme + "://" + bucketName + "." + targetURL.Host + "/?location"
157 } else {
158 targetURL.Path = path.Join(bucketName, "") + "/"
159 targetURL.RawQuery = urlValues.Encode()
160 urlStr = targetURL.String()
161 }
162
163 // Get a new HTTP request for the method.
164 req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlStr, nil)
165 if err != nil {
166 return nil, err
167 }
168
169 // Set UserAgent for the request.
170 c.setUserAgent(req)
171
172 // Get credentials from the configured credentials provider.
173 value, err := c.credsProvider.GetWithContext(c.CredContext())
174 if err != nil {
175 return nil, err
176 }
177
178 var (
179 signerType = value.SignerType
180 accessKeyID = value.AccessKeyID
181 secretAccessKey = value.SecretAccessKey
182 sessionToken = value.SessionToken
183 )
184
185 // Custom signer set then override the behavior.
186 if c.overrideSignerType != credentials.SignatureDefault {
187 signerType = c.overrideSignerType
188 }
189
190 // If signerType returned by credentials helper is anonymous,

Callers 2

getBucketLocationMethod · 0.95

Calls 13

setUserAgentMethod · 0.95
CredContextMethod · 0.95
SignV2Function · 0.92
IsAmazonOutpostsEndpointFunction · 0.92
SignV4OutpostsFunction · 0.92
SignV4Function · 0.92
getDefaultLocationFunction · 0.85
GetWithContextMethod · 0.80
IsAnonymousMethod · 0.80
IsV2Method · 0.80
SetMethod · 0.45

Tested by 1