Search in sources :

Example 16 with Credentials

use of com.ibm.watson.discovery.v1.model.Credentials in project java-sdk by watson-developer-cloud.

the class Discovery method listCredentials.

/**
 * List credentials.
 *
 * <p>List all the source credentials that have been created for this service instance.
 *
 * <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
 *
 * @param listCredentialsOptions the {@link ListCredentialsOptions} containing the options for the
 *     call
 * @return a {@link ServiceCall} with a result of type {@link CredentialsList}
 */
public ServiceCall<CredentialsList> listCredentials(ListCredentialsOptions listCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(listCredentialsOptions, "listCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", listCredentialsOptions.environmentId());
    RequestBuilder builder = RequestBuilder.get(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "listCredentials");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    ResponseConverter<CredentialsList> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<CredentialsList>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) CredentialsList(com.ibm.watson.discovery.v1.model.CredentialsList) HashMap(java.util.HashMap)

Example 17 with Credentials

use of com.ibm.watson.discovery.v1.model.Credentials in project java-sdk by watson-developer-cloud.

the class Discovery method createCredentials.

/**
 * Create credentials.
 *
 * <p>Creates a set of credentials to connect to a remote source. Created credentials are used in
 * a configuration to associate a collection with the remote source.
 *
 * <p>**Note:** All credentials are sent over an encrypted connection and encrypted at rest.
 *
 * @param createCredentialsOptions the {@link CreateCredentialsOptions} containing the options for
 *     the call
 * @return a {@link ServiceCall} with a result of type {@link Credentials}
 */
public ServiceCall<Credentials> createCredentials(CreateCredentialsOptions createCredentialsOptions) {
    com.ibm.cloud.sdk.core.util.Validator.notNull(createCredentialsOptions, "createCredentialsOptions cannot be null");
    Map<String, String> pathParamsMap = new HashMap<String, String>();
    pathParamsMap.put("environment_id", createCredentialsOptions.environmentId());
    RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(getServiceUrl(), "/v1/environments/{environment_id}/credentials", pathParamsMap));
    Map<String, String> sdkHeaders = SdkCommon.getSdkHeaders("discovery", "v1", "createCredentials");
    for (Entry<String, String> header : sdkHeaders.entrySet()) {
        builder.header(header.getKey(), header.getValue());
    }
    builder.header("Accept", "application/json");
    builder.query("version", String.valueOf(this.version));
    final JsonObject contentJson = new JsonObject();
    if (createCredentialsOptions.sourceType() != null) {
        contentJson.addProperty("source_type", createCredentialsOptions.sourceType());
    }
    if (createCredentialsOptions.credentialDetails() != null) {
        contentJson.add("credential_details", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCredentialsOptions.credentialDetails()));
    }
    if (createCredentialsOptions.status() != null) {
        contentJson.add("status", com.ibm.cloud.sdk.core.util.GsonSingleton.getGson().toJsonTree(createCredentialsOptions.status()));
    }
    builder.bodyJson(contentJson);
    ResponseConverter<Credentials> responseConverter = ResponseConverterUtils.getValue(new com.google.gson.reflect.TypeToken<Credentials>() {
    }.getType());
    return createServiceCall(builder.build(), responseConverter);
}
Also used : RequestBuilder(com.ibm.cloud.sdk.core.http.RequestBuilder) HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Credentials(com.ibm.watson.discovery.v1.model.Credentials) DeleteCredentials(com.ibm.watson.discovery.v1.model.DeleteCredentials)

Aggregations

DeleteCredentials (com.ibm.watson.discovery.v1.model.DeleteCredentials)12 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)10 Credentials (com.ibm.watson.discovery.v1.model.Credentials)9 RequestBuilder (com.ibm.cloud.sdk.core.http.RequestBuilder)5 WatsonServiceUnitTest (com.ibm.watson.common.WatsonServiceUnitTest)5 HashMap (java.util.HashMap)5 MockResponse (okhttp3.mockwebserver.MockResponse)5 Test (org.testng.annotations.Test)5 CredentialDetails (com.ibm.watson.discovery.v1.model.CredentialDetails)4 CredentialsList (com.ibm.watson.discovery.v1.model.CredentialsList)3 JsonObject (com.google.gson.JsonObject)2 Credentials (com.haleconnect.api.user.v1.model.Credentials)2 CreateCredentialsOptions (com.ibm.watson.discovery.v1.model.CreateCredentialsOptions)2 DeleteCredentialsOptions (com.ibm.watson.discovery.v1.model.DeleteCredentialsOptions)2 GetCredentialsOptions (com.ibm.watson.discovery.v1.model.GetCredentialsOptions)2 ListCredentialsOptions (com.ibm.watson.discovery.v1.model.ListCredentialsOptions)2 StatusDetails (com.ibm.watson.discovery.v1.model.StatusDetails)2 UpdateCredentialsOptions (com.ibm.watson.discovery.v1.model.UpdateCredentialsOptions)2 ApiException (com.haleconnect.api.user.v1.ApiException)1 LoginApi (com.haleconnect.api.user.v1.api.LoginApi)1