use of com.azure.core.management.profile.AzureProfile in project azure-credentials-plugin by jenkinsci.
the class AzureResourceManagerRetriever method getAzureResourceManager.
private static AzureResourceManager getAzureResourceManager(AzureBaseCredentials azureCredentials, @CheckForNull 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);
}
use of com.azure.core.management.profile.AzureProfile in project azure-credentials-plugin by jenkinsci.
the class AzureImdsCredentials method validate.
public boolean validate() throws AzureCredentials.ValidationException {
try {
final String credentialSubscriptionId = getSubscriptionId();
AzureProfile profile = new AzureProfile(AzureEnvUtil.resolveAzureEnv(getAzureEnvName()));
ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder().build();
AzureResourceManager azure = AzureResourceManager.configure().withHttpClient(HttpClientRetriever.get()).authenticate(credential, profile).withSubscription(credentialSubscriptionId);
PagedIterable<Subscription> subscriptions = azure.subscriptions().list();
if (subscriptionId != null) {
for (Subscription subscription : subscriptions) {
if (subscription.subscriptionId().equalsIgnoreCase(credentialSubscriptionId)) {
return true;
}
}
} else {
return true;
}
} catch (Exception e) {
throw new AzureCredentials.ValidationException(Messages.Azure_CantValidate() + ": " + e.getMessage(), e);
}
throw new AzureCredentials.ValidationException(Messages.Azure_Invalid_SubscriptionId());
}
use of com.azure.core.management.profile.AzureProfile in project azure-credentials-plugin by jenkinsci.
the class IntegrationTestBase method getAzureClient.
protected static AzureResourceManager getAzureClient() {
final TokenCredential credential = new ClientSecretCredentialBuilder().clientId(testEnv.clientId).clientSecret(testEnv.clientSecret).tenantId(testEnv.tenantId).build();
AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
return AzureResourceManager.authenticate(credential, profile).withSubscription(testEnv.subscriptionId);
}
use of com.azure.core.management.profile.AzureProfile 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);
}
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();
}
Aggregations