From 775cec5b2b61cfb70c5cca97ed44586ebcae7f5c Mon Sep 17 00:00:00 2001 From: David Broadfoot Date: Mon, 4 Dec 2023 19:12:44 +1100 Subject: [PATCH 1/2] Add --session option to support S3 operations using a session token from an AWS SSO profile --- src/Squirrel.CommandLine/Commands/S3Commands.cs | 6 ++++++ src/Squirrel.CommandLine/Sync/S3Repository.cs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Squirrel.CommandLine/Commands/S3Commands.cs b/src/Squirrel.CommandLine/Commands/S3Commands.cs index bf820bf7b..2601f19ec 100644 --- a/src/Squirrel.CommandLine/Commands/S3Commands.cs +++ b/src/Squirrel.CommandLine/Commands/S3Commands.cs @@ -9,6 +9,8 @@ public class S3BaseCommand : BaseCommand public string Secret { get; private set; } + public string Session { get; private set; } + public string Region { get; private set; } public string Endpoint { get; private set; } @@ -30,6 +32,10 @@ protected S3BaseCommand(string name, string description) .SetArgumentHelpName("KEY") .SetRequired(); + AddOption((v) => Session = v, "--session") + .SetDescription("Authentication session token.") + .SetArgumentHelpName("SESSION"); + var region = AddOption((v) => Region = v, "--region") .SetDescription("AWS service region (eg. us-west-1).") .SetArgumentHelpName("REGION"); diff --git a/src/Squirrel.CommandLine/Sync/S3Repository.cs b/src/Squirrel.CommandLine/Sync/S3Repository.cs index 29ed48627..57d567bd7 100644 --- a/src/Squirrel.CommandLine/Sync/S3Repository.cs +++ b/src/Squirrel.CommandLine/Sync/S3Repository.cs @@ -23,10 +23,10 @@ private static AmazonS3Client GetS3Client(S3BaseCommand options) { if (options.Region != null) { var r = RegionEndpoint.GetBySystemName(options.Region); - return new AmazonS3Client(options.KeyId, options.Secret, r); + return new AmazonS3Client(options.KeyId, options.Secret, options.Session, r); } else if (options.Endpoint != null) { var config = new AmazonS3Config() { ServiceURL = options.Endpoint }; - return new AmazonS3Client(options.KeyId, options.Secret, config); + return new AmazonS3Client(options.KeyId, options.Secret, options.Session, config); } else { throw new InvalidOperationException("Missing endpoint"); } From 2fdb4f2596883f8822269dd052317290da4e9b32 Mon Sep 17 00:00:00 2001 From: David Broadfoot Date: Fri, 8 Dec 2023 15:52:51 +1100 Subject: [PATCH 2/2] Make aws keyid / key optional to allow the default AWS Profile to be used --- src/Squirrel.CommandLine/Commands/S3Commands.cs | 6 ++---- src/Squirrel.CommandLine/Sync/S3Repository.cs | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Squirrel.CommandLine/Commands/S3Commands.cs b/src/Squirrel.CommandLine/Commands/S3Commands.cs index 2601f19ec..8828167ce 100644 --- a/src/Squirrel.CommandLine/Commands/S3Commands.cs +++ b/src/Squirrel.CommandLine/Commands/S3Commands.cs @@ -24,13 +24,11 @@ protected S3BaseCommand(string name, string description) { AddOption((v) => KeyId = v, "--keyId") .SetDescription("Authentication identifier or access key.") - .SetArgumentHelpName("KEYID") - .SetRequired(); + .SetArgumentHelpName("KEYID"); AddOption((v) => Secret = v, "--secret") .SetDescription("Authentication secret key.") - .SetArgumentHelpName("KEY") - .SetRequired(); + .SetArgumentHelpName("KEY"); AddOption((v) => Session = v, "--session") .SetDescription("Authentication session token.") diff --git a/src/Squirrel.CommandLine/Sync/S3Repository.cs b/src/Squirrel.CommandLine/Sync/S3Repository.cs index 57d567bd7..c19eb9006 100644 --- a/src/Squirrel.CommandLine/Sync/S3Repository.cs +++ b/src/Squirrel.CommandLine/Sync/S3Repository.cs @@ -23,6 +23,11 @@ private static AmazonS3Client GetS3Client(S3BaseCommand options) { if (options.Region != null) { var r = RegionEndpoint.GetBySystemName(options.Region); + + if (string.IsNullOrWhiteSpace(options.KeyId)) { + return new AmazonS3Client(r); + } + return new AmazonS3Client(options.KeyId, options.Secret, options.Session, r); } else if (options.Endpoint != null) { var config = new AmazonS3Config() { ServiceURL = options.Endpoint };