Search in sources :

Example 1 with HttpLogDetailLevel

use of com.azure.core.http.policy.HttpLogDetailLevel in project azure-maven-plugins by microsoft.

the class RedisManagerFactory method create.

@Cacheable(cacheName = "RedisManager", key = "$subscriptionId")
public static RedisManager create(String subscriptionId) {
    final Account account = Azure.az(AzureAccount.class).account();
    final AzureConfiguration config = Azure.az().config();
    final String userAgent = config.getUserAgent();
    final HttpLogDetailLevel logLevel = Optional.ofNullable(config.getLogLevel()).map(HttpLogDetailLevel::valueOf).orElse(HttpLogDetailLevel.NONE);
    final AzureProfile azureProfile = new AzureProfile(null, subscriptionId, account.getEnvironment());
    return RedisManager.configure().withHttpClient(AzureService.getDefaultHttpClient()).withLogLevel(logLevel).withPolicy(getUserAgentPolicy(userAgent)).authenticate(account.getTokenCredential(subscriptionId), azureProfile);
}
Also used : AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Account(com.microsoft.azure.toolkit.lib.auth.Account) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) AzureProfile(com.azure.core.management.profile.AzureProfile) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable)

Example 2 with HttpLogDetailLevel

use of com.azure.core.http.policy.HttpLogDetailLevel in project azure-maven-plugins by microsoft.

the class MySqlManagerFactory method create.

@Cacheable(cacheName = "MySqlManager", key = "$subscriptionId")
public static MySqlManager create(String subscriptionId) {
    final Account account = Azure.az(AzureAccount.class).account();
    final AzureConfiguration config = Azure.az().config();
    final String userAgent = config.getUserAgent();
    final HttpLogDetailLevel logLevel = Optional.ofNullable(config.getLogLevel()).map(HttpLogDetailLevel::valueOf).orElse(HttpLogDetailLevel.NONE);
    final AzureProfile azureProfile = new AzureProfile(null, subscriptionId, account.getEnvironment());
    return MySqlManager.configure().withHttpClient(AzureService.getDefaultHttpClient()).withLogOptions(new HttpLogOptions().setLogLevel(logLevel)).withPolicy(getUserAgentPolicy(userAgent)).authenticate(account.getTokenCredential(subscriptionId), azureProfile);
}
Also used : AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Account(com.microsoft.azure.toolkit.lib.auth.Account) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) AzureProfile(com.azure.core.management.profile.AzureProfile) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable)

Example 3 with HttpLogDetailLevel

use of com.azure.core.http.policy.HttpLogDetailLevel in project azure-maven-plugins by microsoft.

the class StorageManagerFactory method create.

@Cacheable(cacheName = "StorageManager", key = "$subscriptionId")
public static StorageManager create(String subscriptionId) {
    final Account account = Azure.az(AzureAccount.class).account();
    final AzureConfiguration config = Azure.az().config();
    final String userAgent = config.getUserAgent();
    final HttpLogDetailLevel logLevel = Optional.ofNullable(config.getLogLevel()).map(HttpLogDetailLevel::valueOf).orElse(HttpLogDetailLevel.NONE);
    final AzureProfile azureProfile = new AzureProfile(null, subscriptionId, account.getEnvironment());
    return StorageManager.configure().withHttpClient(AzureService.getDefaultHttpClient()).withLogLevel(logLevel).withPolicy(getUserAgentPolicy(userAgent)).authenticate(account.getTokenCredential(subscriptionId), azureProfile);
}
Also used : AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Account(com.microsoft.azure.toolkit.lib.auth.Account) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) AzureProfile(com.azure.core.management.profile.AzureProfile) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable)

Example 4 with HttpLogDetailLevel

use of com.azure.core.http.policy.HttpLogDetailLevel in project azure-maven-plugins by microsoft.

the class ApplicationInsights method getApplicationInsightsManager.

@Cacheable(cacheName = "applicationinsights/{}/manager", key = "$subscriptionId")
private ApplicationInsightsManager getApplicationInsightsManager(String subscriptionId) {
    final Account account = Azure.az(AzureAccount.class).account();
    final String tenantId = account.getSubscription(subscriptionId).getTenantId();
    final AzureConfiguration config = Azure.az().config();
    final String userAgent = config.getUserAgent();
    final HttpLogOptions logOptions = new HttpLogOptions();
    logOptions.setLogLevel(Optional.ofNullable(config.getLogLevel()).map(HttpLogDetailLevel::valueOf).orElse(HttpLogDetailLevel.NONE));
    final AzureProfile azureProfile = new AzureProfile(tenantId, subscriptionId, account.getEnvironment());
    // todo: migrate resource provider related codes to common library
    final Providers providers = ResourceManager.configure().withHttpClient(AzureService.getDefaultHttpClient()).withPolicy(getUserAgentPolicy(userAgent)).authenticate(account.getTokenCredential(subscriptionId), azureProfile).withSubscription(subscriptionId).providers();
    return ApplicationInsightsManager.configure().withHttpClient(AzureService.getDefaultHttpClient()).withLogOptions(logOptions).withPolicy(getUserAgentPolicy(userAgent)).withPolicy(// add policy to auto register resource providers
    new ProviderRegistrationPolicy(providers)).authenticate(account.getTokenCredential(subscriptionId), azureProfile);
}
Also used : Account(com.microsoft.azure.toolkit.lib.auth.Account) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) ProviderRegistrationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy) AzureProfile(com.azure.core.management.profile.AzureProfile) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) HttpLogOptions(com.azure.core.http.policy.HttpLogOptions) Providers(com.azure.resourcemanager.resources.models.Providers) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable)

Example 5 with HttpLogDetailLevel

use of com.azure.core.http.policy.HttpLogDetailLevel in project azure-maven-plugins by microsoft.

the class AzureAppService method getAppServiceManager.

// todo: share codes with other library which leverage track2 mgmt sdk
@Cacheable(cacheName = "appservice/{}/manager", key = "$sid")
@AzureOperation(name = "appservice.get_client.subscription", params = "sid", type = AzureOperation.Type.SERVICE)
public AppServiceManager getAppServiceManager(String sid) {
    final Account account = Azure.az(AzureAccount.class).account();
    final AzureConfiguration config = Azure.az().config();
    final String userAgent = config.getUserAgent();
    final HttpLogDetailLevel logLevel = Optional.ofNullable(config.getLogLevel()).map(HttpLogDetailLevel::valueOf).orElse(HttpLogDetailLevel.NONE);
    final AzureProfile azureProfile = new AzureProfile(null, sid, account.getEnvironment());
    return AppServiceManager.configure().withHttpClient(AzureService.getDefaultHttpClient()).withLogLevel(logLevel).withPolicy(// set user agent with policy
    getUserAgentPolicy(userAgent)).authenticate(account.getTokenCredential(sid), azureProfile);
}
Also used : Account(com.microsoft.azure.toolkit.lib.auth.Account) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) AzureConfiguration(com.microsoft.azure.toolkit.lib.AzureConfiguration) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) AzureProfile(com.azure.core.management.profile.AzureProfile) AzureAccount(com.microsoft.azure.toolkit.lib.auth.AzureAccount) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable) AzureOperation(com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)

Aggregations

HttpLogDetailLevel (com.azure.core.http.policy.HttpLogDetailLevel)9 AzureProfile (com.azure.core.management.profile.AzureProfile)9 AzureConfiguration (com.microsoft.azure.toolkit.lib.AzureConfiguration)8 Account (com.microsoft.azure.toolkit.lib.auth.Account)8 AzureAccount (com.microsoft.azure.toolkit.lib.auth.AzureAccount)8 Cacheable (com.microsoft.azure.toolkit.lib.common.cache.Cacheable)8 HttpLogOptions (com.azure.core.http.policy.HttpLogOptions)2 ProviderRegistrationPolicy (com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy)2 Providers (com.azure.resourcemanager.resources.models.Providers)2 AzureOperation (com.microsoft.azure.toolkit.lib.common.operation.AzureOperation)2 TokenCredential (com.azure.core.credential.TokenCredential)1 IAccount (com.microsoft.azure.toolkit.lib.account.IAccount)1 IAzureAccount (com.microsoft.azure.toolkit.lib.account.IAzureAccount)1