Skip to content

Commit

Permalink
Ensure that requestHeaders is correctly assigned a value (#15)
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw authored Mar 12, 2024
1 parent 2912959 commit ad68b70
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
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

0 comments on commit ad68b70

Please sign in to comment.