Skip to content

Commit

Permalink
write: update config file section with same name if no cred process f…
Browse files Browse the repository at this point in the history
…lag (#453)

### Why

Default credentials file takes priority over the default config which is
where we store profiles using `credential_process`. If someone had an
existing profile in config file and then runs `bmx write`, creds will be
stored into the default credentials file making the existing one
useless. We should remove the existing key in the config file so there
is no confusion.

`credential_process` is the better way for majority of people but there
are some scenarios where it's not supported. So we are leaving some
information to the user that it is no longer being used. Just in case
they unintentionally ran write without the flag. Not going with a prompt
to confirm because that could break existing scripts

### Ticket

VUL-385

---------

Co-authored-by: Chenfeng Bao <[email protected]>
  • Loading branch information
gord5500 and cfbao authored Jun 19, 2024
1 parent 6495405 commit a494d89
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/D2L.Bmx/WriteHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,27 @@ bool useCredentialProcess
+ $" --role {awsCredsInfo.Role}"
+ $" --duration {awsCredsInfo.Duration}";
} else {
if( File.Exists( SharedCredentialsFile.DefaultConfigFilePath ) ) {
string sectionName = $"profile {profile}";
var defaultConfigFile = parser.ReadFile( SharedCredentialsFile.DefaultConfigFilePath );
if( defaultConfigFile.Sections.ContainsSection( sectionName )
&& defaultConfigFile[sectionName].ContainsKey( "credential_process" ) ) {

if( defaultConfigFile[sectionName].Count == 1 ) {
defaultConfigFile.Sections.RemoveSection( sectionName );
} else {
defaultConfigFile[sectionName].RemoveKey( "credential_process" );
}
parser.WriteFile( SharedCredentialsFile.DefaultConfigFilePath, defaultConfigFile );
Console.WriteLine(
"""
An existing profile with the same name using the `credential_process` setting was found in the default config file.
The setting has been removed, and static credentials will be used for the profile.
To continue using non-static credentials, rerun the command with the --use-credential-process flag.
"""
);
}
}
if( !data.Sections.ContainsSection( profile ) ) {
data.Sections.AddSection( profile );
}
Expand Down

0 comments on commit a494d89

Please sign in to comment.