use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-gradle-plugins by lenala.
the class AzureAuthHelper method getAuthObjFromConfiguration.
/**
* Get Authenticated object by reading app token credentials from gradle.properties
*
* @return Authenticated object if configurations are correct; otherwise return null.
*/
private Authenticated getAuthObjFromConfiguration(final AuthConfiguration config) {
final ApplicationTokenCredentials credential = getAppTokenCredentials();
if (credential == null) {
return null;
}
final Authenticated auth = azureConfigure().authenticate(credential);
if (auth != null) {
logger.quiet(AUTH_WITH_CLIENT_ID + config.getAuthenticationSetting(CLIENT_ID));
}
return auth;
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-tools-for-java by Microsoft.
the class IntegrationTestBase method setUpStep.
public void setUpStep() throws Exception {
if (currentTestName == null) {
currentTestName = name.getMethodName();
} else {
throw new Exception("Setting up another test in middle of a test");
}
addTextReplacementRule(GLOBAL_ENDPOINT, MOCK_URI + "/");
ApplicationTokenCredentials credentials = new TestCredentials();
String defaultSubscription = "";
if (IS_MOCKED) {
defaultSubscription = MOCK_SUBSCRIPTION;
File recordFile = getRecordFile();
ObjectMapper mapper = new ObjectMapper();
try {
testRecord = mapper.readValue(recordFile, TestRecord.class);
} catch (Exception e) {
throw new Exception("Fail read test record: " + e.getMessage());
}
} else {
try {
credentials = ApplicationTokenCredentials.fromFile(new File(azureAuthFile));
} catch (Exception e) {
throw new Exception("Fail to open auth file:" + azureAuthFile);
}
defaultSubscription = credentials.defaultSubscriptionId();
}
interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
if (IS_MOCKED) {
return registerRecordedResponse(chain);
} else {
return chain.proceed(chain.request());
}
}
};
restClient = createRestClient(credentials);
initialize(restClient, defaultSubscription, credentials.domain());
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-tools-for-java by Microsoft.
the class IntegrationTestBase method createRestClient.
private RestClient createRestClient(ApplicationTokenCredentials credentials) {
final RestClient client;
ApplicationTokenCredentials cred = credentials;
if (IS_MOCKED) {
cred = new TestCredentials();
client = new RestClient.Builder().withBaseUrl(MOCK_URI + "/").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(cred).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
} else {
client = new RestClient.Builder().withBaseUrl(GLOBAL_ENDPOINT).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(cred).withLogLevel(LogLevel.BODY_AND_HEADERS).withInterceptor(interceptor).build();
}
return client;
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project azure-tools-for-java by Microsoft.
the class IntegrationTestBase method setUpStep.
public void setUpStep() throws Exception {
if (currentTestName == null) {
currentTestName = name.getMethodName();
} else {
throw new Exception("Setting up another test in middle of a test");
}
addTextReplacementRule(GLOBAL_ENDPOINT, MOCK_URI + "/");
ApplicationTokenCredentials credentials = new TestCredentials();
String defaultSubscription = "";
if (IS_MOCKED) {
defaultSubscription = MOCK_SUBSCRIPTION;
File recordFile = getRecordFile();
ObjectMapper mapper = new ObjectMapper();
try {
testRecord = mapper.readValue(recordFile, TestRecord.class);
} catch (Exception e) {
throw new Exception("Fail read test record: " + e.getMessage());
}
} else {
try {
credentials = ApplicationTokenCredentials.fromFile(new File(azureAuthFile));
} catch (Exception e) {
throw new Exception("Fail to open auth file:" + azureAuthFile);
}
defaultSubscription = credentials.defaultSubscriptionId();
}
interceptor = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
if (IS_MOCKED) {
return registerRecordedResponse(chain);
} else {
return chain.proceed(chain.request());
}
}
};
restClient = createRestClient(credentials);
initialize(restClient, defaultSubscription, credentials.domain());
}
use of com.microsoft.azure.credentials.ApplicationTokenCredentials in project cloudbreak by hortonworks.
the class AzureUseAnExistingSubnetInAnExistingVpcNetworkTest method createNetwork.
@Test
@Parameters({ "networkName", "description", "publicInAccount", "regionName", "resourceGroupName", "vpcName", "vpcSubnet" })
public void createNetwork(String networkName, @Optional("") String description, @Optional("false") boolean publicInAccount, String regionName, @Optional("it-vpc-resource-group") String resourceGroupName, @Optional("it-vpc") String vpcName, @Optional("it-vpc-subnet") String vpcSubnet) {
ApplicationTokenCredentials serviceClientCredentials = new ApplicationTokenCredentials(defaultAccesKey, defaultTenantId, defaultSecretKey, null);
Azure azure = Azure.authenticate(serviceClientCredentials).withSubscription(defaultSubscriptionId);
azure.networks().define(vpcName).withRegion(regionName).withNewResourceGroup(resourceGroupName).withAddressSpace("10.0.0.0/16").withSubnet(vpcSubnet, "10.0.0.0/16").create();
NetworkRequest networkRequest = new NetworkRequest();
networkRequest.setName(networkName);
networkRequest.setDescription(description);
Map<String, Object> map = new HashMap<>();
map.put("networkId", vpcName);
map.put("subnetId", vpcSubnet);
map.put("resourceGroupName", resourceGroupName);
networkRequest.setParameters(map);
networkRequest.setCloudPlatform("AZURE");
// networkJson.setPublicInAccount(publicInAccount);
String id = getCloudbreakClient().networkEndpoint().postPrivate(networkRequest).getId().toString();
getItContext().putContextParam(CloudbreakITContextConstants.NETWORK_ID, id, true);
}
Aggregations