Search in sources :

Example 26 with ApplicationTokenCredentials

use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project cloudbreak by hortonworks.

the class AzureClient method connect.

private void connect() {
    AzureTokenCredentials creds = new ApplicationTokenCredentials(clientId, tenantId, secretKey, AzureEnvironment.AZURE).withDefaultSubscriptionId(subscriptionId);
    azure = Azure.configure().withProxyAuthenticator(new JavaNetAuthenticator()).withLogLevel(LogLevel.BASIC).authenticate(creds).withSubscription(subscriptionId);
}
Also used : ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) JavaNetAuthenticator(okhttp3.JavaNetAuthenticator) AzureTokenCredentials(com.microsoft.azure.credentials.AzureTokenCredentials)

Example 27 with ApplicationTokenCredentials

use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project cloudbreak by hortonworks.

the class AzureSetup method validateAdlsFileSystem.

private void validateAdlsFileSystem(CloudCredential credential, FileSystem fileSystem) {
    Map<String, Object> credentialAttributes = credential.getParameters();
    String clientSecret = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.CREDENTIAL_SECRET_KEY));
    String subscriptionId = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.SUBSCRIPTION_ID));
    String clientId = String.valueOf(credentialAttributes.get(AdlsFileSystemConfiguration.ACCESS_KEY));
    String tenantId = fileSystem.getStringParameter(AdlsFileSystemConfiguration.TENANT_ID);
    String accountName = fileSystem.getStringParameter(FileSystemConfiguration.ACCOUNT_NAME);
    ApplicationTokenCredentials creds = new ApplicationTokenCredentials(clientId, tenantId, clientSecret, AzureEnvironment.AZURE);
    DataLakeStoreAccountManagementClient adlsClient = new DataLakeStoreAccountManagementClientImpl(creds);
    adlsClient.withSubscriptionId(subscriptionId);
    List<DataLakeStoreAccount> dataLakeStoreAccounts = adlsClient.accounts().list();
    boolean validAccountname = false;
    for (DataLakeStoreAccount account : dataLakeStoreAccounts) {
        if (account.name().equalsIgnoreCase(accountName)) {
            validAccountname = true;
            break;
        }
    }
    if (!validAccountname) {
        throw new CloudConnectorException("The provided file system account name does not belong to a valid ADLS account");
    }
}
Also used : DataLakeStoreAccount(com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount) CloudConnectorException(com.sequenceiq.cloudbreak.cloud.exception.CloudConnectorException) DataLakeStoreAccountManagementClient(com.microsoft.azure.management.datalake.store.DataLakeStoreAccountManagementClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) DataLakeStoreAccountManagementClientImpl(com.microsoft.azure.management.datalake.store.implementation.DataLakeStoreAccountManagementClientImpl)

Aggregations

ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)27 File (java.io.File)9 Azure (com.microsoft.azure.management.Azure)8 RestClient (com.microsoft.rest.RestClient)7 Before (org.junit.Before)7 AzureResponseBuilder (com.microsoft.azure.AzureResponseBuilder)6 AzureJacksonAdapter (com.microsoft.azure.serializer.AzureJacksonAdapter)6 ResourcePoolState (com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState)5 AuthCredentialsServiceState (com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState)5 AzureEnvironment (com.microsoft.azure.AzureEnvironment)4 ComputeManagementClientImpl (com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl)4 IOException (java.io.IOException)4 NetworkManagementClientImpl (com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl)3 ResourceManagementClientImpl (com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl)3 Parameters (org.testng.annotations.Parameters)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Authenticated (com.microsoft.azure.management.Azure.Authenticated)2 DataLakeStoreAccountManagementClientImpl (com.microsoft.azure.management.datalake.store.implementation.DataLakeStoreAccountManagementClientImpl)2 DataLakeStoreAccount (com.microsoft.azure.management.datalake.store.models.DataLakeStoreAccount)2 NetworkRequest (com.sequenceiq.cloudbreak.api.model.NetworkRequest)2