Search in sources :

Example 6 with AzureProfile

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

use of com.azure.core.management.profile.AzureProfile in project DataSpaceConnector by eclipse-dataspaceconnector.

the class AzureResourceManagerExtension method initialize.

@Override
public void initialize(ServiceExtensionContext context) {
    var tenantId = requiredSetting(context, "edc.azure.tenant.id");
    var subscriptionId = requiredSetting(context, "edc.azure.subscription.id");
    // Detect credential source based on runtime environment, e.g. Azure CLI, environment variables
    var credential = new DefaultAzureCredentialBuilder().build();
    var azure = AzureEnvironment.AZURE;
    var profile = new AzureProfile(tenantId, subscriptionId, azure);
    var resourceManager = AzureResourceManager.authenticate(credential, profile).withSubscription(subscriptionId);
    context.registerService(AzureEnvironment.class, azure);
    context.registerService(TokenCredential.class, credential);
    context.registerService(AzureProfile.class, profile);
    context.registerService(AzureResourceManager.class, resourceManager);
}
Also used : DefaultAzureCredentialBuilder(com.azure.identity.DefaultAzureCredentialBuilder) AzureProfile(com.azure.core.management.profile.AzureProfile)

Example 8 with AzureProfile

use of com.azure.core.management.profile.AzureProfile in project terra-workspace-manager by DataBiosphere.

the class CrlService method buildComputeManager.

private ComputeManager buildComputeManager(AzureCloudContext azureCloudContext, AzureConfiguration azureConfig) {
    TokenCredential azureCreds = getManagedAppCredentials(azureConfig);
    AzureProfile azureProfile = new AzureProfile(azureCloudContext.getAzureTenantId(), azureCloudContext.getAzureSubscriptionId(), AzureEnvironment.AZURE);
    // We must use FQDN because there are two `Defaults` symbols imported otherwise.
    ComputeManager manager = bio.terra.cloudres.azure.resourcemanager.common.Defaults.crlConfigure(clientConfig, ComputeManager.configure()).authenticate(azureCreds, azureProfile);
    return manager;
}
Also used : AzureProfile(com.azure.core.management.profile.AzureProfile) TokenCredential(com.azure.core.credential.TokenCredential) ComputeManager(com.azure.resourcemanager.compute.ComputeManager)

Example 9 with AzureProfile

use of com.azure.core.management.profile.AzureProfile in project terra-workspace-manager by DataBiosphere.

the class CrlService method buildRelayManager.

private RelayManager buildRelayManager(AzureCloudContext azureCloudContext, AzureConfiguration azureConfig) {
    TokenCredential azureCreds = getManagedAppCredentials(azureConfig);
    AzureProfile azureProfile = new AzureProfile(azureCloudContext.getAzureTenantId(), azureCloudContext.getAzureSubscriptionId(), AzureEnvironment.AZURE);
    // We must use FQDN because there are two `Defaults` symbols imported otherwise.
    RelayManager manager = bio.terra.cloudres.azure.resourcemanager.relay.Defaults.crlConfigure(clientConfig, RelayManager.configure()).authenticate(azureCreds, azureProfile);
    return manager;
}
Also used : RelayManager(com.azure.resourcemanager.relay.RelayManager) AzureProfile(com.azure.core.management.profile.AzureProfile) TokenCredential(com.azure.core.credential.TokenCredential)

Example 10 with AzureProfile

use of com.azure.core.management.profile.AzureProfile in project terra-workspace-manager by DataBiosphere.

the class CrlService method buildResourceManager.

/**
 * Get a resource manager pointed at the MRG subscription
 *
 * @param azureCloudContext target cloud context
 * @return azure resource manager
 */
public ResourceManager buildResourceManager(AzureCloudContext azureCloudContext, AzureConfiguration azureConfig) {
    TokenCredential azureCreds = getManagedAppCredentials(azureConfig);
    AzureProfile azureProfile = new AzureProfile(azureCloudContext.getAzureTenantId(), azureCloudContext.getAzureSubscriptionId(), AzureEnvironment.AZURE);
    // We must use FQDN because there are two `Defaults` symbols imported otherwise.
    ResourceManager manager = bio.terra.cloudres.azure.resourcemanager.common.Defaults.crlConfigure(clientConfig, ResourceManager.configure()).authenticate(azureCreds, azureProfile).withSubscription(azureCloudContext.getAzureSubscriptionId());
    return manager;
}
Also used : AzureProfile(com.azure.core.management.profile.AzureProfile) ResourceManager(com.azure.resourcemanager.resources.ResourceManager) 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