-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Open Config commands & bug fixes (#20)
- Fixes bug when no default credentials are found in AWS file - Adds an open config command (app and AWS)
- Loading branch information
Showing
14 changed files
with
167 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/Ellosoft.AwsCredentialsManager/Commands/Config/ConfigBranch.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2023 Ellosoft Limited. All rights reserved. | ||
|
||
namespace Ellosoft.AwsCredentialsManager.Commands.Config; | ||
|
||
[Name("config")] | ||
[Description("Open config file")] | ||
public class ConfigBranch | ||
{ | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Ellosoft.AwsCredentialsManager/Commands/Config/OpenAwsConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright (c) 2023 Ellosoft Limited. All rights reserved. | ||
|
||
using Ellosoft.AwsCredentialsManager.Services; | ||
using Ellosoft.AwsCredentialsManager.Services.IO; | ||
|
||
namespace Ellosoft.AwsCredentialsManager.Commands.Config; | ||
|
||
[Name("aws")] | ||
[Description("Open AWS credentials file")] | ||
[Examples("aws")] | ||
public class OpenAwsConfig(IFileManager fileManager) : Command | ||
{ | ||
public override int Execute(CommandContext context) | ||
{ | ||
var awsCredentialsPath = Path.Combine(AppDataDirectory.UserProfileDirectory, ".aws", "credentials"); | ||
|
||
if (!File.Exists(awsCredentialsPath)) | ||
throw new CommandException($"The file {awsCredentialsPath} does not exist"); | ||
|
||
fileManager.OpenFile(awsCredentialsPath); | ||
|
||
return 0; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Ellosoft.AwsCredentialsManager/Commands/Config/OpenConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright (c) 2023 Ellosoft Limited. All rights reserved. | ||
|
||
using Ellosoft.AwsCredentialsManager.Services.Configuration; | ||
using Ellosoft.AwsCredentialsManager.Services.IO; | ||
|
||
namespace Ellosoft.AwsCredentialsManager.Commands.Config; | ||
|
||
[Name("user")] | ||
[Description("Open credentials manager user config file (default)")] | ||
[Examples("user")] | ||
public class OpenConfig(IConfigManager configManager, IFileManager fileManager) : Command | ||
{ | ||
public override int Execute(CommandContext context) | ||
{ | ||
if (!File.Exists(configManager.AppConfigPath)) | ||
configManager.SaveConfig(); | ||
|
||
fileManager.OpenFile(configManager.AppConfigPath); | ||
|
||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2023 Ellosoft Limited. All rights reserved. | ||
|
||
using Ellosoft.AwsCredentialsManager.Services.AWS; | ||
using Ellosoft.AwsCredentialsManager.Services.AWS.Interactive; | ||
using Ellosoft.AwsCredentialsManager.Services.Configuration; | ||
using Ellosoft.AwsCredentialsManager.Services.Configuration.Interactive; | ||
using Ellosoft.AwsCredentialsManager.Services.IO; | ||
using Ellosoft.AwsCredentialsManager.Services.Okta; | ||
using Ellosoft.AwsCredentialsManager.Services.Okta.Interactive; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Ellosoft.AwsCredentialsManager; | ||
|
||
public static class ServiceRegistration | ||
{ | ||
public static IServiceCollection RegisterAppServices(this IServiceCollection services) | ||
{ | ||
services | ||
.AddSingleton<IFileManager, FileManager>() | ||
.AddSingleton<IConfigManager, ConfigManager>() | ||
.AddSingleton<CredentialsManager>() | ||
.AddSingleton<EnvironmentManager>(); | ||
|
||
// okta related services | ||
services | ||
.AddSingleton<OktaClassicAuthenticator>() | ||
.AddSingleton<OktaClassicAccessTokenProvider>() | ||
.AddSingleton<IOktaLoginService, OktaLoginService>() | ||
.AddSingleton<IOktaMfaFactorSelector, OktaMfaFactorSelector>() | ||
.AddSingleton<AwsOktaSessionManager>() | ||
.AddSingleton<OktaSamlService>(); | ||
|
||
// aws related services | ||
services | ||
.AddSingleton<RdsTokenGenerator>() | ||
.AddSingleton<AwsSamlService>(); | ||
|
||
services | ||
.AddKeyedSingleton(nameof(OktaHttpClientFactory), OktaHttpClientFactory.CreateHttpClient()); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/Ellosoft.AwsCredentialsManager/Services/IO/FileManager.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2023 Ellosoft Limited. All rights reserved. | ||
|
||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Ellosoft.AwsCredentialsManager.Services.IO; | ||
|
||
public interface IFileManager | ||
{ | ||
void OpenFile(string filePath); | ||
} | ||
|
||
public class FileManager : IFileManager | ||
{ | ||
public void OpenFile(string filePath) | ||
{ | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
{ | ||
Process.Start("explorer", $"\"{filePath}\""); | ||
|
||
return; | ||
} | ||
|
||
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) | ||
{ | ||
Process.Start("open", $"\"{filePath}\""); | ||
|
||
return; | ||
} | ||
|
||
throw new InvalidOperationException("Unsupported operating system."); | ||
} | ||
} |