mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-25 03:41:25 -07:00
Ansible.Basic - add required_by to module spec (#51407)
* Ansible.Basic - add required_by to module spec * fix typo in docs
This commit is contained in:
parent
994063bbf9
commit
de118734e9
4 changed files with 231 additions and 2 deletions
|
@ -83,6 +83,7 @@ namespace Ansible.Basic
|
|||
{ "options", new List<object>() { typeof(Hashtable), typeof(Hashtable) } },
|
||||
{ "removed_in_version", new List<object>() { null, typeof(string) } },
|
||||
{ "required", new List<object>() { false, typeof(bool) } },
|
||||
{ "required_by", new List<object>() { typeof(Hashtable), typeof(Hashtable) } },
|
||||
{ "required_if", new List<object>() { typeof(List<List<object>>), null } },
|
||||
{ "required_one_of", new List<object>() { typeof(List<List<string>>), null } },
|
||||
{ "required_together", new List<object>() { typeof(List<List<string>>), null } },
|
||||
|
@ -792,6 +793,7 @@ namespace Ansible.Basic
|
|||
CheckRequiredTogether(param, (IList)spec["required_together"]);
|
||||
CheckRequiredOneOf(param, (IList)spec["required_one_of"]);
|
||||
CheckRequiredIf(param, (IList)spec["required_if"]);
|
||||
CheckRequiredBy(param, (IDictionary)spec["required_by"]);
|
||||
|
||||
// finally ensure all missing parameters are set to null and handle sub options
|
||||
foreach (DictionaryEntry entry in optionSpec)
|
||||
|
@ -1012,6 +1014,28 @@ namespace Ansible.Basic
|
|||
}
|
||||
}
|
||||
|
||||
private void CheckRequiredBy(IDictionary param, IDictionary requiredBy)
|
||||
{
|
||||
foreach (DictionaryEntry entry in requiredBy)
|
||||
{
|
||||
string key = (string)entry.Key;
|
||||
if (!param.Contains(key))
|
||||
continue;
|
||||
|
||||
List<string> missing = new List<string>();
|
||||
List<string> requires = ParseList(entry.Value).Cast<string>().ToList();
|
||||
foreach (string required in requires)
|
||||
if (!param.Contains(required))
|
||||
missing.Add(required);
|
||||
|
||||
if (missing.Count > 0)
|
||||
{
|
||||
string msg = String.Format("missing parameter(s) required by '{0}': {1}", key, String.Join(", ", missing));
|
||||
FailJson(FormatOptionsContext(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckSubOption(IDictionary param, string key, IDictionary spec)
|
||||
{
|
||||
string type;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue