Search in sources :

Example 6 with HttpLogDetailLevel

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

the class AbstractAzureResourceModule method getResourceManager.

protected static <R extends AzureConfigurable<R>, T extends Manager> T getResourceManager(final String subscriptionId, Supplier<AzureConfigurable<R>> configurableSupplier, AuthenticationMethod<R, T> authenticationMethod) {
    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());
    final TokenCredential tokenCredential = account.getTokenCredential(subscriptionId);
    final R configurable = configurableSupplier.get().withPolicy(getUserAgentPolicy(userAgent)).withLogLevel(logLevel);
    return authenticationMethod.apply(configurable, tokenCredential, 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) TokenCredential(com.azure.core.credential.TokenCredential)

Example 7 with HttpLogDetailLevel

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

the class AzureService method getResourceManager.

@Cacheable(cacheName = "resource/{}/manager", key = "$subscriptionId")
default ResourceManager getResourceManager(String subscriptionId) {
    // make sure it is signed in.
    final IAccount account = az(IAzureAccount.class).account();
    final AzureConfiguration config = Azure.az().config();
    final String userAgent = config.getUserAgent();
    final HttpLogDetailLevel logDetailLevel = config.getLogLevel() == null ? HttpLogDetailLevel.NONE : HttpLogDetailLevel.valueOf(config.getLogLevel());
    final AzureProfile azureProfile = new AzureProfile(account.getEnvironment());
    final Providers providers = ResourceManager.configure().withHttpClient(getDefaultHttpClient()).withPolicy(getUserAgentPolicy(userAgent)).authenticate(account.getTokenCredential(subscriptionId), azureProfile).withSubscription(subscriptionId).providers();
    return ResourceManager.configure().withHttpClient(getDefaultHttpClient()).withLogLevel(logDetailLevel).withPolicy(// set user agent with policy
    getUserAgentPolicy(userAgent)).withPolicy(// add policy to auto register resource providers
    new ProviderRegistrationPolicy(providers)).authenticate(account.getTokenCredential(subscriptionId), azureProfile).withSubscription(subscriptionId);
}
Also used : IAccount(com.microsoft.azure.toolkit.lib.account.IAccount) IAzureAccount(com.microsoft.azure.toolkit.lib.account.IAzureAccount) HttpLogDetailLevel(com.azure.core.http.policy.HttpLogDetailLevel) ProviderRegistrationPolicy(com.azure.resourcemanager.resources.fluentcore.policy.ProviderRegistrationPolicy) AzureProfile(com.azure.core.management.profile.AzureProfile) Providers(com.azure.resourcemanager.resources.models.Providers) Cacheable(com.microsoft.azure.toolkit.lib.common.cache.Cacheable)

Example 8 with HttpLogDetailLevel

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

the class AzureSpringCloud method getClient.

@Cacheable(cacheName = "asc/{}/client", key = "$subscriptionId")
@AzureOperation(name = "springcloud.get_client.subscription", params = "subscriptionId", type = AzureOperation.Type.SERVICE)
protected SpringServices getClient(final 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 AppPlatformManager.configure().withHttpClient(AzureService.getDefaultHttpClient()).withLogLevel(logLevel).withPolicy(// set user agent with policy
    getUserAgentPolicy(userAgent)).authenticate(account.getTokenCredential(subscriptionId), azureProfile).springServices();
}
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)

Example 9 with HttpLogDetailLevel

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

the class SqlServerManagerFactory method create.

@Cacheable(cacheName = "SqlServerManager", key = "$subscriptionId")
public static SqlServerManager 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 SqlServerManager.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)

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