public async Task <RegeneratedSecret> Rekey(TimeSpan requestedValidPeriod) { Logger.LogInformation("Generating a new secret of length {SecretKeyLength}", Configuration.KeyLength); RegeneratedSecret newKey = new RegeneratedSecret() { Expiry = DateTimeOffset.UtcNow + requestedValidPeriod, UserHint = Configuration.UserHint, NewSecretValue = await _cryptographicImplementation.GenerateCryptographicallyRandomSecureString(Configuration.KeyLength) }; var functionsApp = await GetResourceAsync(); if (functionsApp == null) { throw new Exception($"Cannot locate Functions application called '{Configuration.ResourceName}' in group '{Configuration.ResourceGroup}'"); } Logger.LogInformation("Removing previous Function Key '{FunctionKeyName}' from Function '{FunctionName}'", Configuration.FunctionKeyName, Configuration.FunctionName); await functionsApp.RemoveFunctionKeyAsync(Configuration.FunctionName, Configuration.FunctionKeyName); Logger.LogInformation("Adding new Function Key '{FunctionKeyName}' from Function '{FunctionName}'", Configuration.FunctionKeyName, Configuration.FunctionName); await functionsApp.AddFunctionKeyAsync(Configuration.FunctionName, Configuration.FunctionKeyName, newKey.NewSecretValue.GetNormalString()); return(newKey); }
public override async Task <RegeneratedSecret> Rekey(TimeSpan requestedValidPeriod) { Logger.LogInformation("Generating a new secret of length {0}", Configuration.KeyLength); RegeneratedSecret newKey = new RegeneratedSecret() { Expiry = DateTimeOffset.UtcNow + requestedValidPeriod, UserHint = Configuration.UserHint, NewSecretValue = HelperMethods.GenerateCryptographicallySecureString(Configuration.KeyLength) }; var functionsApp = await(await GetAzure()).AppServices.FunctionApps.GetByResourceGroupAsync(ResourceGroup, ResourceName); if (functionsApp == null) { throw new Exception($"Cannot locate Functions application called '{ResourceName}' in group '{ResourceGroup}'"); } Logger.LogInformation("Removing previous Function Key '{0}' from Function '{1}'", Configuration.FunctionKeyName, Configuration.FunctionName); await functionsApp.RemoveFunctionKeyAsync(Configuration.FunctionName, Configuration.FunctionKeyName); Logger.LogInformation("Adding new Function Key '{0}' from Function '{1}'", Configuration.FunctionKeyName, Configuration.FunctionName); await functionsApp.AddFunctionKeyAsync(Configuration.FunctionName, Configuration.FunctionKeyName, newKey.NewSecretValue); return(newKey); }