From 0b8026d9f8ac9530aa222b23664a9568e5bf99f8 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Fri, 30 Jun 2023 13:52:13 -0400 Subject: [PATCH 1/3] Add forEachSpec_ --- src/Stackctl/Spec/Changes.hs | 4 +--- src/Stackctl/Spec/Deploy.hs | 4 +--- src/Stackctl/Spec/Discover.hs | 17 ++++++++++++++++- src/Stackctl/Spec/List.hs | 3 +-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Stackctl/Spec/Changes.hs b/src/Stackctl/Spec/Changes.hs index 7ff6ebe..e3fc021 100644 --- a/src/Stackctl/Spec/Changes.hs +++ b/src/Stackctl/Spec/Changes.hs @@ -76,9 +76,7 @@ runChanges ChangesOptions {..} = do Nothing -> pushLoggerLn formatted Just p -> liftIO $ T.appendFile p $ formatted <> "\n" - specs <- discoverSpecs - - for_ specs $ \spec -> do + forEachSpec_ $ \spec -> do withThreadContext ["stackName" .= stackSpecStackName spec] $ do emChangeSet <- createChangeSet spec scoParameters scoTags diff --git a/src/Stackctl/Spec/Deploy.hs b/src/Stackctl/Spec/Deploy.hs index a9d6c2e..ffc632d 100644 --- a/src/Stackctl/Spec/Deploy.hs +++ b/src/Stackctl/Spec/Deploy.hs @@ -88,9 +88,7 @@ runDeploy DeployOptions {..} = do removed <- inferRemovedStacks traverse_ (deleteRemovedStack sdoDeployConfirmation) removed - specs <- discoverSpecs - - for_ specs $ \spec -> do + forEachSpec_ $ \spec -> do withThreadContext ["stackName" .= stackSpecStackName spec] $ do checkIfStackRequiresDeletion sdoDeployConfirmation $ stackSpecStackName spec diff --git a/src/Stackctl/Spec/Discover.hs b/src/Stackctl/Spec/Discover.hs index 6153ee8..6fddb20 100644 --- a/src/Stackctl/Spec/Discover.hs +++ b/src/Stackctl/Spec/Discover.hs @@ -1,5 +1,6 @@ module Stackctl.Spec.Discover - ( discoverSpecs + ( forEachSpec_ + , discoverSpecs , buildSpecPath ) where @@ -17,6 +18,20 @@ import Stackctl.StackSpecPath import System.FilePath (isPathSeparator) import System.FilePath.Glob +forEachSpec_ + :: ( MonadMask m + , MonadResource m + , MonadLogger m + , MonadReader env m + , HasAwsScope env + , HasConfig env + , HasDirectoryOption env + , HasFilterOption env + ) + => (StackSpec -> m ()) + -> m () +forEachSpec_ f = traverse_ f =<< discoverSpecs + discoverSpecs :: ( MonadMask m , MonadResource m diff --git a/src/Stackctl/Spec/List.hs b/src/Stackctl/Spec/List.hs index 25369fa..b12dceb 100644 --- a/src/Stackctl/Spec/List.hs +++ b/src/Stackctl/Spec/List.hs @@ -40,10 +40,9 @@ runList => ListOptions -> m () runList _ = do - specs <- discoverSpecs Colors {..} <- getColorsLogger - for_ specs $ \spec -> do + forEachSpec_ $ \spec -> do let path = stackSpecFilePath spec name = stackSpecStackName spec From 9fcf0ffc418cc95825ce1460e80bebfc1bb63e98 Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Mon, 28 Aug 2023 15:49:23 -0400 Subject: [PATCH 2/3] Add awsWithAuth This function allows access to the underlying `AuthEnv`. It's not used by Stackctl (yet) but is used by tooling that uses Stackctl as its AWS SDK wrapper to supply concrete keys to external processes that aren't SSO-session aware. In the future, this AWS "library" should be extracted and shared, but for now we accept such minor extensions even if they only exist for these external. use-cases. --- src/Stackctl/AWS/Core.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Stackctl/AWS/Core.hs b/src/Stackctl/AWS/Core.hs index 28e1a01..73fa269 100644 --- a/src/Stackctl/AWS/Core.hs +++ b/src/Stackctl/AWS/Core.hs @@ -2,6 +2,7 @@ module Stackctl.AWS.Core ( AwsEnv , HasAwsEnv (..) , awsEnvDiscover + , awsWithAuth , awsSimple , awsSend , awsPaginate @@ -32,7 +33,7 @@ import Amazonka hiding (LogLevel (..)) import qualified Amazonka as AWS import Amazonka.Auth.Keys (fromSession) import Amazonka.Data.Text (FromText (..), ToText (..)) -import Amazonka.Env (env_logger, env_region) +import Amazonka.Env (env_auth, env_logger, env_region) import Amazonka.STS.AssumeRole import Conduit (ConduitM) import Control.Monad.Logger (defaultLoc, toLogStr) @@ -74,6 +75,12 @@ class HasAwsEnv env where instance HasAwsEnv AwsEnv where awsEnvL = id +awsWithAuth + :: (MonadIO m, MonadReader env m, HasAwsEnv env) => (AuthEnv -> m a) -> m a +awsWithAuth f = do + auth <- view $ awsEnvL . unL . env_auth . to runIdentity + withAuth auth f + awsSimple :: ( MonadResource m , MonadReader env m From 9c0894d03057bf7509b83e1950a9865fba9e6d8e Mon Sep 17 00:00:00 2001 From: patrick brisbin Date: Mon, 28 Aug 2023 15:52:58 -0400 Subject: [PATCH 3/3] Version bump --- CHANGELOG.md | 7 ++++++- package.yaml | 2 +- stackctl.cabal | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5caa541..11cafce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -## [_Unreleased_](https://github.com/freckle/stackctl/compare/v1.4.2.2...main) +## [_Unreleased_](https://github.com/freckle/stackctl/compare/v1.4.3.0...main) + +## [v1.4.3.0](https://github.com/freckle/stackctl/compare/v1.4.2.2...v1.4.3.0) + +- Add `awsWithAuth` +- Add `forEachSpec_` ## [v1.4.2.2](https://github.com/freckle/stackctl/compare/v1.4.2.1...v1.4.2.2) diff --git a/package.yaml b/package.yaml index 2a4d096..23e607c 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: stackctl -version: 1.4.2.2 +version: 1.4.3.0 github: freckle/stackctl license: MIT author: Freckle Engineering diff --git a/stackctl.cabal b/stackctl.cabal index ae1dcb6..7ab2b95 100644 --- a/stackctl.cabal +++ b/stackctl.cabal @@ -5,7 +5,7 @@ cabal-version: 1.18 -- see: https://github.com/sol/hpack name: stackctl -version: 1.4.2.2 +version: 1.4.3.0 description: Please see homepage: https://github.com/freckle/stackctl#readme bug-reports: https://github.com/freckle/stackctl/issues