utils.getExpectedResponse(res, robot, switchBoard, prompt, regex).then((response) => { selection = parseInt(response.match[1], 10); let app = appsBound[selection - 1]; let appName = app.name; let appGuid = app.guid; let message = i18n.__('service.unbind.in.progress'); robot.emit('ibmcloud.formatter', { response: res, message: message}); // Find the service bindings GUID for this service and app. robot.logger.info(`${TAG}: Asynch call using cf library to get service instance binding for instance ${serviceInstanceGuid}.`); cf.ServiceInstances.getInstanceBindings(serviceInstanceGuid).then((result) => { robot.logger.info(`${TAG}: Bindings results for instance ${serviceInstanceGuid} obtained.`); let bindings = result.resources; let binding = null; for (let i = 0; i < bindings.length; i++) { if (bindings[i].entity.app_guid === appGuid) { binding = bindings[i]; break; } } if (!binding) { robot.logger.error(`${TAG}: No service bindings exist.`); let message = i18n.__('service.bind.not.found'); robot.emit('ibmcloud.formatter', { response: res, message: message}); return; } // Now take action action of unbinding. robot.logger.info(`${TAG}: Asynch call using cf library to remove service instance binding for instance ${serviceInstanceGuid} and binding guid ${binding.metadata.guid}.`); cf.ServiceBindings.remove(binding.metadata.guid).then((result) => { robot.logger.info(`${TAG}: Successfully remove service binding ${appName} for instance ${serviceInstanceGuid}.`); let message = i18n.__('service.unbind.success', serviceInstanceName, appName); robot.emit('ibmcloud.formatter', { response: res, message: message}); activity.emitBotActivity(robot, res, { activity_id: 'activity.service.unbind', app_name: appName, app_guid: appGuid, space_name: activeSpace.name, space_guid: activeSpace.guid }); }); }); });
cf.Spaces.getSummary(spaceGuid).then((result) => { let summaryStr = ''; if (result) { summaryStr = JSON.stringify(result); } robot.logger.info(`${TAG}: cf library returned with summary ${summaryStr}.`); let services = result.services; let serviceInstanceGuid = null; // Iterate the list of services to find a match to the serviceName. for (let i = 0; i < services.length; i++) { if (serviceName === services[i].name) { serviceInstanceGuid = services[i].guid; break; } } // Verify GUID found. if (serviceInstanceGuid === null) { robot.logger.info(`${TAG}: ${serviceName} not found in ${activeSpace.name}.`); let message = i18n.__('service.instance.not.found', serviceName); robot.emit('ibmcloud.formatter', { response: res, message: message}); return; } // Finally remove the service instance, per the GUID. robot.logger.info(`${TAG}: Asynch call using cf library to remove service instance ${serviceInstanceGuid}.`); cf.ServiceInstances.remove(serviceInstanceGuid).then((result) => { robot.logger.info(`${TAG}: Successfully remove service instance ${serviceName} with guid ${serviceInstanceGuid}.`); let message = i18n.__('service.instance.remove.success', serviceName); robot.emit('ibmcloud.formatter', { response: res, message: message}); activity.emitBotActivity(robot, res, { activity_id: 'activity.service.remove', space_name: activeSpace.name, space_guid: activeSpace.guid }); }, (err) => { robot.logger.error(`${TAG}: Error removing service instance ${serviceName} with guid ${serviceInstanceGuid}.`); robot.logger.error(err.stack); let message = i18n.__('service.instance.remove.error', JSON.parse(err).description); robot.emit('ibmcloud.formatter', { response: res, message: message}); }); }, (err) => {