Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that requestHeaders is correctly assigned a value #15

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions azure/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,21 @@ func (c *container) PreSignRequest(ctx context.Context, method stow.ClientMethod
params stow.PresignRequestParams) (response stow.PresignResponse, err error) {
containerName := c.id
blobName := key

var requestHeaders map[string]string
permissions := sas.BlobPermissions{}
switch method {
case stow.ClientMethodGet:
permissions.Read = true
case stow.ClientMethodPut:
permissions.Add = true
permissions.Write = true

requestHeaders = map[string]string{"Content-Length": strconv.Itoa(len(params.ContentMD5)), "Content-MD5": params.ContentMD5}
requestHeaders["x-ms-blob-type"] = "BlockBlob" // https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob?tabs=microsoft-entra-id#remarks

if params.AddContentMD5Metadata {
requestHeaders[fmt.Sprintf("x-ms-meta-%s", stow.FlyteContentMD5)] = params.ContentMD5
}
}

sasQueryParams, err := c.preSigner(ctx, sas.BlobSignatureValues{
Expand All @@ -68,13 +75,6 @@ func (c *container) PreSignRequest(ctx context.Context, method stow.ClientMethod
// Create the SAS URL for the resource you wish to access, and append the SAS query parameters.
qp := sasQueryParams.Encode()

requestHeaders := map[string]string{"Content-Length": strconv.Itoa(len(params.ContentMD5)), "Content-MD5": params.ContentMD5}
requestHeaders["x-ms-blob-type"] = "BlockBlob" // https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob?tabs=microsoft-entra-id#remarks

if params.AddContentMD5Metadata {
requestHeaders[fmt.Sprintf("x-ms-meta-%s", stow.FlyteContentMD5)] = params.ContentMD5
}

return stow.PresignResponse{Url: fmt.Sprintf("%s/%s?%s", c.client.URL(), blobName, qp), RequiredRequestHeaders: requestHeaders}, nil
}

Expand Down
14 changes: 7 additions & 7 deletions google/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ func (c *Container) Bucket() *storage.BucketHandle {

func (c *Container) PreSignRequest(_ context.Context, clientMethod stow.ClientMethod, id string,
params stow.PresignRequestParams) (response stow.PresignResponse, err error) {
headers := make([]string, 0, 3)
var requestHeaders map[string]string
if len(params.HttpMethod) == 0 {
switch clientMethod {
case stow.ClientMethodGet:
params.HttpMethod = http.MethodGet
case stow.ClientMethodPut:
params.HttpMethod = http.MethodPut
requestHeaders = map[string]string{"Content-Length": strconv.Itoa(len(params.ContentMD5)), "Content-MD5": params.ContentMD5}
if params.AddContentMD5Metadata {
headers = append(headers, fmt.Sprintf("%s%s: %s", googleMetadataPrefix, stow.FlyteContentMD5, params.ContentMD5))
requestHeaders[fmt.Sprintf("%s%s", googleMetadataPrefix, stow.FlyteContentMD5)] = params.ContentMD5
}
}
}

headers := make([]string, 0, 3)
requestHeaders := map[string]string{"Content-Length": strconv.Itoa(len(params.ContentMD5)), "Content-MD5": params.ContentMD5}
if params.AddContentMD5Metadata {
headers = append(headers, fmt.Sprintf("%s%s: %s", googleMetadataPrefix, stow.FlyteContentMD5, params.ContentMD5))
requestHeaders[fmt.Sprintf("%s%s", googleMetadataPrefix, stow.FlyteContentMD5)] = params.ContentMD5
}

url, error := c.Bucket().SignedURL(id, &storage.SignedURLOptions{
Method: params.HttpMethod,
Expires: time.Now().Add(params.ExpiresIn),
Expand Down
2 changes: 1 addition & 1 deletion s3/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *container) PreSignRequest(ctx context.Context, clientMethod stow.Client
}

metadata := make(map[string]*string)
requestHeaders := map[string]string{"Content-Length": strconv.Itoa(len(params.ContentMD5)), "Content-MD5": params.ContentMD5}
requestHeaders = map[string]string{"Content-Length": strconv.Itoa(len(params.ContentMD5)), "Content-MD5": params.ContentMD5}
if params.AddContentMD5Metadata {
metadata[stow.FlyteContentMD5] = aws.String(params.ContentMD5)
requestHeaders[fmt.Sprintf("x-amz-meta-%s", stow.FlyteContentMD5)] = params.ContentMD5
Expand Down