Search in sources :

Example 21 with ApplicationTokenCredentials

use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-gradle-plugins by lenala.

the class AzureAuthHelper method getAuthObjFromConfiguration.

/**
 * Get Authenticated object by reading app token credentials from gradle.properties
 *
 * @return Authenticated object if configurations are correct; otherwise return null.
 */
private Authenticated getAuthObjFromConfiguration(final AuthConfiguration config) {
    final ApplicationTokenCredentials credential = getAppTokenCredentials();
    if (credential == null) {
        return null;
    }
    final Authenticated auth = azureConfigure().authenticate(credential);
    if (auth != null) {
        logger.quiet(AUTH_WITH_CLIENT_ID + config.getAuthenticationSetting(CLIENT_ID));
    }
    return auth;
}
Also used : Authenticated(com.microsoft.azure.management.Azure.Authenticated) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials)

Example 22 with ApplicationTokenCredentials

use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-tools-for-java by Microsoft.

the class IntegrationTestBase method setUpStep.

public void setUpStep() throws Exception {
    if (currentTestName == null) {
        currentTestName = name.getMethodName();
    } else {
        throw new Exception("Setting up another test in middle of a test");
    }
    addTextReplacementRule(GLOBAL_ENDPOINT, MOCK_URI + "/");
    ApplicationTokenCredentials credentials = new TestCredentials();
    String defaultSubscription = "";
    if (IS_MOCKED) {
        defaultSubscription = MOCK_SUBSCRIPTION;
        File recordFile = getRecordFile();
        ObjectMapper mapper = new ObjectMapper();
        try {
            testRecord = mapper.readValue(recordFile, TestRecord.class);
        } catch (Exception e) {
            throw new Exception("Fail read test record: " + e.getMessage());
        }
    } else {
        try {
            credentials = ApplicationTokenCredentials.fromFile(new File(azureAuthFile));
        } catch (Exception e) {
            throw new Exception("Fail to open auth file:" + azureAuthFile);
        }
        defaultSubscription = credentials.defaultSubscriptionId();
    }
    interceptor = new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            if (IS_MOCKED) {
                return registerRecordedResponse(chain);
            } else {
                return chain.proceed(chain.request());
            }
        }
    };
    restClient = createRestClient(credentials);
    initialize(restClient, defaultSubscription, credentials.domain());
}
Also used : Response(okhttp3.Response) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) IOException(java.io.IOException) File(java.io.File) Interceptor(okhttp3.Interceptor) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 23 with ApplicationTokenCredentials

use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-tools-for-java by Microsoft.

the class IntegrationTestBase method createRestClient.

private RestClient createRestClient(ApplicationTokenCredentials credentials) {
    final RestClient client;
    ApplicationTokenCredentials cred = credentials;
    if (IS_MOCKED) {
        cred = new TestCredentials();
        client = new RestClient.Builder().withBaseUrl(MOCK_URI + "/").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(cred).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
    } else {
        client = new RestClient.Builder().withBaseUrl(GLOBAL_ENDPOINT).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(cred).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
    }
    return client;
}
Also used : AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) MappingBuilder(com.github.tomakehurst.wiremock.client.MappingBuilder) ResponseDefinitionBuilder(com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials)

Example 24 with ApplicationTokenCredentials

use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-tools-for-java by Microsoft.

the class IntegrationTestBase method setUpStep.

public void setUpStep() throws Exception {
    if (currentTestName == null) {
        currentTestName = name.getMethodName();
    } else {
        throw new Exception("Setting up another test in middle of a test");
    }
    addTextReplacementRule(GLOBAL_ENDPOINT, MOCK_URI + "/");
    ApplicationTokenCredentials credentials = new TestCredentials();
    String defaultSubscription = "";
    if (IS_MOCKED) {
        defaultSubscription = MOCK_SUBSCRIPTION;
        File recordFile = getRecordFile();
        ObjectMapper mapper = new ObjectMapper();
        try {
            testRecord = mapper.readValue(recordFile, TestRecord.class);
        } catch (Exception e) {
            throw new Exception("Fail read test record: " + e.getMessage());
        }
    } else {
        try {
            credentials = ApplicationTokenCredentials.fromFile(new File(azureAuthFile));
        } catch (Exception e) {
            throw new Exception("Fail to open auth file:" + azureAuthFile);
        }
        defaultSubscription = credentials.defaultSubscriptionId();
    }
    interceptor = new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            if (IS_MOCKED) {
                return registerRecordedResponse(chain);
            } else {
                return chain.proceed(chain.request());
            }
        }
    };
    restClient = createRestClient(credentials);
    initialize(restClient, defaultSubscription, credentials.domain());
}
Also used : Response(okhttp3.Response) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) IOException(java.io.IOException) File(java.io.File) Interceptor(okhttp3.Interceptor) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 25 with ApplicationTokenCredentials

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

the class AzureUseAnExistingSubnetInAnExistingVpcNetworkTest method createNetwork.

@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "resourceGroupName", "vpcName", "vpcSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-resource-group") String resourceGroupName, @Optional("it-vpc") String vpcName, @Optional("it-vpc-subnet") String vpcSubnet) {
    ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(defaultAccesKey, defaultTenantId, defaultSecretKey, null);
    Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(defaultSubscriptionId);
    azure.networks().define(vpcName).withRegion(regionName).withNewResourceGroup(resourceGroupName).withAddressSpace("10.0.0.0/16").withSubnet(vpcSubnet, "10.0.0.0/16").create();
    NetworkRequest networkRequest = new NetworkRequest();
    networkRequest.setName(networkName);
    networkRequest.setDescription(description);
    Map<String, Object> map = new HashMap<>();
    map.put("networkId", vpcName);
    map.put("subnetId", vpcSubnet);
    map.put("resourceGroupName", resourceGroupName);
    networkRequest.setParameters(map);
    networkRequest.setCloudPlatform("AZURE");
    // networkJson.setPublicInAccount(publicInAccount);
    String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
    getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Also used : Azure(com.microsoft.azure.management.Azure) HashMap(java.util.HashMap) NetworkRequest(com.sequenceiq.cloudbreak.api.model.NetworkRequest) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

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