use of com.microsoft.azure.AzureEnvironment in project azure-sdk-for-java by Azure.
the class CertificateCredentialImpl method exportAuthFile.
void exportAuthFile(ServicePrincipalImpl servicePrincipal) {
if (authFile == null) {
return;
}
RestClient restClient = servicePrincipal.manager().roleInner().restClient();
AzureEnvironment environment = null;
if (restClient.credentials() instanceof AzureTokenCredentials) {
environment = ((AzureTokenCredentials) restClient.credentials()).environment();
} else {
String baseUrl = restClient.retrofit().baseUrl().toString();
for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) {
if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) {
environment = env;
}
}
if (environment == null) {
throw new IllegalArgumentException("Unknown resource manager endpoint " + baseUrl);
}
}
StringBuilder builder = new StringBuilder();
builder.append(String.format("client=%s", servicePrincipal.applicationId())).append("\n");
builder.append(String.format("certificate=%s", privateKeyPath)).append("\n");
builder.append(String.format("certificatePassword=%s", privateKeyPassword)).append("\n");
builder.append(String.format("tenant=%s", servicePrincipal.manager().tenantId())).append("\n");
builder.append(String.format("subscription=%s", servicePrincipal.assignedSubscription)).append("\n");
builder.append(String.format("authURL=%s", normalizeAuthFileUrl(environment.activeDirectoryEndpoint()))).append("\n");
builder.append(String.format("baseURL=%s", normalizeAuthFileUrl(environment.resourceManagerEndpoint()))).append("\n");
builder.append(String.format("graphURL=%s", normalizeAuthFileUrl(environment.graphEndpoint()))).append("\n");
builder.append(String.format("managementURI=%s", normalizeAuthFileUrl(environment.managementEndpoint())));
try {
authFile.write(builder.toString().getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.microsoft.azure.AzureEnvironment in project azure-sdk-for-java by Azure.
the class PasswordCredentialImpl method exportAuthFile.
void exportAuthFile(ServicePrincipalImpl servicePrincipal) {
if (authFile == null) {
return;
}
RestClient restClient = servicePrincipal.manager().roleInner().restClient();
AzureEnvironment environment = null;
if (restClient.credentials() instanceof AzureTokenCredentials) {
environment = ((AzureTokenCredentials) restClient.credentials()).environment();
} else {
String baseUrl = restClient.retrofit().baseUrl().toString();
for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) {
if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) {
environment = env;
}
}
if (environment == null) {
throw new IllegalArgumentException("Unknown resource manager endpoint " + baseUrl);
}
}
StringBuilder builder = new StringBuilder();
builder.append(String.format("client=%s", servicePrincipal.applicationId())).append("\n");
builder.append(String.format("key=%s", value())).append("\n");
builder.append(String.format("tenant=%s", servicePrincipal.manager().tenantId())).append("\n");
builder.append(String.format("subscription=%s", servicePrincipal.assignedSubscription)).append("\n");
builder.append(String.format("authURL=%s", normalizeAuthFileUrl(environment.activeDirectoryEndpoint()))).append("\n");
builder.append(String.format("baseURL=%s", normalizeAuthFileUrl(environment.resourceManagerEndpoint()))).append("\n");
builder.append(String.format("graphURL=%s", normalizeAuthFileUrl(environment.graphEndpoint()))).append("\n");
builder.append(String.format("managementURI=%s", normalizeAuthFileUrl(environment.managementEndpoint())));
try {
authFile.write(builder.toString().getBytes());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations