Search in sources :

Example 86 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project azure-sdk-for-java by Azure.

the class KeyVaultCredentials method applyCredentialsFilter.

@Override
public void applyCredentialsFilter(OkHttpClient.Builder clientBuilder) {
    clientBuilder.addInterceptor(new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            HttpUrl url = chain.request().url();
            Map<String, String> challengeMap = cache.getCachedChallenge(url);
            if (challengeMap != null) {
                // Get the bearer token
                String credential = getAuthenticationCredentials(challengeMap);
                Request newRequest = chain.request().newBuilder().header(AUTHENTICATE, BEARER_TOKEP_REFIX + credential).build();
                return chain.proceed(newRequest);
            } else {
                // response
                return chain.proceed(chain.request());
            }
        }
    });
    // Caches the challenge for failed request and re-send the request with
    // access token.
    clientBuilder.authenticator(new Authenticator() {

        @Override
        public Request authenticate(Route route, Response response) throws IOException {
            // if challenge is not cached then extract and cache it
            String authenticateHeader = response.header(WWW_AUTHENTICATE);
            Map<String, String> challengeMap = extractChallenge(authenticateHeader, BEARER_TOKEP_REFIX);
            // Cache the challenge
            cache.addCachedChallenge(response.request().url(), challengeMap);
            // Get the bearer token from the callback by providing the
            // challenges
            String credential = getAuthenticationCredentials(challengeMap);
            if (credential == null) {
                return null;
            }
            // be cached anywhere in our code.
            return response.request().newBuilder().header(AUTHENTICATE, BEARER_TOKEP_REFIX + credential).build();
        }
    });
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) IOException(java.io.IOException) Interceptor(okhttp3.Interceptor) Map(java.util.Map) HashMap(java.util.HashMap) HttpUrl(okhttp3.HttpUrl) Authenticator(okhttp3.Authenticator) Route(okhttp3.Route)

Example 87 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method updateCertificateIssuerWithServiceResponseAsync.

/**
     * Updates the specified certificate issuer.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param issuerName The name of the issuer.
     * @return the observable to the IssuerBundle object
     */
public Observable<ServiceResponse<IssuerBundle>> updateCertificateIssuerWithServiceResponseAsync(String vaultBaseUrl, String issuerName) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (issuerName == null) {
        throw new IllegalArgumentException("Parameter issuerName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    final String provider = null;
    final IssuerCredentials credentials = null;
    final OrganizationDetails organizationDetails = null;
    final IssuerAttributes attributes = null;
    CertificateIssuerUpdateParameters parameter = new CertificateIssuerUpdateParameters();
    parameter.withProvider(null);
    parameter.withCredentials(null);
    parameter.withOrganizationDetails(null);
    parameter.withAttributes(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.updateCertificateIssuer(issuerName, this.apiVersion(), this.acceptLanguage(), parameter, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<IssuerBundle>>>() {

        @Override
        public Observable<ServiceResponse<IssuerBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<IssuerBundle> clientResponse = updateCertificateIssuerDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : OrganizationDetails(com.microsoft.azure.keyvault.models.OrganizationDetails) IssuerAttributes(com.microsoft.azure.keyvault.models.IssuerAttributes) CertificateIssuerUpdateParameters(com.microsoft.azure.keyvault.models.CertificateIssuerUpdateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) IssuerBundle(com.microsoft.azure.keyvault.models.IssuerBundle) ServiceResponse(com.microsoft.rest.ServiceResponse) IssuerCredentials(com.microsoft.azure.keyvault.models.IssuerCredentials)

Example 88 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project azure-sdk-for-java by Azure.

the class KeyVaultClientImpl method setSecretWithServiceResponseAsync.

/**
     * Sets a secret in a specified key vault.
     *
     * @param vaultBaseUrl The vault name, for example https://myvault.vault.azure.net.
     * @param secretName The name of the secret.
     * @param value The value of the secret.
     * @return the observable to the SecretBundle object
     */
public Observable<ServiceResponse<SecretBundle>> setSecretWithServiceResponseAsync(String vaultBaseUrl, String secretName, String value) {
    if (vaultBaseUrl == null) {
        throw new IllegalArgumentException("Parameter vaultBaseUrl is required and cannot be null.");
    }
    if (secretName == null) {
        throw new IllegalArgumentException("Parameter secretName is required and cannot be null.");
    }
    if (this.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.apiVersion() is required and cannot be null.");
    }
    if (value == null) {
        throw new IllegalArgumentException("Parameter value is required and cannot be null.");
    }
    final Map<String, String> tags = null;
    final String contentType = null;
    final SecretAttributes secretAttributes = null;
    SecretSetParameters parameters = new SecretSetParameters();
    parameters.withValue(value);
    parameters.withTags(null);
    parameters.withContentType(null);
    parameters.withSecretAttributes(null);
    String parameterizedHost = Joiner.on(", ").join("{vaultBaseUrl}", vaultBaseUrl);
    return service.setSecret(secretName, this.apiVersion(), this.acceptLanguage(), parameters, parameterizedHost, this.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<SecretBundle>>>() {

        @Override
        public Observable<ServiceResponse<SecretBundle>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<SecretBundle> clientResponse = setSecretDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : SecretSetParameters(com.microsoft.azure.keyvault.models.SecretSetParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody) Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) SecretBundle(com.microsoft.azure.keyvault.models.SecretBundle) ServiceResponse(com.microsoft.rest.ServiceResponse) SecretAttributes(com.microsoft.azure.keyvault.models.SecretAttributes)

Example 89 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project azure-sdk-for-java by Azure.

the class RoleAssignmentsInner method createByIdWithServiceResponseAsync.

/**
     * Creates a role assignment by ID.
     *
     * @param roleAssignmentId The ID of the role assignment to create.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the RoleAssignmentInner object
     */
public Observable<ServiceResponse<RoleAssignmentInner>> createByIdWithServiceResponseAsync(String roleAssignmentId) {
    if (roleAssignmentId == null) {
        throw new IllegalArgumentException("Parameter roleAssignmentId is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    final RoleAssignmentPropertiesInner properties = null;
    RoleAssignmentCreateParameters parameters = new RoleAssignmentCreateParameters();
    parameters.withProperties(null);
    return service.createById(roleAssignmentId, this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<RoleAssignmentInner>>>() {

        @Override
        public Observable<ServiceResponse<RoleAssignmentInner>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<RoleAssignmentInner> clientResponse = createByIdDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) RoleAssignmentCreateParameters(com.microsoft.azure.management.graphrbac.RoleAssignmentCreateParameters) Observable(rx.Observable) ResponseBody(okhttp3.ResponseBody)

Example 90 with Response

use of com.yahoo.vespa.clustercontroller.core.restapiv2.Response in project azure-sdk-for-java by Azure.

the class ServicePrincipalsInner method updatePasswordCredentialsWithServiceResponseAsync.

/**
     * Updates the passwordCredentials associated with a service principal.
     *
     * @param objectId The object ID of the service principal.
     * @param value A collection of PasswordCredentials.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceResponse} object if successful.
     */
public Observable<ServiceResponse<Void>> updatePasswordCredentialsWithServiceResponseAsync(String objectId, List<PasswordCredentialInner> value) {
    if (objectId == null) {
        throw new IllegalArgumentException("Parameter objectId is required and cannot be null.");
    }
    if (this.client.tenantID() == null) {
        throw new IllegalArgumentException("Parameter this.client.tenantID() is required and cannot be null.");
    }
    if (this.client.apiVersion() == null) {
        throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
    }
    if (value == null) {
        throw new IllegalArgumentException("Parameter value is required and cannot be null.");
    }
    Validator.validate(value);
    PasswordCredentialsUpdateParameters parameters = new PasswordCredentialsUpdateParameters();
    parameters.withValue(value);
    return service.updatePasswordCredentials(objectId, this.client.tenantID(), this.client.apiVersion(), this.client.acceptLanguage(), parameters, this.client.userAgent()).flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {

        @Override
        public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {
            try {
                ServiceResponse<Void> clientResponse = updatePasswordCredentialsDelegate(response);
                return Observable.just(clientResponse);
            } catch (Throwable t) {
                return Observable.error(t);
            }
        }
    });
}
Also used : Response(retrofit2.Response) ServiceResponse(com.microsoft.rest.ServiceResponse) ServiceResponse(com.microsoft.rest.ServiceResponse) Observable(rx.Observable) PasswordCredentialsUpdateParameters(com.microsoft.azure.management.graphrbac.PasswordCredentialsUpdateParameters) ResponseBody(okhttp3.ResponseBody)

Aggregations

Response (okhttp3.Response)1083 Request (okhttp3.Request)814 IOException (java.io.IOException)434 Test (org.junit.Test)330 Response (retrofit2.Response)319 Call (okhttp3.Call)236 ResponseBody (okhttp3.ResponseBody)208 OkHttpClient (okhttp3.OkHttpClient)192 ServiceResponse (com.microsoft.rest.ServiceResponse)179 RequestBody (okhttp3.RequestBody)128 Observable (rx.Observable)116 Callback (okhttp3.Callback)111 MockResponse (okhttp3.mockwebserver.MockResponse)93 List (java.util.List)89 HttpUrl (okhttp3.HttpUrl)81 LinkHeaders (com.instructure.canvasapi2.utils.LinkHeaders)72 TypeToken (com.google.common.reflect.TypeToken)71 ArrayList (java.util.ArrayList)71 File (java.io.File)70 JSONObject (org.json.JSONObject)65