Search in sources :

Example 16 with AzureProfile

use of com.azure.core.management.profile.AzureProfile 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 17 with AzureProfile

use of com.azure.core.management.profile.AzureProfile 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)

Example 18 with AzureProfile

use of com.azure.core.management.profile.AzureProfile in project azure-vm-agents-plugin by jenkinsci.

the class AzureClientUtil method getAzureResourceManager.

private static AzureResourceManager getAzureResourceManager(AzureBaseCredentials azureCredentials, String subscriptionId) {
    AzureProfile profile = new AzureProfile(azureCredentials.getAzureEnvironment());
    TokenCredential tokenCredential = AzureCredentials.getTokenCredential(azureCredentials);
    AzureResourceManager.Authenticated builder = AzureResourceManager.configure().withHttpClient(HttpClientRetriever.get()).authenticate(tokenCredential, profile);
    if (Util.fixEmpty(subscriptionId) == null) {
        return builder.withDefaultSubscription();
    }
    return builder.withSubscription(subscriptionId);
}
Also used : AzureProfile(com.azure.core.management.profile.AzureProfile) AzureResourceManager(com.azure.resourcemanager.AzureResourceManager) TokenCredential(com.azure.core.credential.TokenCredential)

Aggregations

AzureProfile (com.azure.core.management.profile.AzureProfile)18 HttpLogDetailLevel (com.azure.core.http.policy.HttpLogDetailLevel)9 TokenCredential (com.azure.core.credential.TokenCredential)8 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 AzureResourceManager (com.azure.resourcemanager.AzureResourceManager)3 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 ClientSecretCredentialBuilder (com.azure.identity.ClientSecretCredentialBuilder)1 DefaultAzureCredentialBuilder (com.azure.identity.DefaultAzureCredentialBuilder)1 ManagedIdentityCredential (com.azure.identity.ManagedIdentityCredential)1 ManagedIdentityCredentialBuilder (com.azure.identity.ManagedIdentityCredentialBuilder)1 ComputeManager (com.azure.resourcemanager.compute.ComputeManager)1 RelayManager (com.azure.resourcemanager.relay.RelayManager)1 ResourceManager (com.azure.resourcemanager.resources.ResourceManager)1 Subscription (com.azure.resourcemanager.resources.models.Subscription)1