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);
            }
        }
        private Dictionary <StorageKeyKind, string> GetV2Keys(string resourceGroupName, string storageAccountName)
        {
            Microsoft.Azure.Management.Storage.StorageManagementClient storageClient = GetCurrentStorageV2Client(Context);
            var    r  = storageClient.StorageAccounts.ListKeys(resourceGroupName, storageAccountName);
            string k1 = r.StorageAccountKeys.Key1;
            string k2 = r.StorageAccountKeys.Key2;
            Dictionary <StorageKeyKind, String> result = new Dictionary <StorageKeyKind, String>();

            result.Add(StorageKeyKind.Primary, k1);
            result.Add(StorageKeyKind.Secondary, k2);
            return(result);
        }
            protected override async Task ConfigureTestResources(ResourceGroup resourceGroup)
            {
                var storageClient = new StorageManagementClient(new TokenCredentials(authToken))
                {
                    SubscriptionId = subscriptionId
                };
                var storageAccountName = resourceGroupName.Replace("-", "").Substring(0, 20);
                var storageAccount     = await storageClient.StorageAccounts.CreateAsync(resourceGroupName,
                                                                                         accountName : storageAccountName,
                                                                                         new StorageAccountCreateParameters()
                {
                    Sku      = new Sku("Standard_LRS"),
                    Kind     = "Storage",
                    Location = resourceGroupLocation
                }
                                                                                         );

                var keys = await storageClient.StorageAccounts.ListKeysAsync(resourceGroupName, storageAccountName);

                var linuxSvcPlan = await webMgmtClient.AppServicePlans.BeginCreateOrUpdateAsync(resourceGroupName,
                                                                                                $"{resourceGroupName}-linux-asp",
                                                                                                new AppServicePlan(resourceGroupLocation)
                {
                    Sku      = new SkuDescription("B1", "Basic"),
                    Kind     = "linux",
                    Reserved = true
                }
                                                                                                );

                site = await webMgmtClient.WebApps.BeginCreateOrUpdateAsync(resourceGroupName,
                                                                            $"{resourceGroupName}-linux",
                                                                            new Site(resourceGroupLocation)
                {
                    ServerFarmId = linuxSvcPlan.Id,
                    Kind         = "functionapp,linux",
                    Reserved     = true,
                    SiteConfig   = new SiteConfig
                    {
                        AlwaysOn              = true,
                        LinuxFxVersion        = "DOTNET|6.0",
                        Use32BitWorkerProcess = true,
                        AppSettings           = new List <NameValuePair>
                        {
                            new NameValuePair("FUNCTIONS_WORKER_RUNTIME", "dotnet"),
                            new NameValuePair("FUNCTIONS_EXTENSION_VERSION", "~4"),
                            new NameValuePair("AzureWebJobsStorage", $"DefaultEndpointsProtocol=https;AccountName={storageAccount.Name};AccountKey={keys.Keys.First().Value};EndpointSuffix=core.windows.net")
                        }
                    }
                }
                                                                            );
            }
Пример #4
0
        private async void OKbutton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(subscriptionComboBox.Text) && !String.IsNullOrEmpty(resourceGroupcomboBox.Text) && !String.IsNullOrEmpty(storageAccountcomboBox.Text))
                {
                    if (storageAccountcomboBox.SelectedItem == null)
                    {
                        var subObject          = (AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem;
                        var azureARMAuthResult = AuthenticateHelper.RefreshTokenByAuthority(subObject.Authority, Properties.Settings.Default.appIdURI);
                        var authToken          = azureARMAuthResult.AccessToken;
                        var token = new Microsoft.Rest.TokenCredentials(authToken);
                        var storageManagementClient = new Microsoft.Azure.Management.Storage.StorageManagementClient(new Uri(Properties.Settings.Default.appIdURI), token);
                        storageManagementClient.SubscriptionId = subObject.SubscriptionId;
                        var result = await storageManagementClient.StorageAccounts.CheckNameAvailabilityAsync(storageAccountcomboBox.Text);

                        if (!(result.NameAvailable.Value))
                        {
                            var messageBoxResult = System.Windows.Forms.MessageBox.Show(
                                "Storage account name is not available in this subscription. Please choose another name", "Name not available",
                                System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                        }
                        else
                        {
                            createNewStorageAccount  = true;
                            storageSubID             = ((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId;
                            storageResourceGroupName = resourceGroupcomboBox.Text;
                            storageAccountName       = storageAccountcomboBox.Text;
                            region            = regionComboBox.Text;
                            this.DialogResult = true;
                            this.Close();
                        }
                    }
                    else
                    {
                        storageSubID             = ((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId;
                        storageResourceGroupName = resourceGroupcomboBox.SelectedItem.ToString();
                        storageAccountName       = storageAccountcomboBox.Text;
                        this.DialogResult        = true;
                        this.Close();
                    }
                }
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
        public static async Task <Boolean> CreateStorageAccount(String authority, AutomationManagementClient automationManagementClient, string resourceGroupName, AutomationAccount account, string storageResourceGroup, string storageSubID, string storageAccount, string storageRGLocation)
        {
            try
            {
                // Get the token for the tenant on this subscription.
                var cloudtoken               = AuthenticateHelper.RefreshTokenByAuthority(authority, Properties.Settings.Default.appIdURI);
                var subscriptionCreds        = new TokenCloudCredentials(storageSubID, cloudtoken.AccessToken);
                var resourceManagementClient = new ResourceManagementClient(subscriptionCreds, new Uri(Properties.Settings.Default.appIdURI));

                // Check if the resource group exists, otherwise create it.
                var rgExists = resourceManagementClient.ResourceGroups.CheckExistence(storageResourceGroup);
                if (!(rgExists.Exists))
                {
                    var resourceGroup = new ResourceGroup {
                        Location = storageRGLocation
                    };
                    await resourceManagementClient.ResourceGroups.CreateOrUpdateAsync(storageResourceGroup, resourceGroup);
                }

                // Create storage client and set subscription to work against
                var token = new Microsoft.Rest.TokenCredentials(cloudtoken.AccessToken);
                var storageManagementClient = new Microsoft.Azure.Management.Storage.StorageManagementClient(new Uri(Properties.Settings.Default.appIdURI), token);
                storageManagementClient.SubscriptionId = storageSubID;

                // Use Standard local replication as the sku since it is not critical to keep these modules replicated
                var storageParams = new StorageAccountCreateParameters()
                {
                    Location = storageRGLocation,
                    Kind     = Kind.Storage,
                    Sku      = new Microsoft.Azure.Management.Storage.Models.Sku(SkuName.StandardLRS)
                };

                // Create storage account
                CancellationToken cancelToken = new CancellationToken();
                await storageManagementClient.StorageAccounts.CreateAsync(storageResourceGroup, storageAccount, storageParams, cancelToken);
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
            return(true);
        }
Пример #6
0
        private async void subscriptionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var subObject          = (AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem;
            var azureARMAuthResult = AuthenticateHelper.RefreshTokenByAuthority(subObject.Authority, Properties.Settings.Default.appIdURI);

            authority = subObject.Authority;
            var authToken = azureARMAuthResult.AccessToken;
            var token     = new Microsoft.Rest.TokenCredentials(authToken);
            var storageManagementClient = new Microsoft.Azure.Management.Storage.StorageManagementClient(new Uri(Properties.Settings.Default.appIdURI), token);

            storageManagementClient.SubscriptionId = subObject.SubscriptionId;
            resourceGroupcomboBox.Items.Clear();
            try
            {
                storageAccounts = storageManagementClient.StorageAccounts.List();
                foreach (var storageAccount in storageAccounts)
                {
                    var startPosition = storageAccount.Id.IndexOf("/resourceGroups/");
                    var endPosition   = storageAccount.Id.IndexOf("/", startPosition + 16);
                    var resourceGroup = storageAccount.Id.Substring(startPosition + 16, endPosition - startPosition - 16);
                    if (resourceGroupcomboBox.Items.IndexOf(resourceGroup) == -1)
                    {
                        resourceGroupcomboBox.Items.Add(resourceGroup);
                    }
                }
                var cloudtoken                = AuthenticateHelper.RefreshTokenByAuthority(authority, Properties.Settings.Default.appIdURI);
                var subscriptionCreds         = new TokenCloudCredentials(((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId, cloudtoken.AccessToken);
                var resourceManagementClient  = new Microsoft.Azure.Subscriptions.SubscriptionClient(subscriptionCreds, new Uri(Properties.Settings.Default.appIdURI));
                CancellationToken cancelToken = new CancellationToken();
                var subscriptionRegions       = await resourceManagementClient.Subscriptions.ListLocationsAsync(((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId, cancelToken);

                regionComboBox.ItemsSource       = subscriptionRegions.Locations;
                regionComboBox.DisplayMemberPath = "Name";
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }