public class ScpCfCloudPlatform extends Object implements CloudPlatform
Constructor and Description |
---|
ScpCfCloudPlatform() |
Modifier and Type | Method and Description |
---|---|
String |
getApplicationName()
Get the application name.
|
String |
getApplicationProcessId()
Get the process ID of the current application.
|
String |
getApplicationUrl()
Get the application url.
|
com.google.gson.JsonObject |
getConnectivityServiceCredentials()
Retrieves the connectivity service credentials.
|
List<com.google.gson.JsonObject> |
getConnectivityServiceCredentialsList()
Retrieves the service credentials for all bound connectivity service instances.
|
com.google.gson.JsonObject |
getDestinationServiceCredentials()
Retrieves the destination service credentials.
|
List<com.google.gson.JsonObject> |
getDestinationServiceCredentialsList()
Retrieves the service credentials for all bound destination service instances.
|
io.vavr.control.Option<String> |
getEnvironmentVariable(String name)
Retrieves the environment variable by its name.
|
HttpSecuritySettings |
getHttpSecuritySettings()
Returns the
HttpSecuritySettings of the CloudPlatform . |
static ScpCfCloudPlatform |
getInstanceOrThrow()
Be aware that this method is Beta (as indicated by the annotation) and therefore subject to breaking changes.
|
com.google.gson.JsonObject |
getServiceCredentials(String serviceName)
Retrieves the credentials of a service.
|
com.google.gson.JsonObject |
getServiceCredentials(String serviceName,
String servicePlan)
Retrieves the credentials of a service.
|
Map<String,com.google.gson.JsonElement> |
getVcapApplication()
Provides access to the "VCAP_APPLICATION" environment variable.
|
Map<String,com.google.gson.JsonArray> |
getVcapServices()
Provides access to the "VCAP_SERVICES" environment variable.
|
String |
getXsAppName()
Retrieves the "xsappname" from the XSUAA service instance credentials.
|
com.google.gson.JsonObject |
getXsuaaServiceCredentials()
Retrieves the XSUAA service credentials.
|
com.google.gson.JsonObject |
getXsuaaServiceCredentials(com.auth0.jwt.interfaces.DecodedJWT jwt)
Retrieves the service credentials for all bound XSUAA service instances based on the given JSON Web Token and the
service plans of each instance.
|
com.google.gson.JsonObject |
getXsuaaServiceCredentials(String servicePlan)
Retrieves the XSUAA service credentials.
|
List<com.google.gson.JsonObject> |
getXsuaaServiceCredentialsList()
Retrieves the service credentials for all bound XSUAA service instances.
|
static void |
invalidateCaches()
Invalidates all internal caches holding the parsed VCAP_APPLICATION and VCAP_SERVICES environment variables.
|
void |
setEnvironmentVariableReader(Function<String,String> environmentVariableReader)
Set a custom function to read environment variables with.
|
public static void invalidateCaches()
Caution:This method is not thread-safe!
@Beta @Nonnull public static ScpCfCloudPlatform getInstanceOrThrow() throws CloudPlatformException
CloudPlatformException
- If not executed on the Cloud Foundry (CF) version of SAP Cloud Platform.@Nonnull public io.vavr.control.Option<String> getEnvironmentVariable(@Nonnull String name)
name
- The name of the environment variable.@Nonnull public Map<String,com.google.gson.JsonElement> getVcapApplication() throws CloudPlatformException
JsonElement
entries in "VCAP_APPLICATION" by their names.CloudPlatformException
- If there is an issue accessing the environment variable.@Nonnull public Map<String,com.google.gson.JsonArray> getVcapServices() throws CloudPlatformException
JsonArray
entries in "VCAP_SERVICES" by their names.CloudPlatformException
- If there is an issue accessing the environment variable.@Nonnull public String getApplicationName() throws CloudPlatformException
getApplicationName
in interface CloudPlatform
CloudPlatformException
- If there is an error accessing the application name.@Nonnull public String getApplicationProcessId() throws CloudPlatformException
getApplicationProcessId
in interface CloudPlatform
CloudPlatformException
- If there is an error accessing the process ID.@Nonnull @Beta public HttpSecuritySettings getHttpSecuritySettings()
CloudPlatform
HttpSecuritySettings
of the CloudPlatform
.getHttpSecuritySettings
in interface CloudPlatform
HttpSecuritySettings
@Nonnull public String getApplicationUrl() throws CloudPlatformException
getApplicationUrl
in interface CloudPlatform
CloudPlatformException
- If there is an error accessing the application url.@Nonnull public String getXsAppName() throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
CloudPlatformException
- If there is an issue accessing XS application name.NoServiceBindingException
- If there is no binding to the XSUAA service.MultipleServiceBindingsException
- If there are multiple bindings to the XSUAA service.@Nonnull public com.google.gson.JsonObject getServiceCredentials(@Nonnull String serviceName) throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
serviceName
- The name of the service.JsonObject
for the service credentials.CloudPlatformException
- If there is an issue accessing the service credentials.NoServiceBindingException
- If there is no binding to the requested service.MultipleServiceBindingsException
- If there are multiple bindings to the requested service.@Nonnull public com.google.gson.JsonObject getServiceCredentials(@Nonnull String serviceName, @Nullable String servicePlan) throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
serviceName
- The name of the service.servicePlan
- The plan of the service (optional). If null
, the service plan is ignored when retrieving the
service credentials, i.e., only one binding must exist to the service.JsonObject
for the service credentials.CloudPlatformException
- If there is an issue accessing the service credentials.NoServiceBindingException
- If there is no binding to the requested service.MultipleServiceBindingsException
- If there are multiple bindings to the requested service.@Nonnull public com.google.gson.JsonObject getXsuaaServiceCredentials() throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
JsonObject
for the XSUAA service credentials.CloudPlatformException
- If there is an issue accessing the service credentials.NoServiceBindingException
- If there is no binding to the XSUAA service.MultipleServiceBindingsException
- If there are multiple bindings to the XSUAA service.@Nonnull public com.google.gson.JsonObject getXsuaaServiceCredentials(@Nonnull String servicePlan) throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
servicePlan
- The plan of the service (optional). If null
, the service plan is ignored when retrieving the
service credentials, i.e., only one binding must exist to the service.JsonObject
for the XSUAA credentials.CloudPlatformException
- If there is an issue accessing the service credentials.NoServiceBindingException
- If there is no binding to the XSUAA service.MultipleServiceBindingsException
- If there are multiple bindings to the XSUAA service.@Nonnull public List<com.google.gson.JsonObject> getXsuaaServiceCredentialsList() throws CloudPlatformException
JsonObject
containing the credentials for all bound XSUAA service instances.CloudPlatformException
- If there is an issue accessing the service credentials.@Nonnull public com.google.gson.JsonObject getXsuaaServiceCredentials(@Nonnull com.auth0.jwt.interfaces.DecodedJWT jwt) throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
Retrieves the service credentials for all bound XSUAA service instances based on the given JSON Web Token and the service plans of each instance.
First the xsuaa instances are matched against the client ID and audiences of the JWT token. Then the service plan
is checked on the matching instances. If a unified broker instance is found among the filtered instances
(plan = "broker"
) then it is selected and returned, even if there are other bound xsuaa instances. This
is done to accommodate the recommended migration towards a unified broker instance, where other instances of
other plans (e.g. application
) may still exist.
This method does not make assumptions about the number of bound service instances. However, only one instance of
plan broker
and/or one instance of another plan is permitted.
jwt
- The JWT for which to return the matching XSUAA service instance credentials.JsonObject
for the XSUAA service credentials.CloudPlatformException
- If there is an issue accessing the service credentials.NoServiceBindingException
- If there is no matching binding to a XSUAA service instance.MultipleServiceBindingsException
- If there are multiple bindings to matching XSUAA service instances.@Nonnull public com.google.gson.JsonObject getDestinationServiceCredentials() throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
JsonObject
for the destination service credentials.CloudPlatformException
- If there is an issue accessing the service credentials.NoServiceBindingException
- If there is no binding to the destination service.MultipleServiceBindingsException
- If there are multiple bindings to the destination service.@Nonnull public List<com.google.gson.JsonObject> getDestinationServiceCredentialsList() throws CloudPlatformException
JsonObject
containing the credentials for all bound destination service instances.CloudPlatformException
- If there is an issue accessing the service credentials.@Nonnull public com.google.gson.JsonObject getConnectivityServiceCredentials() throws CloudPlatformException, NoServiceBindingException, MultipleServiceBindingsException
JsonObject
for the connectivity service credentials.CloudPlatformException
- If there is an issue accessing the service credentials.NoServiceBindingException
- If there is no binding to the connectivity service.MultipleServiceBindingsException
- If there are multiple bindings to the connectivity service.@Nonnull public List<com.google.gson.JsonObject> getConnectivityServiceCredentialsList() throws CloudPlatformException
JsonObject
containing the credentials for all bound connectivity service instances.CloudPlatformException
- If there is an issue accessing the service credentials.public void setEnvironmentVariableReader(@Nonnull Function<String,String> environmentVariableReader)
CloudPlatform
setEnvironmentVariableReader
in interface CloudPlatform
environmentVariableReader
- A generic key-value mapping.Copyright © 2021 SAP SE. All rights reserved.