Skip to content

Add config file support for config resolution#729

Open
ubaskota wants to merge 2 commits into
smithy-lang:config_integration_implementationfrom
ubaskota:config_file_support
Open

Add config file support for config resolution#729
ubaskota wants to merge 2 commits into
smithy-lang:config_integration_implementationfrom
ubaskota:config_file_support

Conversation

@ubaskota

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:
Add support for parsing and merging AWS config and credentials files (~/.aws/config and ~/.aws/credentials) as part of the config resolution pipeline.

Changes:

  • Custom line-by-line parser that handles inline comments, sub-properties, and property continuations
  • Standardizer that normalizes section prefixes, handles [default] vs [profile default] precedence, and separates
    profiles/sso-sessions/services
  • ParsedConfigFile class for querying the merged result
  • Async config loading with path resolution from environment variables and defaults
  • Added support to run conformance tests (config-file-parser-tests.json and config-file-location-tests.json)+ unit tests for the query layer and file I/O edge cases

Testing:

  • Verified that the newly added and existing tests pass
  • Manually tested against a real ~/.aws/config file to verify end-to-end parsing behavior

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@ubaskota ubaskota requested a review from a team as a code owner June 24, 2026 18:56
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/__init__.py Outdated
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/__init__.py Outdated
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/file_parser.py Outdated
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/__init__.py
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/file_parser.py Outdated
Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/file_parser.py
from smithy_aws_core.config.exceptions import ConfigParseError

# Type aliases
type PropertyValue = str | dict[str, str]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Discussion]

Instead of having ProfileProperties, a ProfileMap could have a Profile; each Profile could have ScalarProperties and GroupedProperties. The union feels a bit awkward to have to consider while coding around the StandardizedOutput object.

What do you think?

Comment thread packages/smithy-aws-core/src/smithy_aws_core/config/file_parser.py Outdated
@ubaskota ubaskota requested a review from a team as a code owner July 10, 2026 02:08
sso_sessions: ProfileMap = {}
services: ProfileMap = {}

has_profile_default = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[discussion/suggestion]

It feels a bit odd to have a method that has so many if statements gated behind the filetype flag. How would you feel about getting rid of that flag and instead having standardize_config_file and standardize_credentials_file methods similar to the parser methods?

:param file_type: Whether this is a config or credentials file.
:returns: StandardizedOutput with profiles, sso_sessions, and services.
"""
profiles: ProfileMap = {}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit]

A better name for this would be SectionMap or similar since profiles is only the first of these three

class TestMerge:
"""Tests for credentials/config merge behavior."""

def test_credentials_override_config_for_duplicate_key(self):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this assertion already covered by test_credentials_override_config?

result = await parse_config_file(nonexistent)
assert result == {}

@pytest.mark.asyncio

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a superset of the test above it; we should just call parse in this test and make it all one test IMO.

@SamRemis SamRemis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, clicked approve by mistake. Only the test comments are blocking

@ubaskota ubaskota force-pushed the config_file_support branch from cb70998 to 27cbdd5 Compare July 11, 2026 21:04
@ubaskota ubaskota changed the base branch from develop to config_integration_implementation July 11, 2026 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants