private static List <SecretKind> LoadSecretKinds(VaultAlias vaultAlias, out List <string> unknownSk)
        {
            SecretKinds       allSecretKinds       = Utils.LoadFromJsonFile <SecretKinds>(Settings.Default.SecretKindsJsonFileLocation);
            List <SecretKind> validatedSecretKinds = new List <SecretKind>(vaultAlias.SecretKinds.Length);

            unknownSk = new List <string>();

            foreach (var secretKind in vaultAlias.SecretKinds)
            {
                SecretKind sk;
                if (allSecretKinds.TryGetValue(secretKind, out sk))
                {
                    validatedSecretKinds.Add(sk);
                }
                else
                {
                    unknownSk.Add(secretKind);
                }
            }

            return(validatedSecretKinds);
        }
Beispiel #2
0
        private static List <SecretKind> LoadSecretKinds(VaultAlias vaultAlias, out List <string> unknownSk)
        {
            SecretKinds       allSecretKinds       = Utils.LoadFromJsonFile <SecretKinds>(Settings.Default.SecretKindsJsonFileLocation);
            List <SecretKind> validatedSecretKinds = new List <SecretKind>(allSecretKinds.Count) ?? new List <SecretKind>(vaultAlias.SecretKinds.Length);

            unknownSk = new List <string>();

            // If there are no SecretKinds in the VaultAliases.json for a vault OR if it's a vault Not in VaultAliases, return ALL SecretKinds.
            if (vaultAlias.SecretKinds == null || (vaultAlias.SecretKinds.Length == 1 && (string)vaultAlias.SecretKinds.GetValue(0) == "Custom"))
            {
                foreach (var key in allSecretKinds.Keys)
                {
                    SecretKind sk;
                    allSecretKinds.TryGetValue(key, out sk);
                    validatedSecretKinds.Add(sk);
                }
            }
            // Otherwise, return just the specified SecretKinds
            else
            {
                foreach (var secretKind in vaultAlias.SecretKinds)
                {
                    SecretKind sk;
                    if (allSecretKinds.TryGetValue(secretKind, out sk))
                    {
                        validatedSecretKinds.Add(sk);
                    }
                    else
                    {
                        unknownSk.Add(secretKind);
                    }
                }
            }

            // Sort the Secret Kinds
            List <SecretKind> orderedValidatedSecretKinds = validatedSecretKinds.OrderBy(o => o.Alias).ToList();

            return(orderedValidatedSecretKinds);
        }