public static async Task DeleteCloudModule(AutomationModule module, AutomationManagementClient automationManagementClient, string resourceGroupName, string accountName) { CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(TIMEOUT_MS); await automationManagementClient.Modules.DeleteAsync(resourceGroupName, accountName, module.Name, cts.Token); }
public static async Task UploadModule(AuthenticationResult auth, AutomationModule module, AutomationManagementClient automationManagementClient, string resourceGroupName, AutomationAccount account, string storageResourceGroup, string storageSubID, string storageAccount) { // Update the module from powershell gallery if it exists, otherwise upload to storage if (!(await UploadFromGalleryIfExists(module.Name, module.localVersion, automationManagementClient, resourceGroupName, account))) { // Create storage client and set subscription to work against var token = new Microsoft.Rest.TokenCredentials(auth.AccessToken); var storageManagementClient = new Microsoft.Azure.Management.Storage.StorageManagementClient(new Uri(Properties.Settings.Default.appIdURI), token); storageManagementClient.SubscriptionId = storageSubID; // Get storage key and set up connection to storage account var storageKeys = storageManagementClient.StorageAccounts.ListKeys(storageResourceGroup, storageAccount); var storageKey = storageKeys.Keys.FirstOrDefault().Value; var storageConnection = "DefaultEndpointsProtocol=https;AccountName=" + storageAccount + ";AccountKey=" + storageKey; CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(storageConnection); // Zip and upload module to storage account var zipModule = ZipModuleFolder(module.localModulePath, module.Name); var blobClient = cloudStorageAccount.CreateCloudBlobClient(); await UploadModuleToStorageAccount(blobClient, Constants.moduleContainer, zipModule, module.Name.ToLower()); // Get sas token and upload to automation account var SaSURI = await GetSASToken(blobClient, Constants.moduleContainer, module.Name.ToLower()); await UploadModuleToAutomationAccount(module.Name, automationManagementClient, resourceGroupName, account, SaSURI); } }
public static void DeleteLocalModule(AutomationModule module) { Directory.Delete(module.localModulePath, true); }