static ServiceAccount getInstance(String url, String instanceId,
            String userId, String password, String apiKey,
            String iamBearerToken, String iamEndpoint) {
        if(url == null || instanceId == null) {
            logger.config(
                    "Not enough environment variables to initialize an instance of ServiceAccount with either Globalization Pipeline Authentication or IAM Authorization. Globalization Pipeline URL and instance id are required.");
            return null;
        }
        if (userId == null || password == null) {
            logger.config("Not enough environment variables to initialize an instance of ServiceAccount supporting Globalization Pipeline Authentication.");
        }
        else {
            ServiceAccount account = getInstance(url, instanceId, userId, password);
            logger.config("A ServiceAccount is created from environment variables: GP_URL="
                    + url + ", GP_INSTANCE_ID=" + instanceId + ", GP_USER_ID=" +
                    userId + ", GP_PASSWORD=***");

            return account;
        }
        if(iamEndpoint==null||iamEndpoint.isEmpty()) {
            logger.config("Not enough environment variables to initialize an instance of ServiceAccount supporting IAM Authorization. IAM endpoint is either not set or blank.");
            return null;
        }
        if (apiKey==null||apiKey.isEmpty()) {
            logger.config("Not enough environment variables to initialize an instance of ServiceAccount supporting IAM Authorization using IAM API Key.");
        }
        else {
            ServiceAccount account = getInstance(url, instanceId, TokenManagerFactory.getTokenLifeCycleManager(iamEndpoint, apiKey));
            logger.config("A ServiceAccount is created from environment variables: GP_URL="
                    + url + ", GP_INSTANCE_ID=" + instanceId + ", GP_IAM_API_KEY=***");

            return account;
        }
        
        if (iamBearerToken==null||iamBearerToken.isEmpty()) {
            logger.config("Not enough environment variables to initialize an instance of ServiceAccount supporting IAM Authorization using IAM bearer token.");
            return null;
        }
        else {
            ServiceAccount account = getInstance(url, instanceId, TokenManagerFactory.getTokenManager(iamBearerToken));
            logger.config("A ServiceAccount is created from environment variables: GP_URL="
                    + url + ", GP_INSTANCE_ID=" +instanceId+ ", GP_IAM_BEARER_TOKEN=***");
            return account;
        }
    }
static ServiceAccount getInstance ( String url , String instanceId , String userId , String password , String apiKey , String iamBearerToken , String iamEndpoint ) { if ( url == null || instanceId == null ) { logger . config ( "Not enough environment variables to initialize an instance of ServiceAccount with either Globalization Pipeline Authentication or IAM Authorization. Globalization Pipeline URL and instance id are required." ) ; return null ; } if ( userId == null || password == null ) { logger . config ( "Not enough environment variables to initialize an instance of ServiceAccount supporting Globalization Pipeline Authentication." ) ; } else { ServiceAccount account = getInstance ( url , instanceId , userId , password ) ; logger . config ( "A ServiceAccount is created from environment variables: GP_URL=" + url + ", GP_INSTANCE_ID=" + instanceId + ", GP_USER_ID=" + userId + ", GP_PASSWORD=***" ) ; return account ; } if ( iamEndpoint == null || iamEndpoint . isEmpty ( ) ) { logger . config ( "Not enough environment variables to initialize an instance of ServiceAccount supporting IAM Authorization. IAM endpoint is either not set or blank." ) ; return null ; } if ( apiKey == null || apiKey . isEmpty ( ) ) { logger . config ( "Not enough environment variables to initialize an instance of ServiceAccount supporting IAM Authorization using IAM API Key." ) ; } else { ServiceAccount account = getInstance ( url , instanceId , TokenManagerFactory . getTokenLifeCycleManager ( iamEndpoint , apiKey ) ) ; logger . config ( "A ServiceAccount is created from environment variables: GP_URL=" + url + ", GP_INSTANCE_ID=" + instanceId + ", GP_IAM_API_KEY=***" ) ; return account ; } if ( iamBearerToken == null || iamBearerToken . isEmpty ( ) ) { logger . config ( "Not enough environment variables to initialize an instance of ServiceAccount supporting IAM Authorization using IAM bearer token." ) ; return null ; } else { ServiceAccount account = getInstance ( url , instanceId , TokenManagerFactory . getTokenManager ( iamBearerToken ) ) ; logger . config ( "A ServiceAccount is created from environment variables: GP_URL=" + url + ", GP_INSTANCE_ID=" + instanceId + ", GP_IAM_BEARER_TOKEN=***" ) ; return account ; } }
@param url
The service URL of Globlization Pipeline service.
(e.g. https://gp-rest.ng.bluemix.net/translate/rest)
@param instanceId
The instance ID of the service instance.
(e.g. d3f537cd617f34c86ac6b270f3065e73)
@param userId
The user ID for the service instance.
(e.g. e92a1282a0e4f97bec93aa9f56fdb838)
@param password
The password for the service instance.
(e.g. zg5SlD+ftXYRIZDblLgEA/ILkkCNqE1y)
@param iamEndpoint
IAM endpoint.
@param iamBearerToken
IAM Bearer token.
@param apiKey
IAM API Key.
@return An instance of ServiceAccount, or null if essential params are not available.