MCPcopy
hub / github.com/scality/cloudserver / signGcpRequest

Function signGcpRequest

tests/functional/raw-node/utils/makeRequest.js:12–28  ·  view source on GitHub ↗
(request, credentials, date)

Source from the content-addressed store, hash-verified

10const constructStringToSignV2 = require('arsenal/build/lib/auth/v2/constructStringToSign').default;
11
12function signGcpRequest(request, credentials, date) {
13 if (!credentials || !credentials.secretKey || !credentials.accessKey) {
14 throw new Error('Invalid GCP credentials: must have accessKey and secretKey properties. ' +
15 `Got: ${JSON.stringify(credentials)}`);
16 }
17 // eslint-disable-next-line no-param-reassign
18 request.headers['x-goog-date'] = date.toUTCString();
19 const data = Object.assign({}, request.headers);
20 const logger = { trace: () => {} };
21 const stringToSign = constructStringToSignV2(request, data, logger, 'GCP');
22 // Sign with HMAC-SHA1
23 const signature = crypto.createHmac('sha1', credentials.secretKey)
24 .update(stringToSign)
25 .digest('base64');
26 // eslint-disable-next-line no-param-reassign
27 request.headers['Authorization'] = `GOOG1 ${credentials.accessKey}:${signature}`;
28}
29
30const transport = conf.https ? https : http;
31const ipAddress = process.env.IP ? process.env.IP : '127.0.0.1';

Callers 1

makeRequestFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected