Skip to content

Commit 9687232

Browse files
Merge pull request #357 from jonathanmorley/fix-newlines
fix newlines when adding profiles
2 parents 7cfc422 + b19da85 commit 9687232

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist-workspace.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pr-run-mode = "upload"
2929
github-attestations = true
3030

3131
# Force the builds onto the best runners for their architecture
32+
[dist.github-custom-runners.x86_64-pc-windows-msvc]
33+
runner = "windows-latest"
3234
[dist.github-custom-runners.aarch64-pc-windows-msvc]
3335
runner = "windows-11-arm"
3436
[dist.github-custom-runners.aarch64-unknown-linux-gnu]

src/aws/profile.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ impl Store {
2525
)?,
2626
};
2727

28-
let credentials_file = fs::read_to_string(&path)?.parse().wrap_err_with(|| {
29-
format!("Failed to parse AWS credentials file {}", &path.display())
30-
})?;
28+
let credentials_file = if path.exists() {
29+
fs::read_to_string(&path)?.parse().wrap_err_with(|| {
30+
format!("Failed to parse AWS credentials file {}", &path.display())
31+
})?
32+
} else {
33+
AwsCredentialsFile::default()
34+
};
3135

3236
Ok(Self {
3337
path,
@@ -112,7 +116,13 @@ aws_secret_access_key = STATIC_SECRET_ACCESS_KEY
112116
"#;
113117

114118
#[test]
115-
fn insert_credential_no_file() -> Result<()> {
119+
fn load_no_file() -> Result<()> {
120+
Store::load(Some(&PathBuf::from("THIS PATH DOES NOT EXIST")))?;
121+
Ok(())
122+
}
123+
124+
#[test]
125+
fn insert_credential_empty_file() -> Result<()> {
116126
let tempfile = NamedTempFile::new()?;
117127

118128
let mut store = Store::load(Some(tempfile.path()))?;
@@ -128,6 +138,17 @@ aws_secret_access_key = STATIC_SECRET_ACCESS_KEY
128138
),
129139
)?;
130140

141+
store.upsert_credential(
142+
"bar",
143+
&Credentials::new(
144+
"NEW_BAR_ACCESS_KEY",
145+
"NEW_BAR_SECRET_ACCESS_KEY",
146+
Some("NEW_BAR_SESSION_TOKEN".to_string()),
147+
None,
148+
"oktaws",
149+
),
150+
)?;
151+
131152
store.save()?;
132153

133154
let contents = fs::read_to_string(tempfile)?;
@@ -144,6 +165,16 @@ aws_secret_access_key = STATIC_SECRET_ACCESS_KEY
144165
lines.next(),
145166
Some("aws_session_token = NEW_FOO_SESSION_TOKEN")
146167
);
168+
assert_eq!(lines.next(), Some("[bar]"));
169+
assert_eq!(lines.next(), Some("aws_access_key_id = NEW_BAR_ACCESS_KEY"));
170+
assert_eq!(
171+
lines.next(),
172+
Some("aws_secret_access_key = NEW_BAR_SECRET_ACCESS_KEY")
173+
);
174+
assert_eq!(
175+
lines.next(),
176+
Some("aws_session_token = NEW_BAR_SESSION_TOKEN")
177+
);
147178
assert_eq!(lines.next(), None);
148179

149180
Ok(())
@@ -264,7 +295,7 @@ aws_secret_access_key = STATIC_SECRET_ACCESS_KEY"
264295
"The credentials for static are not STS. Refusing to overwrite them
265296
266297
Location:
267-
{}:53:24",
298+
{}:57:24",
268299
PathBuf::from_iter(["src", "aws", "profile.rs"]).display()
269300
),
270301
);
@@ -304,7 +335,7 @@ Caused by:
304335
1: Parsing Error: VerboseError {{ errors: [(\"foo\", Nom(Eof))] }}
305336
306337
Location:
307-
{}:28:67",
338+
{}:29:48",
308339
tempfile.path().display(),
309340
PathBuf::from_iter(["src", "aws", "profile.rs"]).display()
310341
)

0 commit comments

Comments
 (0)