use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class AuthMethodManager method loadSettings.
@AzureOperation(name = "account|auth_setting.load", type = AzureOperation.Type.TASK)
private static AuthMethodDetails loadSettings() {
System.out.println("loading authMethodDetails...");
try {
String json = AzureStoreManager.getInstance().getIdeStore().getProperty(ACCOUNT, AUTH_METHOD_DETAIL, "");
if (StringUtils.isBlank(json)) {
FileStorage fs = new FileStorage(FILE_NAME_AUTH_METHOD_DETAILS, CommonSettings.getSettingsBaseDir());
byte[] data = fs.read();
json = new String(data);
AzureStoreManager.getInstance().getIdeStore().setProperty(ACCOUNT, AUTH_METHOD_DETAIL, json);
fs.removeFile();
}
if (StringUtils.isBlank(json)) {
System.out.println("No auth method details are saved.");
return new AuthMethodDetails();
}
return JsonHelper.deserialize(AuthMethodDetails.class, json);
} catch (IOException ignored) {
System.out.println("Failed to loading authMethodDetails settings. Use defaults.");
return new AuthMethodDetails();
}
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class AuthMethodManager method getAzureClient.
@NotNull
@AzureOperation(name = "common|rest_client.create", params = { "sid" }, type = AzureOperation.Type.TASK)
public Azure getAzureClient(String sid) {
final AzureManager manager = getAzureManager();
if (manager != null) {
final Azure azure = manager.getAzure(sid);
if (azure != null) {
return azure;
}
}
final String error = "Failed to connect Azure service with current account";
final String action = "Confirm you have already signed in with subscription: " + sid;
final String errorCode = "001";
throw new AzureToolkitRuntimeException(error, null, action, errorCode);
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class FileUtil method zipFiles.
/**
* Utility method to zip the given collection source files to the destination file.
* @param sourceFiles source files array
* @param targetZipFile ZIP file that will be created or overwritten
*/
@AzureOperation(name = "common|artifact.zip_files", params = { "targetZipFile.getName()" }, type = AzureOperation.Type.TASK)
public static void zipFiles(@NotNull final File[] sourceFiles, @NotNull final File targetZipFile) throws Exception {
ensureValidZipSourceAndTarget(sourceFiles, targetZipFile);
final FileOutputStream fos = new FileOutputStream(targetZipFile);
final ZipOutputStream zipOut = new ZipOutputStream(fos);
try {
for (final File file : sourceFiles) {
addToZipFile(file, zipOut);
}
} finally {
if (zipOut != null) {
zipOut.close();
}
if (fos != null) {
fos.close();
}
}
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class SubscriptionManager method loadSubscriptions.
@AzureOperation(name = "account|subscription.load_cache", type = AzureOperation.Type.TASK)
public static List<SubscriptionDetail> loadSubscriptions() {
System.out.println("SubscriptionManager.loadSubscriptions()");
try {
String json = AzureStoreManager.getInstance().getIdeStore().getProperty(TelemetryConstants.ACCOUNT, "subscription_details");
if (StringUtils.isBlank(json)) {
final FileStorage file = new FileStorage(FILE_NAME_SUBSCRIPTIONS_DETAILS, CommonSettings.getSettingsBaseDir());
final byte[] data = file.read();
json = new String(data, StandardCharsets.UTF_8);
file.removeFile();
AzureStoreManager.getInstance().getIdeStore().setProperty(TelemetryConstants.ACCOUNT, "subscriptions_json", json);
}
if (json.isEmpty()) {
System.out.println("subscription details is empty");
return Collections.emptyList();
}
final SubscriptionDetail[] sda = JsonHelper.deserialize(SubscriptionDetail[].class, json);
return new ArrayList<>(Arrays.asList(sda));
} catch (final IOException e) {
final String error = "Failed to load local cached subscriptions";
final String action = "Retry later or logout to clear local cached subscriptions";
throw new AzureToolkitRuntimeException(error, e);
}
}
use of com.microsoft.azure.toolkit.lib.common.operation.AzureOperation in project azure-tools-for-java by Microsoft.
the class AzureMvpModel method listLocationsBySubscriptionId.
/**
* List Location by Subscription ID.
*
* @param sid subscription Id
* @return List of Location instances
*/
@AzureOperation(name = "common|region.list.subscription", params = { "sid" }, type = AzureOperation.Type.SERVICE)
public List<Region> listLocationsBySubscriptionId(String sid) {
List<Region> locations = new ArrayList<>();
Subscription subscription = getSubscriptionById(sid);
try {
locations.addAll(az(AzureAccount.class).listRegions(subscription.getId()));
} catch (Exception e) {
e.printStackTrace();
}
Collections.sort(locations, getComparator(Region::getName));
return locations;
}
Aggregations