コード例 #1
0
        public async Task DeleteAsync(Srn srn)
        {
            if (!srn.HasKey())
            {
                // we're deleting the namespace itself
                _cache.Remove(srn.Namespace);
                _watcher.EnableRaisingEvents = false;
                File.Delete(BuildPath(srn.Namespace));
                _watcher.EnableRaisingEvents = true;

                return;
            }

            await SetAsync(srn, null);
        }
コード例 #2
0
        public async Task <dynamic> GetAsync(Srn srn)
        {
            if (!srn.HasNamespace())
            {
                // Retrieve all namespaces
                return(Directory.GetFiles(_servicePath).Select(Path.GetFileNameWithoutExtension));
            }

            var obj = await GetCacheDictAsync(srn.Namespace);

            if (!srn.HasKey())
            {
                return(obj);
            }

            return(obj?[srn.Key]);
        }
コード例 #3
0
        public async Task <dynamic> GetAsync(Srn srn)
        {
            return(await ExecuteVaultContext(async() =>
            {
                // List all namespaces
                if (!srn.HasNamespace())
                {
                    return (await _engine.ReadSecretPathsAsync("/", _mountPoint))?.Data.Keys;
                }

                // List all keys in namespace (non-recursive, though!)
                if (!srn.HasKey())
                {
                    return (await _engine.ReadSecretPathsAsync($"/{srn.Namespace}", _mountPoint))?.Data.Keys;
                }

                return (await _engine.ReadSecretAsync(GetKeyPath(srn), null, _mountPoint))?.Data.Data;
            }));
        }
コード例 #4
0
        public async Task SetAsync(Srn srn, dynamic value)
        {
            if (!srn.HasNamespace() || !srn.HasKey())
            {
                throw new Exception("Setting namespaces directly is not supported.");
            }

            var obj = await GetCacheDictAsync(srn.Namespace, true);

            if (obj == null)
            {
                return;
            }

            obj[srn.Key] = value;

            // Save the JSON file.
            _watcher.EnableRaisingEvents = false;
            await File.WriteAllTextAsync(BuildPath(srn.Namespace), JsonConvert.SerializeObject(obj));

            _watcher.EnableRaisingEvents = true;
        }