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

com.sap.cloud.alert.notification.client.model.DestinationServiceBinding Maven / Gradle / Ivy

Go to download

Means for out-of-the-box events management in SAP Alert Notification service for SAP BTP service.

There is a newer version: 1.11.0
Show newest version
package com.sap.cloud.alert.notification.client.model;

import io.pivotal.cfenv.core.CfCredentials;
import io.pivotal.cfenv.core.CfEnv;

import java.net.URI;

import static java.net.URI.create;

public class DestinationServiceBinding {

    private static final String URL = "uri";
    private static final String OAUTH_URL = "url";
    private static final String CLIENT_ID = "clientid";
    private static final String CLIENT_SECRET = "clientsecret";
    private static final String DESTINATION_SERVICE_LABEL = "destination";
    private static final String OAUTH_TOKEN_URL_SUFFIX = "/oauth/token?grant_type=client_credentials";

    private final URI serviceUri;
    private final URI oauthUri;
    private final String clientId;
    private final String clientSecret;

    public DestinationServiceBinding() {
        this(new CfEnv().findCredentialsByLabel(DESTINATION_SERVICE_LABEL));
    }

    protected DestinationServiceBinding(CfCredentials credentials) {
        this(create(credentials.getString(URL)), //
                create(credentials.getString(OAUTH_URL).endsWith(OAUTH_TOKEN_URL_SUFFIX) ? credentials.getString(OAUTH_URL) : credentials.getString(OAUTH_URL).concat(OAUTH_TOKEN_URL_SUFFIX)), //
                credentials.getString(CLIENT_ID), //
                credentials.getString(CLIENT_SECRET) //
        );
    }

    public DestinationServiceBinding(URI serviceUri, URI oauthUri, String clientId, String clientSecret) {
        this.serviceUri = serviceUri;
        this.oauthUri = oauthUri;
        this.clientId = clientId;
        this.clientSecret = clientSecret;
    }

    public URI getServiceUri() {
        return serviceUri;
    }

    public URI getOauthUri() {
        return oauthUri;
    }

    public String getClientId() {
        return clientId;
    }

    public String getClientSecret() {
        return clientSecret;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy