createSessionRequest - Wrapper creates a new CreateSession request.
(ctx context.Context, bucketName string, sessionMode SessionMode)
| 100 | |
| 101 | // createSessionRequest - Wrapper creates a new CreateSession request. |
| 102 | func (c *Client) createSessionRequest(ctx context.Context, bucketName string, sessionMode SessionMode) (*http.Request, error) { |
| 103 | // Set location query. |
| 104 | urlValues := make(url.Values) |
| 105 | urlValues.Set("session", "") |
| 106 | |
| 107 | // Set get bucket location always as path style. |
| 108 | targetURL := *c.endpointURL |
| 109 | |
| 110 | // Fetch new host based on the bucket location. |
| 111 | host := getS3ExpressEndpoint(c.region, s3utils.IsS3ExpressBucket(bucketName)) |
| 112 | |
| 113 | // as it works in makeTargetURL method from api.go file |
| 114 | if h, p, err := net.SplitHostPort(host); err == nil { |
| 115 | if targetURL.Scheme == "http" && p == "80" || targetURL.Scheme == "https" && p == "443" { |
| 116 | host = h |
| 117 | if ip := net.ParseIP(h); ip != nil && ip.To4() == nil { |
| 118 | host = "[" + h + "]" |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | isVirtualStyle := c.isVirtualHostStyleRequest(targetURL, bucketName) |
| 124 | |
| 125 | var urlStr string |
| 126 | |
| 127 | if isVirtualStyle { |
| 128 | urlStr = c.endpointURL.Scheme + "://" + bucketName + "." + host + "/?session" |
| 129 | } else { |
| 130 | targetURL.Path = path.Join(bucketName, "") + "/" |
| 131 | targetURL.RawQuery = urlValues.Encode() |
| 132 | urlStr = targetURL.String() |
| 133 | } |
| 134 | |
| 135 | // Get a new HTTP request for the method. |
| 136 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, urlStr, nil) |
| 137 | if err != nil { |
| 138 | return nil, err |
| 139 | } |
| 140 | |
| 141 | // Set UserAgent for the request. |
| 142 | c.setUserAgent(req) |
| 143 | |
| 144 | // Get credentials from the configured credentials provider. |
| 145 | value, err := c.credsProvider.GetWithContext(c.CredContext()) |
| 146 | if err != nil { |
| 147 | return nil, err |
| 148 | } |
| 149 | |
| 150 | var ( |
| 151 | signerType = value.SignerType |
| 152 | accessKeyID = value.AccessKeyID |
| 153 | secretAccessKey = value.SecretAccessKey |
| 154 | sessionToken = value.SessionToken |
| 155 | ) |
| 156 | |
| 157 | // Custom signer set then override the behavior. |
| 158 | if c.overrideSignerType != credentials.SignatureDefault { |
| 159 | signerType = c.overrideSignerType |
no test coverage detected