Search in sources :

Example 11 with ApplicationTokenCredentials

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

the class TestBase method setup.

@Before
public void setup() throws Exception {
    addTextReplacementRule("https://management.azure.com/", this.mockUri() + "/");
    setupTest(name.getMethodName());
    ApplicationTokenCredentials credentials;
    RestClient restClient;
    String defaultSubscription;
    if (IS_MOCKED) {
        credentials = new AzureTestCredentials();
        restClient = buildRestClient(new RestClient.Builder().withBaseUrl(this.mockUri() + "/").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), true);
        defaultSubscription = MOCK_SUBSCRIPTION;
        System.out.println(this.mockUri());
        out = System.out;
        System.setOut(new PrintStream(new OutputStream() {

            public void write(int b) {
            //DO NOTHING
            }
        }));
    } else {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        credentials = ApplicationTokenCredentials.fromFile(credFile);
        restClient = buildRestClient(new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withInterceptor(new ProviderRegistrationInterceptor(credentials)).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withReadTimeout(3, TimeUnit.MINUTES).withNetworkInterceptor(this.interceptor()), false);
        defaultSubscription = credentials.defaultSubscriptionId();
        addTextReplacementRule(defaultSubscription, MOCK_SUBSCRIPTION);
    }
    initializeClients(restClient, defaultSubscription, credentials.domain());
}
Also used : PrintStream(java.io.PrintStream) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) OutputStream(java.io.OutputStream) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File) ProviderRegistrationInterceptor(com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor) Before(org.junit.Before)

Example 12 with ApplicationTokenCredentials

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

the class ManageSqlDatabase method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

Example 13 with ApplicationTokenCredentials

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

the class ManageSqlDatabaseInElasticPool method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

Example 14 with ApplicationTokenCredentials

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

the class ManageSqlDatabasesAcrossDifferentDataCenters method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

Example 15 with ApplicationTokenCredentials

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

the class ManageSqlFirewallRules method main.

/**
     * Main entry point.
     * @param args the parameters
     */
public static void main(String[] args) {
    try {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
        RestClient restClient = new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withReadTimeout(150, TimeUnit.SECONDS).withLogLevel(LogLevel.BODY).withCredentials(credentials).build();
        Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription();
        // Print selected subscription
        System.out.println("Selected subscription: " + azure.subscriptionId());
        runSample(azure);
    } catch (Exception e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
}
Also used : Azure(com.microsoft.azure.management.Azure) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File)

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