internal override async Task <Models.SiteInner> SubmitAppSettingsAsync(SiteInner site, CancellationToken cancellationToken = default(CancellationToken)) { if (storageAccountCreatable != null && CreatedResource(storageAccountCreatable.Key) != null) { storageAccountToSet = (IStorageAccount)CreatedResource(storageAccountCreatable.Key); } if (storageAccountToSet == null) { return(await base.SubmitAppSettingsAsync(site, cancellationToken)); } else { var keys = await storageAccountToSet.GetKeysAsync(cancellationToken); var connectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", storageAccountToSet.Name, keys[0].Value); WithAppSetting("AzureWebJobsStorage", connectionString); WithAppSetting("AzureWebJobsDashboard", connectionString); WithAppSetting("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING", connectionString); WithAppSetting("WEBSITE_CONTENTSHARE", SdkContext.RandomResourceName(Name, 32)); // clean up currentStorageAccount = storageAccountToSet; storageAccountToSet = null; storageAccountCreatable = null; return(await base.SubmitAppSettingsAsync(site, cancellationToken)); } }
private async Task GetSharedKeyAsync() { IReadOnlyList <StorageAccountKey> keys = await _storageAccount.GetKeysAsync(); if (keys?.Count == 0) { return; } _primarySharedKey = keys[0].Value; _secondarySharedKey = keys[1].Value; CommandGroups.Add(new HierarchicalResourceCommandGroup( new HierarchicalResourceCommand("Copy primary key", Symbol.Copy, () => { ServiceLocator.SystemService.SetClipboardText(_primarySharedKey); return(Task.CompletedTask); }), new HierarchicalResourceCommand("Copy secondary key", Symbol.Copy, () => { ServiceLocator.SystemService.SetClipboardText(_secondarySharedKey); return(Task.CompletedTask); } ))); foreach (HierarchicalResource child in Children) { if (child is AzureStorageSubAccount sa) { sa.PrimarySharedKey = _primarySharedKey; sa.SecondarySharedKey = _secondarySharedKey; } } }
internal override async Task <Models.SiteInner> SubmitAppSettingsAsync(SiteInner site, CancellationToken cancellationToken = default(CancellationToken)) { if (storageAccountCreatable != null && CreatedResource(storageAccountCreatable.Key) != null) { storageAccountToSet = (IStorageAccount)CreatedResource(storageAccountCreatable.Key); } if (storageAccountToSet == null) { return(await base.SubmitAppSettingsAsync(site, cancellationToken)); } else { AzureEnvironment environment = ResourceUtils.ExtractAzureEnvironment(Manager.RestClient) ?? AzureEnvironment.AzureGlobalCloud; string endpointSuffix = Regex.Replace(environment.StorageEndpointSuffix ?? AzureEnvironment.AzureGlobalCloud.StorageEndpointSuffix, "^\\.*", ""); var servicePlanTask = Manager.AppServicePlans.GetByIdAsync(this.AppServicePlanId()); var keys = await storageAccountToSet.GetKeysAsync(cancellationToken); var connectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1};EndpointSuffix={2}", storageAccountToSet.Name, keys[0].Value, endpointSuffix); AddAppSettingIfNotModified("AzureWebJobsStorage", connectionString); AddAppSettingIfNotModified("AzureWebJobsDashboard", connectionString); if (IsConsumptionAppServicePlan((await servicePlanTask)?.PricingTier)) { AddAppSettingIfNotModified("WEBSITE_CONTENTAZUREFILECONNECTIONSTRING", connectionString); AddAppSettingIfNotModified("WEBSITE_CONTENTSHARE", SdkContext.RandomResourceName(Name, 32)); } // clean up currentStorageAccount = storageAccountToSet; storageAccountToSet = null; storageAccountCreatable = null; return(await base.SubmitAppSettingsAsync(site, cancellationToken)); } }
///GENMHASH:9557699E7EE892CCCC89A074E0915333:A55D3CBCED3C2D7241CB8E96C4D3F217 public async Task BeforeGroupCreateOrUpdateAsync(CancellationToken cancellationToken = default(CancellationToken)) { if (this.importRequestInner != null && this.storageAccount != null) { var storageKeys = await storageAccount.GetKeysAsync(cancellationToken); if (storageKeys == null || storageKeys.Count == 0) { throw new Exception("Failed to retrieve Storage Account Keys"); } var storageAccountKey = storageKeys[0].Value; this.importRequestInner.StorageUri = $"{this.storageAccount?.EndPoints?.Primary?.Blob}{this.importRequestInner.StorageUri}"; this.importRequestInner.StorageKeyType = StorageKeyType.StorageAccessKey; this.importRequestInner.StorageKey = storageAccountKey; } if (this.sqlElasticPoolCreatable != null) { this.parentSqlElasticPool = (SqlElasticPoolImpl)await this.sqlElasticPoolCreatable.CreateAsync(cancellationToken); } else if (this.Inner.ElasticPoolName != null && this.importRequestInner != null) { this.parentSqlElasticPool = (SqlElasticPoolImpl)await this.sqlServerManager.SqlServers.ElasticPools .GetBySqlServerAsync(this.resourceGroupName, this.sqlServerName, this.Inner.ElasticPoolName, cancellationToken); } }
///GENMHASH:E57B7C8F0964999B03C8233B7678D75F:35867B5C8AA1E69EFFB6625C59841587 private async Task <CloudStorageAccount> GetCloudStorageAsync(IStorageAccount storageAccount, CancellationToken cancellationToken = default(CancellationToken)) { var storageAccountKeys = await storageAccount.GetKeysAsync(); var storageAccountkey = storageAccountKeys[0]; return(CloudStorageAccount.Parse($"DefaultEndpointsProtocol=https;AccountName={storageAccount.Name};AccountKey={storageAccountkey.Value};EndpointSuffix=core.Windows.net")); }
public static async Task <string> GetStorageAccountKeyByName(IStorageAccount account, string keyName = "key1", CancellationToken cancellationToken = default) { var keys = await account.GetKeysAsync(cancellationToken); foreach (var curKey in keys) { if (curKey.KeyName == keyName) { return(curKey.Value); } } return(null); }
private async Task <Microsoft.Azure.Management.ContainerRegistry.Fluent.Models.StorageAccountParameters> HandleStorageSettingsAsync(CancellationToken cancellationToken = default(CancellationToken)) { if (this.creatableStorageAccountKey != null) { this.storageAccount = this.CreatedResource(this.creatableStorageAccountKey) as IStorageAccount; } IReadOnlyList <StorageAccountKey> keys = await storageAccount.GetKeysAsync(); StorageAccountParameters storageAccountParameters = new StorageAccountParameters(); storageAccountParameters.Name = storageAccount.Name; storageAccountParameters.AccessKey = keys[0].Value; return(storageAccountParameters); }
protected override Task <IReadOnlyList <StorageAccountKey> > RetrieveCurrentKeyring(IStorageAccount resource, string keyType) => resource.GetKeysAsync();