From a936e418993d6be8fcf82d08b1dff09cfdd6e7cf Mon Sep 17 00:00:00 2001 From: LBGarber Date: Wed, 5 May 2021 13:31:56 -0400 Subject: [PATCH] Add Image Content-Length and Context to UploadImageToURL Add Content-Length to image upload Add SetContext --- images.go | 6 +- .../integration/fixtures/TestUploadImage.yaml | 183 +++++++++++++++++- 2 files changed, 180 insertions(+), 9 deletions(-) diff --git a/images.go b/images.go index 2f1f2c9ba..0a5d1a597 100644 --- a/images.go +++ b/images.go @@ -246,10 +246,10 @@ func (c *Client) CreateImageUpload(ctx context.Context, createOpts ImageCreateUp // UploadImageToURL uploads the given image to the given upload URL func (c *Client) UploadImageToURL(ctx context.Context, uploadURL string, image io.Reader) error { - // We currently need to create a new resty instance in order to bypass the global transport. - // This is due to the S3 rejecting requests with Authorization headers, which are injected - // by the client and test suite. + // Linode-specific headers do not need to be sent to this endpoint req := resty.New().SetDebug(c.resty.Debug).R(). + SetContext(ctx). + SetContentLength(true). SetHeader("Content-Type", "application/octet-stream"). SetBody(image) diff --git a/test/integration/fixtures/TestUploadImage.yaml b/test/integration/fixtures/TestUploadImage.yaml index 02c0f0506..5b5f4a4ff 100644 --- a/test/integration/fixtures/TestUploadImage.yaml +++ b/test/integration/fixtures/TestUploadImage.yaml @@ -14,7 +14,7 @@ interactions: url: https://api.linode.com/v4beta/images/upload method: POST response: - body: '{"upload_to": "https://us-east-1.linodeobjects.com:443/linode-production-machine-images-uploads/12056370?Signature=iiRvVN6J0LbQjK4AiIpK7l3Pvpw%3D&Expires=1620318538&AWSAccessKeyID=SANITIZED", "image": {"id": "private/12056370", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 0, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "pending_upload"}}' + body: '{"upload_to": "https://us-east-1.linodeobjects.com:443/linode-production-machine-images-uploads/12071278?Signature=aXcQc8XotSGc3xD1ADUv5qIiksI%3D&Expires=1620392958&AWSAccessKeyID=SANITIZED", "image": {"id": "private/12071278", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 0, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "pending_upload"}}' headers: Access-Control-Allow-Credentials: - "true" @@ -66,10 +66,10 @@ interactions: - application/json User-Agent: - linodego https://github.com/linode/linodego - url: https://api.linode.com/v4beta/images/private/12056370 + url: https://api.linode.com/v4beta/images/private/12071278 method: GET response: - body: '{"id": "private/12056370", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 0, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "pending_upload"}' + body: '{"id": "private/12071278", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 0, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "pending_upload"}' headers: Access-Control-Allow-Credentials: - "true" @@ -123,10 +123,181 @@ interactions: - application/json User-Agent: - linodego https://github.com/linode/linodego - url: https://api.linode.com/v4beta/images/private/12056370 + url: https://api.linode.com/v4beta/images/private/12071278 method: GET response: - body: '{"id": "private/12056370", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 1, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "available"}' + body: '{"id": "private/12071278", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 0, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "pending_upload"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Content-Length: + - "338" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - images:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "800" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego https://github.com/linode/linodego + url: https://api.linode.com/v4beta/images/private/12071278 + method: GET + response: + body: '{"id": "private/12071278", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 0, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "pending_upload"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Content-Length: + - "338" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - images:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "800" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego https://github.com/linode/linodego + url: https://api.linode.com/v4beta/images/private/12071278 + method: GET + response: + body: '{"id": "private/12071278", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 0, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "pending_upload"}' + headers: + Access-Control-Allow-Credentials: + - "true" + Access-Control-Allow-Headers: + - Authorization, Origin, X-Requested-With, Content-Type, Accept, X-Filter + Access-Control-Allow-Methods: + - HEAD, GET, OPTIONS, POST, PUT, DELETE + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Status + Cache-Control: + - private, max-age=0, s-maxage=0, no-cache, no-store + - private, max-age=60, s-maxage=60 + Content-Length: + - "338" + Content-Security-Policy: + - default-src 'none' + Content-Type: + - application/json + Server: + - nginx + Strict-Transport-Security: + - max-age=31536000 + Vary: + - Authorization, X-Filter + - Authorization, X-Filter + X-Accepted-Oauth-Scopes: + - images:read_only + X-Content-Type-Options: + - nosniff + X-Frame-Options: + - DENY + - DENY + X-Oauth-Scopes: + - '*' + X-Ratelimit-Limit: + - "800" + X-Xss-Protection: + - 1; mode=block + status: 200 OK + code: 200 + duration: "" +- request: + body: "" + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + User-Agent: + - linodego https://github.com/linode/linodego + url: https://api.linode.com/v4beta/images/private/12071278 + method: GET + response: + body: '{"id": "private/12071278", "label": "linodego-test-image", "description": "An image that does stuff.", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "size": 1, "created_by": "LGarber", "type": "manual", "is_public": false, "deprecated": false, "vendor": null, "expiry": null, "eol": null, "status": "available"}' headers: Access-Control-Allow-Credentials: - "true" @@ -180,7 +351,7 @@ interactions: - application/json User-Agent: - linodego https://github.com/linode/linodego - url: https://api.linode.com/v4beta/images/private/12056370 + url: https://api.linode.com/v4beta/images/private/12071278 method: DELETE response: body: '{}'