@sap/cds-dk
Advanced tools
Comparing version 7.9.3 to 7.9.4
@@ -29,6 +29,4 @@ const cds = require('../cds'); | ||
// Serialized because of parallelization issues in the cf CLI, | ||
// see https://github.com/cloudfoundry/cli/issues/2232 | ||
// await Promise.all(Object.keys(bindings).map(async name => { | ||
for (const name of Object.keys(bindings)) { | ||
// run in parallel | ||
await Promise.all(Object.keys(bindings).map(async name => { | ||
const binding = bindings[name] | ||
@@ -44,3 +42,3 @@ const cacheKey = JSON.stringify(binding) | ||
resolvedBindings[name] = resolvedBinding | ||
} | ||
})); | ||
return Object.keys(resolvedBindings).length > 0 ? resolvedBindings : undefined | ||
@@ -47,0 +45,0 @@ } |
@@ -35,8 +35,5 @@ const cds = require('../cds'); | ||
// run in parallel | ||
const targets = options.to.split(/,/g); | ||
// Serialized because of parallelization issues in the cf CLI, | ||
// see https://github.com/cloudfoundry/cli/issues/2232 | ||
// resolvedServices = await Promise.all(targets.map(async target => { | ||
const resolvedServices = []; | ||
for (const target of targets) { | ||
const resolvedServices = await Promise.all(targets.map(async target => { | ||
let binding; | ||
@@ -55,4 +52,4 @@ if (on === 'k8s') { | ||
resolvedService.binding.resolved = false; | ||
resolvedServices.push(resolvedService); | ||
} | ||
return resolvedService; | ||
})); | ||
@@ -59,0 +56,0 @@ if (options.kind) { |
@@ -20,3 +20,3 @@ const path = require('path'); | ||
const DEBUG = cds.debug('deploy'); | ||
const DEBUG = cds.debug('cli'); | ||
@@ -23,0 +23,0 @@ module.exports = new class HanaDeployer { |
@@ -8,3 +8,3 @@ module.exports = { | ||
JAVA_LTS_VERSIONS: [17, 21], | ||
MAVEN_ARCHETYPE_VERSION: '2.9.0', | ||
MAVEN_ARCHETYPE_VERSION: '2.10.1', | ||
@@ -11,0 +11,0 @@ OPTIONS: Object.freeze({ |
@@ -1,3 +0,1 @@ | ||
// eslint-disable-next-line no-console | ||
const cp = require('child_process'); | ||
@@ -9,2 +7,4 @@ const fsp = require('fs').promises; | ||
const axios = require('axios'); | ||
const IS_WIN = os.platform() === 'win32'; | ||
@@ -15,4 +15,4 @@ const execAsync = util.promisify(cp.exec); | ||
const LOG = cds.log ? cds.log('deploy') : console; | ||
const DEBUG = cds.debug('deploy'); | ||
const LOG = cds.log ? cds.log('cli') : console; | ||
const DEBUG = cds.debug('cli'); | ||
@@ -32,2 +32,3 @@ const { bold, warn } = require('./term'); | ||
const CF_CLIENT_MINIMUM_VERSION = 8; | ||
const ENCODED_COMMA = encodeURIComponent(','); | ||
@@ -62,3 +63,2 @@ module.exports = new class CfUtil { | ||
} finally { | ||
// eslint-disable-next-line no-console | ||
DEBUG && console.timeEnd(cmdLine); | ||
@@ -69,37 +69,37 @@ } | ||
async cfRequest(urlPath, queryObj, bodyObj) { | ||
if (queryObj) { | ||
const entries = Object.entries(queryObj); | ||
const queryStr = entries.map(([key, value]) => { | ||
if (Array.isArray(value)) { | ||
value = value.join(','); | ||
} | ||
// commas cause problems in cf curl when not double encoded | ||
// value = value.replace(/,/g, encodeURIComponent(',')); | ||
return `${key}=${encodeURIComponent(value)}`; | ||
}).join('&'); | ||
const url = this.spaceInfo.apiEndpoint + urlPath; | ||
urlPath = urlPath + `?${queryStr}`; | ||
} | ||
const options = { | ||
headers: { 'Authorization': this.spaceInfo.token } | ||
}; | ||
// cf curl PATH [-iv] [-X METHOD] [-H HEADER]... [-d DATA] [--output FILE] | ||
const args = ['curl', urlPath]; | ||
if (bodyObj) { | ||
args.push('-d'); | ||
args.push(JSON.stringify(bodyObj)); // cfRun uses spawn so no special handling for quotes on cli required | ||
if (queryObj && Object.keys(queryObj).length > 0) { | ||
const params = {}; | ||
for (const [k, v] of Object.entries(queryObj)) { | ||
// cf rest API does not accept comma in query parameters | ||
params[k] = v.replaceAll(',', ENCODED_COMMA); | ||
} | ||
options.params = params; | ||
} | ||
const result = await this.cfRun(...args); | ||
let response = {}; | ||
if (result.stdout) { | ||
response = JSON.parse(result.stdout); | ||
} else if (result.stderr) { | ||
response = { errors: [{ title: result.stderr }] }; | ||
try { | ||
let response; | ||
if (bodyObj) { | ||
response = (await axios.post(url, bodyObj, options)); | ||
} else { | ||
response = (await axios.get(url, options)); | ||
} | ||
if (DEBUG) { | ||
options.headers.Authorization = 'bearer <token>'; | ||
LOG.debug(`POST ${url}\n${JSON.stringify(options, null, 4)}\n${JSON.stringify(response.data, null, 4)}`); | ||
} | ||
return response.data; | ||
} catch (err) { | ||
if (err instanceof axios.AxiosError) { | ||
if (err.response?.data?.errors[0]) { | ||
throw JSON.stringify(err.response.data.errors[0], null, 4); | ||
} | ||
throw err.message; | ||
} | ||
} | ||
if (response.errors) { | ||
const errorMessage = response.errors.map((entry) => `${entry.title || ''}: ${entry.detail || ''} (${entry.code || ''})`).join('\n'); | ||
throw new Error(errorMessage); | ||
} | ||
return response; | ||
} | ||
@@ -112,3 +112,3 @@ | ||
} | ||
throw new Error(errorMsg); | ||
throw errorMsg; | ||
} | ||
@@ -156,4 +156,6 @@ | ||
await this._checkCliVersion(); | ||
await this._getCfAuthorization(); | ||
return await this._getCfTargetFromConfigFile() || await this._getCfTargetFromCli(); | ||
const token = await this._getCfAuthorization(); | ||
const target = await this._getCfTargetFromConfigFile() || await this._getCfTargetFromCli(); | ||
target.token = token; | ||
return target; | ||
} | ||
@@ -177,13 +179,13 @@ | ||
const target = await this.getCfTarget(); | ||
this.spaceInfo = target; | ||
const { org, space } = target; | ||
const orgs = await this.cfRequest(`/v3/organizations`, { names: org }); | ||
const orgs = await this.cfRequest('/v3/organizations', { names: org }); | ||
if (!orgs?.resources?.length) { | ||
throw new Error(`CF org ${bold(org)} not found!`); | ||
throw `CF org ${bold(org)} not found!`; | ||
} | ||
const orgGuid = orgs.resources[0].guid; | ||
const spaces = await this.cfRequest(`/v3/spaces`, { names: space, organization_guids: orgGuid }); | ||
const spaces = await this.cfRequest('/v3/spaces', { names: space, organization_guids: orgGuid }); | ||
if (!spaces?.resources?.length) { | ||
throw new Error(`CF space ${bold(space)} not found in org ${bold(org)}!`); | ||
throw `CF space ${bold(space)} not found in org ${bold(org)}!`; | ||
} | ||
@@ -193,3 +195,7 @@ | ||
this.spaceInfo = Object.assign({}, target, { orgGuid, spaceGuid }); | ||
this.spaceInfo = { | ||
...target, | ||
orgGuid, | ||
spaceGuid | ||
} | ||
} | ||
@@ -240,3 +246,6 @@ | ||
case OPERATION_STATE_FAILED: | ||
throw new Error(`The returned service reported state '${OPERATION_STATE_FAILED}'.\n${JSON.stringify(serviceInstance, null, 4)}`); | ||
if (!DEBUG && serviceInstance?.last_operation?.description) { | ||
throw serviceInstance.last_operation.description; | ||
} | ||
throw `The returned service reported state '${OPERATION_STATE_FAILED}'.\n${JSON.stringify(serviceInstance, null, 4)}`; | ||
@@ -249,3 +258,3 @@ default: | ||
throw new Error(`Timeout occurred while getting service ${bold(serviceName)}`); | ||
throw `Timeout occurred while getting service ${bold(serviceName)}`; | ||
} | ||
@@ -274,3 +283,3 @@ | ||
if (!servicePlan?.resources?.length) { | ||
throw new Error(`No service plans found`); | ||
throw `No service plans found for ${planName} in service offering ${serviceOfferingName}.`; | ||
} | ||
@@ -302,3 +311,3 @@ | ||
if (postResult?.errors) { | ||
throw new Error(postResult.errors[0].detail); | ||
throw postResult.errors[0].detail; | ||
} | ||
@@ -311,3 +320,3 @@ | ||
throw new Error(`Could not create service ${bold(serviceName)}`); | ||
throw `Could not create service ${bold(serviceName)}`; | ||
} | ||
@@ -339,3 +348,6 @@ | ||
case OPERATION_STATE_FAILED: | ||
throw new Error(`The returned binding reported state '${OPERATION_STATE_FAILED}'.\n${JSON.stringify(binding, null, 4)}`); | ||
if (!DEBUG && binding?.last_operation?.description) { | ||
throw binding.last_operation.description; | ||
} | ||
throw `The returned binding reported state '${OPERATION_STATE_FAILED}'.\n${JSON.stringify(binding, null, 4)}`; | ||
@@ -348,3 +360,3 @@ default: | ||
throw new Error(`Timeout occurred while getting service key ${bold(serviceKeyName)}`); | ||
throw `Timeout occurred while getting service key ${bold(serviceKeyName)}`; | ||
} | ||
@@ -376,3 +388,3 @@ | ||
if (postResult?.errors) { | ||
throw new Error(postResult.errors[0].detail); | ||
throw postResult.errors[0].detail; | ||
} | ||
@@ -385,4 +397,4 @@ | ||
throw new Error(`Could not create service key ${bold(serviceKeyName)}`); | ||
throw `Could not create service key ${bold(serviceKeyName)}`; | ||
} | ||
} | ||
} |
{ | ||
"name": "@sap/cds-dk", | ||
"version": "7.9.3", | ||
"version": "7.9.4", | ||
"description": "Command line client and development toolkit for the SAP Cloud Application Programming Model", | ||
@@ -5,0 +5,0 @@ "homepage": "https://cap.cloud.sap/", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37397
1687018