Skip to content

Commit

Permalink
chore(functions): remove unused signed url sample (#2018)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace Nassri authored Oct 22, 2020
1 parent edae294 commit dc662bb
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 65 deletions.
40 changes: 0 additions & 40 deletions functions/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 0 additions & 25 deletions functions/http/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});

0 comments on commit dc662bb

Please sign in to comment.