Search in sources :

Example 1 with SecureKeyAlreadyExistsException

use of io.cdap.cdap.common.SecureKeyAlreadyExistsException in project cdap by caskdata.

the class SecureStoreClient method createKey.

/**
 * Creates a secure key
 *
 * @param secureKeyId {@link SecureKeyId} secure key name
 * @param keyCreateRequest {@link SecureKeyCreateRequest}
 * @throws IOException if a network error occurred
 * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server
 * @throws SecureKeyAlreadyExistsException if the secure key already exists
 * @throws NamespaceNotFoundException if namespace is not found
 */
public void createKey(SecureKeyId secureKeyId, SecureKeyCreateRequest keyCreateRequest) throws IOException, UnauthenticatedException, AlreadyExistsException, NamespaceNotFoundException, UnauthorizedException {
    URL url = config.resolveNamespacedURLV3(secureKeyId.getParent(), getSecureKeyPath(secureKeyId));
    HttpResponse response = restClient.execute(HttpMethod.PUT, url, GSON.toJson(keyCreateRequest), null, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_CONFLICT);
    if (response.getResponseCode() == HttpURLConnection.HTTP_CONFLICT) {
        throw new SecureKeyAlreadyExistsException(secureKeyId);
    }
    if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
        throw new NamespaceNotFoundException(secureKeyId.getParent());
    }
}
Also used : SecureKeyAlreadyExistsException(io.cdap.cdap.common.SecureKeyAlreadyExistsException) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) NamespaceNotFoundException(io.cdap.cdap.common.NamespaceNotFoundException)

Aggregations

NamespaceNotFoundException (io.cdap.cdap.common.NamespaceNotFoundException)1 SecureKeyAlreadyExistsException (io.cdap.cdap.common.SecureKeyAlreadyExistsException)1 HttpResponse (io.cdap.common.http.HttpResponse)1 URL (java.net.URL)1