示例#1
0
 public async Task DeleteAsync(Srn srn)
 {
     // TODO: need to find out how to get version
     if (!srn.HasNamespace())
     {
         throw new SrnException("Performing a mount point reset is not yet supported.");
     }
     await ExecuteVaultContext(async() =>
     {
         await _engine.DestroySecretAsync(GetKeyPath(srn), new List <int> {
             0
         }, _mountPoint);
         return(Task.CompletedTask);
     });
 }
示例#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;
        }