in core/routemgmt/common/utils.js [37:85]
function createTenant(gwInfo, namespace, tenantInstance) {
var instance = tenantInstance || 'openwhisk'; // Default to a fixed instance so all openwhisk tenants have a common instance
var options = {
followAllRedirects: true,
url: gwInfo.gwUrl+'/tenants',
headers: {
'Accept': 'application/json'
},
json: { // Auto set header: 'Content-Type': 'application/json'
instance: instance,
namespace: namespace
}
};
if (gwInfo.gwAuth) {
options.headers.Authorization = 'Basic ' + gwInfo.gwAuth;
}
console.log('addTenantToGateway: request: '+JSON.stringify(options));
return new Promise(function(resolve, reject) {
request.put(options, function(error, response, body) {
var statusCode = response ? response.statusCode : undefined;
console.log('addTenantToGateway: response status: '+ statusCode);
if (error) console.error('Warning: addTenantToGateway request failed: '+utils2.makeJsonString(error));
if (body) console.log('addTenantToGateway: response body: '+utils2.makeJsonString(body));
if (error) {
console.error('addTenantToGateway: Unable to configure a tenant on the API Gateway');
reject('Unable to configure the API Gateway: '+utils2.makeJsonString(error));
} else if (statusCode != 200) {
if (body) {
var errMsg = JSON.stringify(body);
if (body.error && body.error.message) errMsg = body.error.message;
reject('API Gateway failure (status code '+statusCode+'): '+ errMsg);
} else {
reject('Unable to configure the API Gateway: Response failure code: '+statusCode);
}
} else {
if (body && body.id) { // body has format like: { id: GUID, namespace: NAMESPACE, instance: 'openwhisk' }
console.log('addTenantToGateway: got a single tenant response');
resolve(body);
} else {
console.error('addTenantToGateway: failure: No tenant guid provided');
reject('Unable to configure the API Gateway: Invalid response from API Gateway');
}
}
});
});
}