use of com.azure.identity.ManagedIdentityCredential 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());
}
Aggregations