use of com.azure.identity.DefaultAzureCredentialBuilder 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);
}
use of com.azure.identity.DefaultAzureCredentialBuilder in project DataSpaceConnector by eclipse-dataspaceconnector.
the class DataPlaneAzureDataFactoryExtension method initialize.
@Override
public void initialize(ServiceExtensionContext context) {
var monitor = context.getMonitor();
var dataFactoryId = requiredSetting(context, RESOURCE_ID);
var keyVaultId = requiredSetting(context, KEY_VAULT_RESOURCE_ID);
var keyVaultLinkedService = context.getSetting(KEY_VAULT_LINKED_SERVICE_NAME, "AzureKeyVault");
var dataFactoryManager = DataFactoryManager.authenticate(credential, profile);
var factory = resourceManager.genericResources().getById(dataFactoryId);
var vault = resourceManager.vaults().getById(keyVaultId);
var secretClient = new SecretClientBuilder().vaultUrl(vault.vaultUri()).credential(new DefaultAzureCredentialBuilder().build()).buildClient();
var maxDuration = Duration.ofHours(1);
var dataFactoryClient = new DataFactoryClient(dataFactoryManager, factory.resourceGroupName(), factory.name());
var keyVaultClient = new KeyVaultClient(secretClient);
var validator = new AzureDataFactoryTransferRequestValidator();
var pipelineFactory = new DataFactoryPipelineFactory(keyVaultLinkedService, keyVaultClient, dataFactoryClient, context.getTypeManager());
var pollDelay = Duration.ofMillis(context.getSetting(DATA_FACTORY_POLL_DELAY, 5000L));
var transferManager = new AzureDataFactoryTransferManager(monitor, dataFactoryClient, pipelineFactory, maxDuration, clock, blobStoreApi, context.getTypeManager(), keyVaultClient, pollDelay);
var transferService = new AzureDataFactoryTransferService(validator, transferManager);
registry.registerTransferService(transferService);
}
use of com.azure.identity.DefaultAzureCredentialBuilder in project vividus by vividus-framework.
the class CredentialFactoryTests method shouldCreateTokenCredential.
@Test
void shouldCreateTokenCredential() {
DefaultAzureCredential defaultAzureCredential = mock(DefaultAzureCredential.class);
try (MockedConstruction<DefaultAzureCredentialBuilder> credentialsBuilder = mockConstruction(DefaultAzureCredentialBuilder.class, (mock, context) -> when(mock.build()).thenReturn(defaultAzureCredential))) {
assertEquals(defaultAzureCredential, CredentialFactory.createTokenCredential());
assertThat(credentialsBuilder.constructed(), hasSize(1));
}
}
use of com.azure.identity.DefaultAzureCredentialBuilder in project MinimumViableDataspace by agera-edc.
the class BlobTransferIntegrationTest method getBlobServiceClient.
@NotNull
private BlobServiceClient getBlobServiceClient(String keyVaultName) {
var credential = new DefaultAzureCredentialBuilder().build();
var vault = new SecretClientBuilder().vaultUrl(format(KEY_VAULT_ENDPOINT_TEMPLATE, keyVaultName)).credential(credential).buildClient();
// Find the first account with a key in the key vault
var accountKeySecret = vault.listPropertiesOfSecrets().stream().filter(s -> s.getName().endsWith("-key1")).findFirst().orElseThrow(() -> new AssertionError("Key vault " + keyVaultName + " should contain the storage account key"));
var accountKey = vault.getSecret(accountKeySecret.getName());
var accountName = accountKeySecret.getName().replaceFirst("-key1$", "");
var blobServiceClient = new BlobServiceClientBuilder().endpoint(format(BLOB_STORE_ENDPOINT_TEMPLATE, accountName)).credential(new StorageSharedKeyCredential(accountName, accountKey.getValue())).buildClient();
return blobServiceClient;
}
use of com.azure.identity.DefaultAzureCredentialBuilder in project tessera by ConsenSys.
the class AzureKeyVaultServiceFactory method create.
@Override
public KeyVaultService create(Config config, EnvironmentVariableProvider envProvider) {
Objects.requireNonNull(config);
final KeyVaultConfig keyVaultConfig = Optional.ofNullable(config.getKeys()).flatMap(k -> k.getKeyVaultConfig(KeyVaultType.AZURE)).orElseThrow(() -> new ConfigException(new RuntimeException("Trying to create Azure key vault connection but no Azure configuration provided")));
final String url = keyVaultConfig.getProperty("url").orElseThrow(() -> new ConfigException(new RuntimeException("No Azure Key Vault url provided")));
final SecretClient secretClient = new SecretClientBuilder().vaultUrl(url).httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)).credential(new DefaultAzureCredentialBuilder().build()).buildClient();
return new AzureKeyVaultService(secretClient);
}
Aggregations