mirror of https://github.com/grpc/grpc-node.git
chore: address code review
This commit is contained in:
parent
782d5acdb2
commit
c89d4438be
|
|
@ -131,7 +131,7 @@ export const credentials = mixin(
|
|||
getHeaders.then(
|
||||
headers => {
|
||||
const metadata = new Metadata();
|
||||
for (const key in headers) {
|
||||
for (const key of Object.keys(headers)) {
|
||||
metadata.add(key, headers[key]);
|
||||
}
|
||||
callback(null, metadata);
|
||||
|
|
|
|||
|
|
@ -187,20 +187,20 @@ function getAuthorizationHeaderFromGoogleCredential(google_credential, url, call
|
|||
// but has getRequestMetadata, which is deprecated in v2.0.0
|
||||
if (typeof google_credential.getRequestHeaders === 'function') {
|
||||
google_credential.getRequestHeaders(url)
|
||||
.then(function(header) {
|
||||
callback(null, header.Authorization);
|
||||
.then(function(headers) {
|
||||
callback(null, headers);
|
||||
})
|
||||
.catch(function(err) {
|
||||
callback(err);
|
||||
return;
|
||||
});
|
||||
} else {
|
||||
google_credential.getRequestMetadata(url, function(err, header) {
|
||||
google_credential.getRequestMetadata(url, function(err, headers) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
callback(null, header.Authorization);
|
||||
callback(null, headers);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -217,14 +217,16 @@ exports.createFromGoogleCredential = function(google_credential) {
|
|||
return exports.createFromMetadataGenerator(function(auth_context, callback) {
|
||||
var service_url = auth_context.service_url;
|
||||
getAuthorizationHeaderFromGoogleCredential(google_credential, service_url,
|
||||
function(err, authHeader) {
|
||||
function(err, headers) {
|
||||
if (err) {
|
||||
common.log(constants.logVerbosity.INFO, 'Auth error:' + err);
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
var metadata = new Metadata();
|
||||
metadata.add('authorization', authHeader);
|
||||
for (const key of Object.keys(headers)) {
|
||||
metadata.add(key, headers[key]);
|
||||
}
|
||||
callback(null, metadata);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue