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