private IHttpActionResult AddOrUpdateFunctionSecret(string keyName, string value, string functionName = null)
        {
            if (functionName != null &&
                !_scriptHostManager.Instance.Functions.Any(f => string.Equals(f.Name, functionName, StringComparison.OrdinalIgnoreCase)))
            {
                return(NotFound());
            }

            KeyOperationResult operationResult;

            if (functionName == null && string.Equals(keyName, MasterKeyName, StringComparison.OrdinalIgnoreCase))
            {
                operationResult = _secretManager.SetMasterKey(value);
            }
            else
            {
                operationResult = _secretManager.AddOrUpdateFunctionSecret(keyName, value, functionName);
            }

            _traceWriter.VerboseFormat(Resources.TraceKeysApiSecretChange, keyName, functionName ?? "host", operationResult.Result);

            switch (operationResult.Result)
            {
            case OperationResult.Created:
            {
                var keyResponse = ApiModelUtility.CreateApiModel(new { name = keyName, value = operationResult.Secret }, Request);
                return(Created(ApiModelUtility.GetBaseUri(Request), keyResponse));
            }

            case OperationResult.Updated:
            {
                var keyResponse = ApiModelUtility.CreateApiModel(new { name = keyName, value = operationResult.Secret }, Request);
                return(Ok(keyResponse));
            }

            case OperationResult.NotFound:
                return(NotFound());

            case OperationResult.Conflict:
                return(Conflict());

            default:
                return(InternalServerError());
            }
        }