Make the code to parse "primaries" configuration more generic so it can be reused for "parental-agents". (cherry picked from commit 6040c714)