public virtual HostSecrets GetHostSecrets() { if (_hostSecrets == null) { string secretFilePath = Path.Combine(_secretsPath, "host.json"); if (File.Exists(secretFilePath)) { // load the secrets file string secretsJson = File.ReadAllText(secretFilePath); _hostSecrets = JsonConvert.DeserializeObject<HostSecrets>(secretsJson); } else { // initialize with new secrets and save it _hostSecrets = new HostSecrets { MasterKey = GenerateSecretString(), FunctionKey = GenerateSecretString() }; File.WriteAllText(secretFilePath, JsonConvert.SerializeObject(_hostSecrets, Formatting.Indented)); } } return _hostSecrets; }
public virtual HostSecrets GetHostSecrets() { if (_hostSecrets == null) { string secretFilePath = Path.Combine(_secretsPath, "host.json"); if (File.Exists(secretFilePath)) { // load the secrets file string secretsJson = File.ReadAllText(secretFilePath); _hostSecrets = JsonConvert.DeserializeObject <HostSecrets>(secretsJson); } else { // initialize with new secrets and save it _hostSecrets = new HostSecrets { MasterKey = GenerateSecretString(), FunctionKey = GenerateSecretString() }; File.WriteAllText(secretFilePath, JsonConvert.SerializeObject(_hostSecrets, Formatting.Indented)); } } return(_hostSecrets); }
private void OnChanged(object sender, FileSystemEventArgs e) { // clear the cached secrets if they exist // they'll be reloaded on demand next time // they are needed string name = Path.GetFileNameWithoutExtension(e.FullPath).ToLowerInvariant(); if (name == "host") { _hostSecrets = null; } else { FunctionSecrets secrets; _secretsMap.TryRemove(name, out secrets); } }
public virtual HostSecrets GetHostSecrets() { if (_hostSecrets == null) { string secretFilePath = Path.Combine(_secretsPath, "host.json"); if (File.Exists(secretFilePath)) { // load the secrets file string secretsJson = File.ReadAllText(secretFilePath); _hostSecrets = JsonConvert.DeserializeObject <HostSecrets>(secretsJson); } else { // initialize with empty instance _hostSecrets = new HostSecrets(); } } return(_hostSecrets); }
public AuthorizationLevelAttributeTests() { _actionContext = new HttpActionContext(); HttpControllerContext controllerContext = new HttpControllerContext(); _actionContext.ControllerContext = controllerContext; HttpConfiguration httpConfig = new HttpConfiguration(); controllerContext.Configuration = httpConfig; Mock<IDependencyResolver> mockDependencyResolver = new Mock<IDependencyResolver>(MockBehavior.Strict); httpConfig.DependencyResolver = mockDependencyResolver.Object; _mockSecretManager = new Mock<SecretManager>(MockBehavior.Strict); _hostSecrets = new HostSecrets { MasterKey = TestMasterKeyValue, FunctionKey = TestHostFunctionKeyValue }; _mockSecretManager.Setup(p => p.GetHostSecrets()).Returns(_hostSecrets); _functionSecrets = new FunctionSecrets { Key = TestFunctionKeyValue }; _mockSecretManager.Setup(p => p.GetFunctionSecrets(It.IsAny<string>())).Returns(_functionSecrets); mockDependencyResolver.Setup(p => p.GetService(typeof(SecretManager))).Returns(_mockSecretManager.Object); }
public virtual HostSecrets GetHostSecrets() { if (_hostSecrets == null) { string secretFilePath = Path.Combine(_secretsPath, "host.json"); if (File.Exists(secretFilePath)) { // load the secrets file string secretsJson = File.ReadAllText(secretFilePath); _hostSecrets = JsonConvert.DeserializeObject<HostSecrets>(secretsJson); } else { // initialize with empty instance _hostSecrets = new HostSecrets(); } } return _hostSecrets; }
private void OnChanged(object sender, FileSystemEventArgs e) { // clear the cached secrets if they exist // they'll be reloaded on demand next time // they are needed string name = Path.GetFileNameWithoutExtension(e.FullPath).ToLowerInvariant(); if (name == "host") { _hostSecrets = null; } else { FunctionSecrets secrets; _secretsMap.TryRemove(name, out secrets); } }