Crate aws_config_mod

Source
Expand description

§aws_config_mod

A missing piece of the Rust AWS SDK. A current missing feature of the SDK is the ability to read and modify AWS config files programatically, such as what we can do with the set command: https://docs.aws.amazon.com/cli/latest/reference/configure/set.html

The goal of this library is allowing you to add, modify, and remove AWS CLI configuration settings for existing configuration files to to generate new ones while any existing whitespace or comments in the original file.

This crate is still a work-in-progress, so if there are any features that you need right away, please open an issue and they will be prioritized.

§Usage

// Assuming you already read the configuration file to a string
let config_content = r#"
[profile A]
credential_source = Ec2InstanceMetadata
endpoint_url = https://profile-a-endpoint.aws/

[profile B]
source_profile = A
role_arn = arn:aws:iam::123456789012:role/roleB
services = profileB

[services profileB]
ec2 =
  endpoint_url = https://profile-b-ec2-endpoint.aws"#;

let mut config = AwsConfigFile::parse(SAMPLE_FILE).expect("Sample file should be valid");

let setting_path = SettingPath::try_from("profile.A.credential_source").expect("Should parse");
config.set(setting_path, Value::from("my-new-credential-source"));
let stringified = config.to_string();
// Write the content back to your file

§TODOs

  • improved error messages
  • automatic config file loading via standard aws config locations and environment variables
  • detect and match formatting
  • set formatting
  • utilize aws types
  • add more strongly typed structs for various aspects of the configuration

Structs§

AwsConfigFile
Represents a complete aws config file. Note that this struct is not intended for use with a credentials file although it can still successfully parse one. To handle credential files specifically, use crate::AwsCredentialsFile.
AwsCredentialsFile
Represents and aws credentials file. A credentials file contains sensitive authentication information separately from the main configuration file.
NestedSetting
Represents a nested setting in its entirety, including indentation, its name and value, and a comment. Since the AWS config file is not recursive, we have this separate type to represent the nested item to avoid defining an unnecessary recursive type.
NestedSettingPath
Represents the path to a crate::NestedSetting. In practical terms, this means a SectionPath followed by a two SettingNames.
Section
Represents an entire section, including the section type, the profile name, and all of the settings
SectionName
Represents the custom profile name associated with a section. In other words, if we see [profile dev], then ‘dev’ is the profile name
SectionPath
Represents the path to a specific crate::Section in a config file.
Setting
Represents a setting in its entirety, including indentation, its name and value, and a comment
SettingName
Represents the name of a setting; in other words, the part that comes before the ‘=’ sign.
SettingPath
A path to a crate::Setting. The path includes the crate::SectionType, the crate::SectionName, and the SettingName of the setting to be accessed.
Value
Represents the value of a setting. In other words, whatever follows the = sign in a configuration setting.

Enums§

Error
Custom error type. Currently incomplete but will eventually feature better parse-error diagnostics
SectionType
Represents the various section types of an AWS config file. If an unknown section type is encountered, rather than failing it’s value is collected under SectionType::Other
ValueType
Represents the two categories of value that a top-level crate::Setting may have. These are a Value or a list of crate::NestedSetting