All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sap.cloud.sdk.cloudplatform.connectivity.DefaultScpXfDestinationLoader Maven / Gradle / Ivy

Go to download

Implementation of the Cloud platform abstraction for general-purpose connectivity on the SAP Cloud Platform (Cloud Foundry).

The newest version!
/*
 * Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved.
 */

package com.sap.cloud.sdk.cloudplatform.connectivity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Nonnull;

import org.slf4j.Logger;

import com.google.common.annotations.Beta;
import com.google.gson.JsonObject;
import com.sap.cloud.sdk.cloudplatform.ScpCfServiceInfo;
import com.sap.cloud.sdk.cloudplatform.logging.CloudLoggerFactory;
import com.sap.cloud.sdk.cloudplatform.security.BasicCredentials;

/**
 * Encapsulated logic to retrieve destinations from the {@code VCAP_SERVICES} on SAP Cloud Platform Cloud Foundry
 * created by the ExtensionFactory.
 * 

* The least amount of information this logic needs in the {@code VCAP_SERVICES} looks as follows: * *

 * {@code
 * {
 *   "VCAP_SERVICES": {
 *     "s4-hana-cloud": [
 *       {
 *         "name": "",
 *         "plan": "",
 *         "credentials": {
 *           "User": "",
 *           "Authentication": "BasicAuthentication",
 *           "URL": "",
 *           "Password": ""
 *         }
 *         ...
 *       }
 *       ...
 *     ]
 *     ...
 *   }
 * }
 * }
 * 
* * The {@code plan} is used as the description of the created destination. */ @Beta public class DefaultScpXfDestinationLoader implements ScpXfDestinationLoader { private static final Logger logger = CloudLoggerFactory.getLogger(DefaultScpXfDestinationLoader.class); @Override @Nonnull public Map loadDestinations() { final Map result = new HashMap<>(); final List destinationJsons = ScpCfServiceInfo.createFor("s4-hana-cloud"); for( final ScpCfServiceInfo entryJson : destinationJsons ) { final JsonObject destinationJson = entryJson.getServiceInfoElem().getAsJsonObject(); final String destinationName = destinationJson.get("name").getAsString(); final String plan = destinationJson.get("plan").getAsString(); final JsonObject credentialsJson = destinationJson.get("credentials").getAsJsonObject(); final String authenticationType = credentialsJson.get("Authentication").getAsString(); // for now only BasicAuthentication is known to be used by Extension Factory if( !"BasicAuthentication".equals(authenticationType) ) { logger.error( "Encountered a destination '" + destinationName + "' with an unsupported authentication type '" + authenticationType + "'. Currently only '" + AuthenticationType.BASIC_AUTHENTICATION + "' is supported."); } else { final String user = credentialsJson.get("User").getAsString(); final String password = credentialsJson.get("Password").getAsString(); final String url = credentialsJson.get("URL").getAsString(); result.put( destinationName, new ScpXfDestination( destinationName, plan, url, AuthenticationType.BASIC_AUTHENTICATION, new BasicCredentials(user, password))); } } return result; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy