From dc662bb1d6e6ffb0b0303d21c1fa987cd0284fb8 Mon Sep 17 00:00:00 2001 From: Ace Nassri Date: Thu, 22 Oct 2020 15:38:28 -0700 Subject: [PATCH] chore(functions): remove unused signed url sample (#2018) --- functions/http/index.js | 40 ------------------------------- functions/http/test/index.test.js | 25 ------------------- 2 files changed, 65 deletions(-) diff --git a/functions/http/index.js b/functions/http/index.js index e3eafd3fc6..e44abe44be 100644 --- a/functions/http/index.js +++ b/functions/http/index.js @@ -183,46 +183,6 @@ exports.uploadFile = (req, res) => { }; // [END functions_http_form_data] -// [START functions_http_signed_url] -const {Storage} = require('@google-cloud/storage'); -const storage = new Storage(); - -/** - * HTTP function that generates a signed URL - * The signed URL can be used to upload files to Google Cloud Storage (GCS) - * - * @param {Object} req Cloud Function request context. - * @param {Object} res Cloud Function response context. - */ -exports.getSignedUrl = (req, res) => { - if (req.method !== 'POST') { - // Return a "method not allowed" error - return res.status(405).end(); - } - // TODO(developer) check that the user is authorized to upload - - // Get a reference to the destination file in GCS - const file = storage.bucket(req.body.bucket).file(req.body.filename); - - // Create a temporary upload URL - const expiresAtMs = Date.now() + 300000; // Link expires in 5 minutes - const config = { - action: 'write', - expires: expiresAtMs, - contentType: req.body.contentType, - }; - - file.getSignedUrl(config, (err, url) => { - if (err) { - console.error(err); - res.status(500).end(); - return; - } - res.send(url); - }); -}; -// [END functions_http_signed_url] - // [START functions_http_cors] /** * HTTP function that supports CORS requests. diff --git a/functions/http/test/index.test.js b/functions/http/test/index.test.js index 2d63a36d70..b719b72820 100644 --- a/functions/http/test/index.test.js +++ b/functions/http/test/index.test.js @@ -240,31 +240,6 @@ describe('functions_http_cors', () => { }); }); -describe('functions_http_signed_url', () => { - it('http:getSignedUrl: should process example request', async () => { - const mocks = getMocks(); - const httpSample = getSample(); - - const reqMock = { - method: 'POST', - body: { - bucket: 'nodejs-docs-samples', - filename: `gcf-gcs-url-${uuid.v4()}`, - contentType: 'application/octet-stream', - }, - }; - - httpSample.sample.getSignedUrl(reqMock, mocks.res); - - // Instead of modifying the sample to return a promise, - // use a delay here and keep the sample idiomatic - await new Promise((resolve) => setTimeout(resolve, 300)); - - assert.strictEqual(mocks.res.status.called, false); - assert.strictEqual(mocks.res.send.calledOnce, true); - }); -}); - describe('functions_http_cors_auth functions_http_form_data functions_http_xml', () => { // Allow-list these region tags with the region-tag enforcer });