Skip to content

Commit

Permalink
fix up & touch up user messages
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbao committed Jul 24, 2024
1 parent efc8019 commit 155dbdc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/D2L.Bmx/Aws/AwsCredsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ AwsCredentials credentials
&& o.Org == org
)
// Prune older (closer to expiry) credentials for the same role
.GroupBy( o => $"{o.AccountName}.${o.RoleName}", ( _, entries ) =>
.GroupBy( o => (o.AccountName, o.RoleName), ( _, entries ) =>
entries.OrderBy( o => o.Credentials.Expiration )
)
.Select( o => o.Last() );
Expand Down
10 changes: 7 additions & 3 deletions src/D2L.Bmx/BmxConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ internal interface IBmxConfigProvider {
void SaveConfiguration( BmxConfig config );
}

internal class BmxConfigProvider( FileIniDataParser parser ) : IBmxConfigProvider {
internal class BmxConfigProvider(
FileIniDataParser parser,
IConsoleWriter consoleWriter
) : IBmxConfigProvider {

public BmxConfig GetConfiguration() {
// Main config is at ~/.bmx/config
string configFileName = BmxPaths.CONFIG_FILE_NAME;
Expand All @@ -18,7 +22,7 @@ public BmxConfig GetConfiguration() {
var tempdata = parser.ReadFile( configFileName );
data.Merge( tempdata );
} catch( Exception ) {
Console.Error.Write( $"WARNING: Failed to load the global config file {configFileName}." );
consoleWriter.WriteWarning( $"WARNING: Failed to load the global config file {configFileName}." );
}
}
// If set, we recursively look up from CWD (all the way to root) for additional bmx config files (labelled as .bmx)
Expand All @@ -29,7 +33,7 @@ public BmxConfig GetConfiguration() {
var tempdata = parser.ReadFile( projectConfigInfo.FullName );
data.Merge( tempdata );
} catch( Exception ) {
Console.Error.Write( $"WARNING: Failed to load the local config file {projectConfigInfo.FullName}." );
consoleWriter.WriteWarning( $"WARNING: Failed to load the local config file {projectConfigInfo.FullName}." );
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/D2L.Bmx/Okta/OktaApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ await resp.Content.ReadAsStreamAsync(),
}

string org = _organization ?? "unknown";
throw new BmxException(
$"Okta authentication for user '{username}' in org '{org}'"
+ "failed. Check if org, user, and password is correct" );
throw new BmxException( $"""
Okta authentication for user '{username}' in org '{org}' failed.
Check if org, user, and password is correct.
""" );
}

async Task IOktaApi.IssueMfaChallengeAsync( string stateToken, string factorId ) {
Expand Down
8 changes: 4 additions & 4 deletions src/D2L.Bmx/OktaAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ mfaFactor is OktaMfaQuestionFactor // Security question factor is a static value
if( File.Exists( BmxPaths.CONFIG_FILE_NAME ) ) {
CacheOktaSession( user, org, sessionResp.Id, sessionResp.ExpiresAt );
} else {
consoleWriter.WriteWarning(
"No config file found. Your Okta session will not be cached. " +
"Consider running `bmx configure` if you own this machine."
);
consoleWriter.WriteWarning( """
No config file found. Your Okta session will not be cached.
Consider running `bmx configure` if you own this machine.
""" );
}
return new AuthenticatedOktaApi( Org: org, User: user, Api: oktaApi );
}
Expand Down
11 changes: 6 additions & 5 deletions src/D2L.Bmx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
userOption,
};
loginCommand.SetHandler( ( InvocationContext context ) => {
var config = new BmxConfigProvider( new FileIniDataParser() ).GetConfiguration();
var consoleWriter = new ConsoleWriter();
var config = new BmxConfigProvider( new FileIniDataParser(), consoleWriter ).GetConfiguration();
var handler = new LoginHandler( new OktaAuthenticator(
new OktaApi(),
new OktaSessionStorage(),
new ConsolePrompter(),
new ConsoleWriter(),
consoleWriter,
config
) );
return handler.HandleAsync(
Expand Down Expand Up @@ -67,7 +68,7 @@

configureCommand.SetHandler( ( InvocationContext context ) => {
var handler = new ConfigureHandler(
new BmxConfigProvider( new FileIniDataParser() ),
new BmxConfigProvider( new FileIniDataParser(), new ConsoleWriter() ),
new ConsolePrompter() );
handler.Handle(
org: context.ParseResult.GetValueForOption( orgOption ),
Expand Down Expand Up @@ -123,7 +124,7 @@
printCommand.SetHandler( ( InvocationContext context ) => {
var consolePrompter = new ConsolePrompter();
var consoleWriter = new ConsoleWriter();
var config = new BmxConfigProvider( new FileIniDataParser() ).GetConfiguration();
var config = new BmxConfigProvider( new FileIniDataParser(), consoleWriter ).GetConfiguration();
var handler = new PrintHandler(
new OktaAuthenticator(
new OktaApi(),
Expand Down Expand Up @@ -177,7 +178,7 @@
writeCommand.SetHandler( ( InvocationContext context ) => {
var consolePrompter = new ConsolePrompter();
var consoleWriter = new ConsoleWriter();
var config = new BmxConfigProvider( new FileIniDataParser() ).GetConfiguration();
var config = new BmxConfigProvider( new FileIniDataParser(), consoleWriter ).GetConfiguration();
var handler = new WriteHandler(
new OktaAuthenticator(
new OktaApi(),
Expand Down

0 comments on commit 155dbdc

Please sign in to comment.