Example #1
0
        public async Task <KeyOperationResult> AddOrUpdateFunctionSecretAsync(string secretName, string secret, string keyScope, ScriptSecretsType secretsType)
        {
            using (_metricsLogger.LatencyEvent(GetMetricEventName(MetricEventNames.SecretManagerAddOrUpdateFunctionSecret), GetFunctionName(keyScope, secretsType)))
            {
                Func <ScriptSecrets> secretsFactory = null;

                if (secretsType == ScriptSecretsType.Function)
                {
                    secretsFactory = () => new FunctionSecrets(new List <Key>());
                }
                else if (secretsType == ScriptSecretsType.Host)
                {
                    secretsType    = ScriptSecretsType.Host;
                    secretsFactory = GenerateHostSecrets;
                }
                else
                {
                    throw new NotSupportedException($"Secrets type {secretsType.ToString("G")} not supported.");
                }

                KeyOperationResult result = await AddOrUpdateSecretAsync(secretsType, keyScope, secretName, secret, secretsFactory);

                _logger.LogInformation(string.Format(Resources.TraceAddOrUpdateFunctionSecret, secretsType, secretName, keyScope ?? "host", result.Result));

                return(result);
            }
        }
        public async Task <KeyOperationResult> AddOrUpdateFunctionSecretAsync(string secretName, string secret, string keyScope, ScriptSecretsType secretsType)
        {
            Func <ScriptSecrets> secretsFactory = null;

            if (secretsType == ScriptSecretsType.Function)
            {
                secretsFactory = () => new FunctionSecrets(new List <Key>());
            }
            else if (secretsType == ScriptSecretsType.Host)
            {
                secretsType    = ScriptSecretsType.Host;
                secretsFactory = GenerateHostSecrets;
            }
            else
            {
                throw new NotSupportedException($"Secrets type {secretsType.ToString("G")} not supported.");
            }

            KeyOperationResult result = await AddOrUpdateSecretAsync(secretsType, keyScope, secretName, secret, secretsFactory);

            string message = string.Format(Resources.TraceAddOrUpdateFunctionSecret, secretsType, secretName, keyScope ?? "host", result.Result);

            _traceWriter.Info(message);
            _logger?.LogInformation(message);

            return(result);
        }
Example #3
0
        public KeyOperationResult AddOrUpdateFunctionSecret(string secretName, string secret, string functionName = null)
        {
            string               secretsFilePath;
            ScriptSecretsType    secretsType;
            Func <ScriptSecrets> secretsFactory = null;

            if (functionName != null)
            {
                secretsFilePath = GetFunctionSecretsFilePath(functionName);
                secretsType     = ScriptSecretsType.Function;
                secretsFactory  = () => new FunctionSecrets(new List <Key>());
            }
            else
            {
                secretsFilePath = _hostSecretsPath;
                secretsType     = ScriptSecretsType.Host;
                secretsFactory  = GenerateHostSecrets;
            }

            KeyOperationResult result = AddOrUpdateSecret(secretsType, secretsFilePath, secretName, secret, secretsFactory);

            _traceWriter.InfoFormat(Resources.TraceAddOrUpdateFunctionSecret, secretsType, secretName, functionName ?? "host", result.Result);

            return(result);
        }
        public async Task <KeyOperationResult> AddOrUpdateFunctionSecretAsync(string secretName, string secret, string functionName = null)
        {
            ScriptSecretsType    secretsType;
            Func <ScriptSecrets> secretsFactory = null;

            if (functionName != null)
            {
                secretsType    = ScriptSecretsType.Function;
                secretsFactory = () => new FunctionSecrets(new List <Key>());
            }
            else
            {
                secretsType    = ScriptSecretsType.Host;
                secretsFactory = GenerateHostSecrets;
            }

            KeyOperationResult result = await AddOrUpdateSecretAsync(secretsType, functionName, secretName, secret, secretsFactory);

            _traceWriter.InfoFormat(Resources.TraceAddOrUpdateFunctionSecret, secretsType, secretName, functionName ?? "host", result.Result);

            return(result);
        }