public static Map<String, Object> getServiceKeyCredentials(CloudControllerClient client, String serviceName, String serviceKeyName) { List<ServiceKey> existingServiceKeys = client.getServiceKeys(serviceName); for (ServiceKey existingServiceKey : existingServiceKeys) { if (existingServiceKey.getName() .equals(serviceKeyName)) { return existingServiceKey.getCredentials(); } } throw new SLException(Messages.ERROR_RETRIEVING_REQUIRED_SERVICE_KEY_ELEMENT, serviceKeyName, serviceName); } }
public static Map<String, Object> getServiceKeyCredentials(CloudControllerClient client, String serviceName, String serviceKeyName) { List<ServiceKey> existingServiceKeys = client.getServiceKeys(serviceName); for (ServiceKey existingServiceKey : existingServiceKeys) { if (existingServiceKey.getName() .equals(serviceKeyName)) { return existingServiceKey.getCredentials(); } } throw new SLException(Messages.ERROR_RETRIEVING_REQUIRED_SERVICE_KEY_ELEMENT, serviceKeyName, serviceName); } }
private void deleteServiceKeys(CloudControllerClient client, String serviceName) { CloudService service = client.getService(serviceName); if (service.isUserProvided()) { return; } List<ServiceKey> serviceKeys = client.getServiceKeys(serviceName); for (ServiceKey serviceKey : serviceKeys) { getStepLogger().info(Messages.DELETING_SERVICE_KEY_FOR_SERVICE, serviceKey.getName(), serviceName); client.deleteServiceKey(serviceName, serviceKey.getName()); } }
private void deleteServiceKeys(CloudControllerClient client, String serviceName) { CloudService service = client.getService(serviceName); if (service.isUserProvided()) { return; } List<ServiceKey> serviceKeys = client.getServiceKeys(serviceName); for (ServiceKey serviceKey : serviceKeys) { getStepLogger().info(Messages.DELETING_SERVICE_KEY_FOR_SERVICE, serviceKey.getName(), serviceName); client.deleteServiceKey(serviceName, serviceKey.getName()); } }
private MethodExecution<String> createOrUpdateServiceKeys(CloudServiceExtended service, DelegateExecution execution, CloudControllerClient client) { MethodExecution<String> methodExecution = new MethodExecution<String>(null, ExecutionState.FINISHED); Map<String, List<ServiceKey>> serviceKeysMap = StepsUtil.getServiceKeysToCreate(execution); List<ServiceKey> serviceKeys = serviceKeysMap.get(service.getName()); List<ServiceKey> existingServiceKeys = serviceOperationExecutor.executeServiceOperation(service, (Supplier<List<ServiceKey>>) () -> client.getServiceKeys(service.getName()), getStepLogger()); if (existingServiceKeys == null) { return methodExecution; } List<ServiceKey> serviceKeysToCreate = getServiceKeysToCreate(serviceKeys, existingServiceKeys); List<ServiceKey> serviceKeysToUpdate = getServiceKeysToUpdate(serviceKeys, existingServiceKeys); List<ServiceKey> serviceKeysToDelete = getServiceKeysToDelete(serviceKeys, existingServiceKeys); if (canDeleteServiceKeys(execution)) { deleteServiceKeys(client, serviceKeysToDelete); // Recreate the service keys, which should be updated, as direct update is not supported // by the controller: deleteServiceKeys(client, serviceKeysToUpdate); createServiceKeys(client, serviceKeysToUpdate); } else { serviceKeysToDelete.forEach(key -> getStepLogger().warn(Messages.WILL_NOT_DELETE_SERVICE_KEY, key.getName(), key.getService() .getName())); serviceKeysToUpdate.forEach(key -> getStepLogger().warn(Messages.WILL_NOT_UPDATE_SERVICE_KEY, key.getName(), key.getService() .getName())); } createServiceKeys(client, serviceKeysToCreate); return methodExecution; }
private MethodExecution<String> createOrUpdateServiceKeys(CloudServiceExtended service, DelegateExecution execution, CloudControllerClient client) { MethodExecution<String> methodExecution = new MethodExecution<String>(null, ExecutionState.FINISHED); Map<String, List<ServiceKey>> serviceKeysMap = StepsUtil.getServiceKeysToCreate(execution); List<ServiceKey> serviceKeys = serviceKeysMap.get(service.getName()); List<ServiceKey> existingServiceKeys = serviceOperationExecutor.executeServiceOperation(service, (Supplier<List<ServiceKey>>) () -> client.getServiceKeys(service.getName()), getStepLogger()); if (existingServiceKeys == null) { return methodExecution; } List<ServiceKey> serviceKeysToCreate = getServiceKeysToCreate(serviceKeys, existingServiceKeys); List<ServiceKey> serviceKeysToUpdate = getServiceKeysToUpdate(serviceKeys, existingServiceKeys); List<ServiceKey> serviceKeysToDelete = getServiceKeysToDelete(serviceKeys, existingServiceKeys); if (canDeleteServiceKeys(execution)) { deleteServiceKeys(client, serviceKeysToDelete); // Recreate the service keys, which should be updated, as direct update is not supported // by the controller: deleteServiceKeys(client, serviceKeysToUpdate); createServiceKeys(client, serviceKeysToUpdate); } else { serviceKeysToDelete.forEach(key -> getStepLogger().warn(Messages.WILL_NOT_DELETE_SERVICE_KEY, key.getName(), key.getService() .getName())); serviceKeysToUpdate.forEach(key -> getStepLogger().warn(Messages.WILL_NOT_UPDATE_SERVICE_KEY, key.getName(), key.getService() .getName())); } createServiceKeys(client, serviceKeysToCreate); return methodExecution; }