use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-sdk-for-java by Azure.
the class DataLakeAnalyticsManagementTestBase method initializeClients.
@Override
protected void initializeClients(RestClient restClient, String defaultSubscription, String domain) {
rgName = generateRandomResourceName("adlarg", 15);
adlsName = generateRandomResourceName("adls", 15);
jobAndCatalogAdlaName = generateRandomResourceName("secondadla", 15);
environmentLocation = Region.US_EAST2;
dataLakeAnalyticsAccountManagementClient = new DataLakeAnalyticsAccountManagementClientImpl(restClient).withSubscriptionId(defaultSubscription);
// TODO: in the future this needs to be dynamic depending on the Azure environment
// the tests are running in.
String adlaSuffix = "azuredatalakeanalytics.net";
addTextReplacementRule("https://(.*)." + adlaSuffix, this.mockUri());
// Generate creds and a set of rest clients for catalog and job
ApplicationTokenCredentials credentials = new AzureTestCredentials();
if (IS_RECORD) {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
try {
credentials = ApplicationTokenCredentials.fromFile(credFile);
} catch (IOException e) {
Assert.fail("Failed to read credentials from file: " + credFile + " with error: " + e.getMessage());
}
}
if (IS_RECORD) {
RestClient restClientWithTimeout = buildRestClient(new RestClient.Builder().withConnectionTimeout(5, TimeUnit.MINUTES).withBaseUrl("https://{accountName}.{adlaJobDnsSuffix}").withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), IS_MOCKED);
dataLakeAnalyticsJobManagementClient = new DataLakeAnalyticsJobManagementClientImpl(restClientWithTimeout).withAdlaJobDnsSuffix(adlaSuffix);
RestClient catalogRestClient = buildRestClient(new RestClient.Builder().withBaseUrl("https://{accountName}.{adlaCatalogDnsSuffix}").withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), IS_MOCKED);
dataLakeAnalyticsCatalogManagementClient = new DataLakeAnalyticsCatalogManagementClientImpl(catalogRestClient).withAdlaCatalogDnsSuffix(adlaSuffix);
} else {
// for mocked clients, we can just use the basic rest client, since the DNS is replaced.
dataLakeAnalyticsCatalogManagementClient = new DataLakeAnalyticsCatalogManagementClientImpl(restClient);
dataLakeAnalyticsJobManagementClient = new DataLakeAnalyticsJobManagementClientImpl(restClient);
}
resourceManagementClient = ResourceManager.authenticate(restClient).withSubscription(defaultSubscription);
dataLakeStoreAccountManagementClient = new DataLakeStoreAccountManagementClientImpl(restClient).withSubscriptionId(defaultSubscription);
storageManagementClient = StorageManager.authenticate(restClient, defaultSubscription);
// create the resource group, ADLS account and ADLA account for job and catalog use.
resourceManagementClient.resourceGroups().define(rgName).withRegion(environmentLocation).create();
DataLakeStoreAccount createParams = new DataLakeStoreAccount();
createParams.withLocation(environmentLocation.name());
dataLakeStoreAccountManagementClient.accounts().create(rgName, adlsName, createParams);
List<DataLakeStoreAccountInfo> adlsAccts = new ArrayList<DataLakeStoreAccountInfo>();
DataLakeStoreAccountInfo adlsInfo = new DataLakeStoreAccountInfo();
adlsInfo.withName(adlsName);
adlsAccts.add(adlsInfo);
DataLakeAnalyticsAccount adlaCreateParams = new DataLakeAnalyticsAccount();
adlaCreateParams.withLocation(environmentLocation.name());
adlaCreateParams.withDataLakeStoreAccounts(adlsAccts);
adlaCreateParams.withDefaultDataLakeStoreAccount(adlsName);
dataLakeAnalyticsAccountManagementClient.accounts().create(rgName, jobAndCatalogAdlaName, adlaCreateParams);
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project photon-model by vmware.
the class AzureRemoteCleanup method setUp.
@Before
public void setUp() throws Exception {
try {
this.credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
this.azureClient = Azure.configure().authenticate(this.credentials).withSubscription(this.subscriptionId);
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project photon-model by vmware.
the class TestAzureLongRunningEnumeration method setUp.
@Override
@Before
public void setUp() throws Exception {
for (int i = 0; i < numOfVMsToTest; i++) {
String azureName = generateName(azureVMNamePrefix);
azureVMNames.add(azureName);
nicSpecs.add(initializeNicSpecs(azureName, false, true, false));
}
try {
/*
* Init Class-specific (shared between test runs) vars.
*
* NOTE: Ultimately this should go to @BeforeClass, BUT BasicReusableHostTestCase.HOST
* is not accessible.
*/
if (computeHost == null) {
PhotonModelServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
AzureAdaptersTestUtils.startServicesSynchronouslyAzure(this.host);
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
// TODO: VSYM-992 - improve test/fix arbitrary timeout
this.host.setTimeoutSeconds(this.timeoutSeconds);
// Create a resource pool where the VMs will be housed
ResourcePoolState resourcePool = createDefaultResourcePool(this.host);
AuthCredentialsServiceState authCredentials = createDefaultAuthCredentials(this.host, this.clientID, this.clientKey, this.subscriptionId, this.tenantId);
endpointState = createDefaultEndpointState(this.host, authCredentials.documentSelfLink);
// create a compute host for the Azure
computeHost = createDefaultComputeHost(this.host, resourcePool.documentSelfLink, endpointState);
endpointState.computeHostLink = computeHost.documentSelfLink;
}
this.host.waitForServiceAvailable(PhotonModelServices.LINKS);
this.host.waitForServiceAvailable(PhotonModelTaskServices.LINKS);
this.nodeStatsUri = UriUtils.buildUri(this.host.getUri(), ServiceUriPaths.CORE_MANAGEMENT);
this.maxMemoryInMb = this.host.getState().systemInfo.maxMemoryByteCount / BYTES_TO_MB;
internalTagResourcesMap.put(NetworkState.class, NETWORK_TAG_TYPE_VALUE);
internalTagResourcesMap.put(SubnetState.class, SUBNET_TAG_TYPE_VALUE);
internalTagResourcesMap.put(NetworkInterfaceState.class, NETWORK_INTERFACE_TAG_TYPE_VALUE);
if (!this.isMock) {
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(this.clientID, this.tenantId, this.clientKey, AzureEnvironment.AZURE);
this.computeManagementClient = new ComputeManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
this.resourceManagementClient = new ResourceManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
this.storageManagementClient = new StorageManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
this.networkManagementClient = new NetworkManagementClientImpl(credentials).withSubscriptionId(this.subscriptionId);
}
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project photon-model by vmware.
the class AzureUtils method getAzureConfig.
/**
* Configures authentication credential for Azure.
*/
public static ApplicationTokenCredentials getAzureConfig(AuthCredentialsServiceState parentAuth) {
String clientId = parentAuth.privateKeyId;
String clientKey = EncryptionUtils.decrypt(parentAuth.privateKey);
String tenantId = parentAuth.customProperties.get(AzureConstants.AZURE_TENANT_ID);
AzureEnvironment azureEnvironment = AzureEnvironment.AZURE;
if (AzureUtils.isAzureClientMock()) {
azureEnvironment.endpoints().put(AzureEnvironment.Endpoint.ACTIVE_DIRECTORY.toString(), AzureUtils.getAzureBaseUri());
}
return new ApplicationTokenCredentials(clientId, tenantId, clientKey, azureEnvironment);
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-gradle-plugins by lenala.
the class AzureAuthHelper method getAppTokenCredentials.
/**
* Get ApplicationTokenCredentials from authentication settings in gradle.properties.
*
* @return ApplicationTokenCredentials object if configuration is correct; otherwise return null.
*/
private ApplicationTokenCredentials getAppTokenCredentials() {
final String clientId = config.getAuthenticationSetting(CLIENT_ID);
if (StringUtils.isEmpty(clientId)) {
logger.quiet(CLIENT_ID_NOT_CONFIG);
return null;
}
final String tenantId = config.getAuthenticationSetting(TENANT_ID);
if (StringUtils.isEmpty(tenantId)) {
logger.quiet(TENANT_ID_NOT_CONFIG);
return null;
}
final String environment = config.getAuthenticationSetting(ENVIRONMENT);
final AzureEnvironment azureEnvironment = getAzureEnvironment(environment);
logger.quiet("Azure Management Endpoint: " + azureEnvironment.managementEndpoint());
final String key = config.getAuthenticationSetting(KEY);
if (!StringUtils.isEmpty(key)) {
logger.quiet(USE_KEY_TO_AUTH);
return new ApplicationTokenCredentials(clientId, tenantId, key, azureEnvironment);
} else {
logger.quiet(KEY_NOT_CONFIG);
}
final String certificate = config.getAuthenticationSetting(CERTIFICATE);
if (StringUtils.isEmpty(certificate)) {
logger.quiet(CERTIFICATE_FILE_NOT_CONFIG);
return null;
}
final String certificatePassword = config.getAuthenticationSetting(CERTIFICATE_PASSWORD);
try {
byte[] cert;
cert = Files.readAllBytes(Paths.get(certificate, new String[0]));
logger.quiet(USE_CERTIFICATE_TO_AUTH + certificate);
return new ApplicationTokenCredentials(clientId, tenantId, cert, certificatePassword, azureEnvironment);
} catch (Exception e) {
logger.quiet(CERTIFICATE_FILE_READ_FAIL + certificate);
}
return null;
}
Aggregations