Search in sources :

Example 1 with AzureEnvironment

use of com.microsoft.azure.AzureEnvironment in project azure-sdk-for-java by Azure.

the class CertificateCredentialImpl method exportAuthFile.

void exportAuthFile(ServicePrincipalImpl servicePrincipal) {
    if (authFile == null) {
        return;
    }
    RestClient restClient = servicePrincipal.manager().roleInner().restClient();
    AzureEnvironment environment = null;
    if (restClient.credentials() instanceof AzureTokenCredentials) {
        environment = ((AzureTokenCredentials) restClient.credentials()).environment();
    } else {
        String baseUrl = restClient.retrofit().baseUrl().toString();
        for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) {
            if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) {
                environment = env;
            }
        }
        if (environment == null) {
            throw new IllegalArgumentException("Unknown resource manager endpoint " + baseUrl);
        }
    }
    StringBuilder builder = new StringBuilder();
    builder.append(String.format("client=%s", servicePrincipal.applicationId())).append("\n");
    builder.append(String.format("certificate=%s", privateKeyPath)).append("\n");
    builder.append(String.format("certificatePassword=%s", privateKeyPassword)).append("\n");
    builder.append(String.format("tenant=%s", servicePrincipal.manager().tenantId())).append("\n");
    builder.append(String.format("subscription=%s", servicePrincipal.assignedSubscription)).append("\n");
    builder.append(String.format("authURL=%s", normalizeAuthFileUrl(environment.activeDirectoryEndpoint()))).append("\n");
    builder.append(String.format("baseURL=%s", normalizeAuthFileUrl(environment.resourceManagerEndpoint()))).append("\n");
    builder.append(String.format("graphURL=%s", normalizeAuthFileUrl(environment.graphEndpoint()))).append("\n");
    builder.append(String.format("managementURI=%s", normalizeAuthFileUrl(environment.managementEndpoint())));
    try {
        authFile.write(builder.toString().getBytes());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : AzureEnvironment(com.microsoft.azure.AzureEnvironment) RestClient(com.microsoft.rest.RestClient) IOException(java.io.IOException) AzureTokenCredentials(com.microsoft.azure.credentials.AzureTokenCredentials)

Example 2 with AzureEnvironment

use of com.microsoft.azure.AzureEnvironment in project azure-sdk-for-java by Azure.

the class PasswordCredentialImpl method exportAuthFile.

void exportAuthFile(ServicePrincipalImpl servicePrincipal) {
    if (authFile == null) {
        return;
    }
    RestClient restClient = servicePrincipal.manager().roleInner().restClient();
    AzureEnvironment environment = null;
    if (restClient.credentials() instanceof AzureTokenCredentials) {
        environment = ((AzureTokenCredentials) restClient.credentials()).environment();
    } else {
        String baseUrl = restClient.retrofit().baseUrl().toString();
        for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) {
            if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) {
                environment = env;
            }
        }
        if (environment == null) {
            throw new IllegalArgumentException("Unknown resource manager endpoint " + baseUrl);
        }
    }
    StringBuilder builder = new StringBuilder();
    builder.append(String.format("client=%s", servicePrincipal.applicationId())).append("\n");
    builder.append(String.format("key=%s", value())).append("\n");
    builder.append(String.format("tenant=%s", servicePrincipal.manager().tenantId())).append("\n");
    builder.append(String.format("subscription=%s", servicePrincipal.assignedSubscription)).append("\n");
    builder.append(String.format("authURL=%s", normalizeAuthFileUrl(environment.activeDirectoryEndpoint()))).append("\n");
    builder.append(String.format("baseURL=%s", normalizeAuthFileUrl(environment.resourceManagerEndpoint()))).append("\n");
    builder.append(String.format("graphURL=%s", normalizeAuthFileUrl(environment.graphEndpoint()))).append("\n");
    builder.append(String.format("managementURI=%s", normalizeAuthFileUrl(environment.managementEndpoint())));
    try {
        authFile.write(builder.toString().getBytes());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : AzureEnvironment(com.microsoft.azure.AzureEnvironment) RestClient(com.microsoft.rest.RestClient) IOException(java.io.IOException) AzureTokenCredentials(com.microsoft.azure.credentials.AzureTokenCredentials)

Aggregations

AzureEnvironment (com.microsoft.azure.AzureEnvironment)2 AzureTokenCredentials (com.microsoft.azure.credentials.AzureTokenCredentials)2 RestClient (com.microsoft.rest.RestClient)2 IOException (java.io.IOException)2