Ejemplo n.º 1
0
        public virtual FunctionSecrets GetFunctionSecrets(string functionName)
        {
            if (string.IsNullOrEmpty(functionName))
            {
                throw new ArgumentNullException("functionName");
            }

            functionName = functionName.ToLowerInvariant();

            return(_secretsMap.GetOrAdd(functionName, (n) =>
            {
                FunctionSecrets secrets;
                string secretFileName = string.Format(CultureInfo.InvariantCulture, "{0}.json", functionName);
                string secretFilePath = Path.Combine(_secretsPath, secretFileName);
                if (File.Exists(secretFilePath))
                {
                    // load the secrets file
                    string secretsJson = File.ReadAllText(secretFilePath);
                    secrets = JsonConvert.DeserializeObject <FunctionSecrets>(secretsJson);
                }
                else
                {
                    // initialize with new secrets and save it
                    secrets = new FunctionSecrets
                    {
                        Key = GenerateSecretString()
                    };

                    File.WriteAllText(secretFilePath, JsonConvert.SerializeObject(secrets, Formatting.Indented));
                }

                return secrets;
            }));
        }
 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);
 }
Ejemplo n.º 3
0
        public virtual FunctionSecrets GetFunctionSecrets(string functionName)
        {
            functionName = functionName.ToLowerInvariant();

            return(_secretsMap.GetOrAdd(functionName, (n) =>
            {
                FunctionSecrets secrets;
                string secretFileName = string.Format("{0}.json", functionName);
                string secretFilePath = Path.Combine(_secretsPath, secretFileName);
                if (File.Exists(secretFilePath))
                {
                    // load the secrets file
                    string secretsJson = File.ReadAllText(secretFilePath);
                    secrets = JsonConvert.DeserializeObject <FunctionSecrets>(secretsJson);
                }
                else
                {
                    // initialize with empty instance
                    secrets = new FunctionSecrets();
                }

                return secrets;
            }));
        }
        public virtual FunctionSecrets GetFunctionSecrets(string functionName)
        {
            functionName = functionName.ToLowerInvariant();

            return _secretsMap.GetOrAdd(functionName, (n) =>
            {
                FunctionSecrets secrets;
                string secretFileName = string.Format("{0}.json", functionName);
                string secretFilePath = Path.Combine(_secretsPath, secretFileName);
                if (File.Exists(secretFilePath))
                {
                    // load the secrets file
                    string secretsJson = File.ReadAllText(secretFilePath);
                    secrets = JsonConvert.DeserializeObject<FunctionSecrets>(secretsJson);
                }
                else
                {
                    // initialize with empty instance
                    secrets = new FunctionSecrets();
                }

                return secrets;
            });
        }
        public virtual FunctionSecrets GetFunctionSecrets(string functionName)
        {
            if (string.IsNullOrEmpty(functionName))
            {
                throw new ArgumentNullException("functionName");
            }

            functionName = functionName.ToLowerInvariant();

            return _secretsMap.GetOrAdd(functionName, (n) =>
            {
                FunctionSecrets secrets;
                string secretFileName = string.Format(CultureInfo.InvariantCulture, "{0}.json", functionName);
                string secretFilePath = Path.Combine(_secretsPath, secretFileName);
                if (File.Exists(secretFilePath))
                {
                    // load the secrets file
                    string secretsJson = File.ReadAllText(secretFilePath);
                    secrets = JsonConvert.DeserializeObject<FunctionSecrets>(secretsJson);
                }
                else
                {
                    // initialize with new secrets and save it
                    secrets = new FunctionSecrets
                    {
                        Key = GenerateSecretString()
                    };

                    File.WriteAllText(secretFilePath, JsonConvert.SerializeObject(secrets, Formatting.Indented));
                }

                return secrets;
            });
        }