Exemplo n.º 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);
     });
 }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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]);
        }
Exemplo n.º 4
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;
            }));
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
 private static string GetKeyPath(Srn srn) => $"{srn.Namespace}/{srn.Key.Replace('.', '/')}";
Exemplo n.º 7
0
 public async Task SetAsync(Srn srn, dynamic value)
 {
     srn.ThrowIfNotFullyQualified();
     await ExecuteVaultContext(async() => await _engine.WriteSecretAsync(GetKeyPath(srn), value, null, _mountPoint));
 }
Exemplo n.º 8
0
 public async Task DeleteAsync(Srn srn, string provider = "default")
 => await srn.ToNamespace(this).DeleteAsync(srn.Key, provider);
Exemplo n.º 9
0
 public async Task SetAsync(Srn srn, dynamic value, string provider = "default")
 => await srn.ToNamespace(this).SetAsync(srn.Key, value, provider);
Exemplo n.º 10
0
 public async Task <dynamic> GetAsync(Srn srn, IList <string> providers)
 => await srn.ToNamespace(this).GetAsync(srn.Key, providers);
Exemplo n.º 11
0
 public async Task <dynamic> GetAsync(Srn srn, string provider = "any")
 => await srn.ToNamespace(this).GetAsync(srn.Key, provider);