Skip to content

Commit

Permalink
Allow an optional registry id to be passed to the aws-docker-login su…
Browse files Browse the repository at this point in the history
…bcommand
  • Loading branch information
timbod7 committed Dec 9, 2024
1 parent c2209e0 commit ffaf3ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion camus2.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: camus2
version: 0.20
version: 0.21
synopsis: Tool to facilitate unpacking and configuring helix software releases
-- description:
homepage:
Expand Down
8 changes: 5 additions & 3 deletions src/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import qualified Data.ByteString.Lazy as LBS
import qualified Data.ByteString.Base64 as B64
import qualified Data.Conduit.List as CL
import qualified Data.HashMap.Strict as HM
import qualified Data.List.NonEmpty as LNE
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
Expand Down Expand Up @@ -134,13 +135,14 @@ listReleases = do

-- Output the command line to docker login to access the default
-- repository
awsDockerLoginCmd :: IOR ()
awsDockerLoginCmd = do
awsDockerLoginCmd :: Maybe T.Text -> IOR ()
awsDockerLoginCmd registryId = do
tcfg <- getToolConfig
env <- mkAwsEnv
liftIO $ do
runResourceT . runAWST env $ do
resp <- send ECR.getAuthorizationToken
let req = set ECR.gatRegistryIds (fmap (\r -> LNE.fromList [r]) registryId) ECR.getAuthorizationToken
resp <- send req
case view ECR.gatrsAuthorizationData resp of
[authData] -> do
let rawtoken = fromMaybe ("error no token in authdata") (view ECR.adAuthorizationToken authData)
Expand Down
11 changes: 8 additions & 3 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ data Command
| FetchContext (Maybe Int)
| UnpackRelease (T.Text,FilePath)
| ExpandTemplate (FilePath,FilePath)
| AwsDockerLoginCmd
| AwsDockerLoginCmd (Maybe T.Text)
| Status Bool Bool
| Start (T.Text,Maybe T.Text)
| Stop T.Text
Expand Down Expand Up @@ -87,7 +87,7 @@ commandParser = subparser
<> command "expand-template"
(info' expandTemplateParser "Injects the config contexts specified into a template")
<> command "aws-docker-login-cmd"
(info' (pure AwsDockerLoginCmd) "Runs the appropriate docker login command to access configured repositories")
(info' awsDockerLoginCmd "Runs the appropriate docker login command to access configured repositories")
<> command "status"
(info' statusParser "Show the proxy system status: specifically the endpoints and live deploys")
<> command "start"
Expand Down Expand Up @@ -135,6 +135,11 @@ expandTemplateParser = ExpandTemplate <$> arguments
where
arguments = (,) <$> fileArgument "TEMPLATE" <*> fileArgument "OUTFILE"

awsDockerLoginCmd :: Parser Command
awsDockerLoginCmd = AwsDockerLoginCmd <$> registryId
where
registryId = optional $ argument str (metavar "REGISTRY_ID")

statusParser :: Parser Command
statusParser = Status <$> showSlaves <*> jsonOutput
where
Expand Down Expand Up @@ -223,7 +228,7 @@ runCommand ShowDefaultNginxConfig = C.showDefaultNginxConfig
runCommand (FetchContext retry) = runWithConfigAndLog (U.fetchConfigContext retry)
runCommand (UnpackRelease (release,toDir)) = runWithConfigAndLog (U.unpackRelease id release toDir)
runCommand (ExpandTemplate (templatePath,destPath)) = runWithConfigAndLog (U.injectContext id templatePath destPath)
runCommand AwsDockerLoginCmd = runWithConfigAndLog (C.awsDockerLoginCmd)
runCommand (AwsDockerLoginCmd registryId) = runWithConfigAndLog (C.awsDockerLoginCmd registryId)
runCommand (Status showSlaves jsonOutput) = runWithConfig (P.showStatus showSlaves jsonOutput)
runCommand (Start (release,mdeploy)) = runWithConfigAndLog (C.createAndStart release (fromMaybe (deployNameFromRelease release) mdeploy))
runCommand (Stop deploy) = runWithConfigAndLog (C.stopDeploy deploy)
Expand Down

0 comments on commit ffaf3ad

Please sign in to comment.