Especially so that even if region is not defined in ~/.aws/credentials but is defined in ~/.aws/config, we can still create AWSCredentials with that region value.
The parsing which was previously done by the AWSCredentialsFileParser class is now handled via:
A AWSProfileConfig class, used to parse any AWS user config file—be it ~/.aws/credentials as before, or ~/.aws/config (new)—and collect all the key/value pairs of each profile found in those files.
The AWSCredentials class can then now be constructed from an array of those AWSProfileConfig objects, combining the values for a profile parsed from different files if needed
I've then updated the tests to account for more scenarios combining those.
[!Note]
While the ~/.aws/credentials and ~/.aws/config files are very similar, they use slightly different format for profile sections, with the ~/.aws/config file listing profiles as [profile <profilename>]—except for the special [default] one—and potentially having other section types, like [services <…>] or [sso-session <…>] too.
What
Especially so that even if
region
is not defined in~/.aws/credentials
but is defined in~/.aws/config
, we can still createAWSCredentials
with thatregion
value.Fixes https://github.com/Automattic/hostmgr/issues/83
How
The parsing which was previously done by the
AWSCredentialsFileParser
class is now handled via:AWSProfileConfig
class, used to parse any AWS user config file—be it~/.aws/credentials
as before, or~/.aws/config
(new)—and collect all the key/value pairs of each profile found in those files.AWSCredentials
class can then now be constructed from an array of thoseAWSProfileConfig
objects, combining the values for a profile parsed from different files if neededI've then updated the tests to account for more scenarios combining those.