Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add env argument for secret mounts #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Language/Docker/Parser/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ data RunFlag
deriving (Show)

data RunMountArg
= MountArgFromImage Text
= MountArgEnv Text
| MountArgFromImage Text
| MountArgId Text
| MountArgMode Text
| MountArgReadOnly Bool
Expand Down Expand Up @@ -161,13 +162,14 @@ secretMount args =
Left e -> customError e
Right as -> return $ foldr secretOpts def as
where
allowed = Set.fromList ["target", "id", "required", "source", "mode", "uid", "gid"]
allowed = Set.fromList ["target", "id", "required", "source", "mode", "uid", "gid", "env"]
required = Set.empty
secretOpts :: RunMountArg -> SecretOpts -> SecretOpts
secretOpts (MountArgTarget path) co = co {sTarget = Just path}
secretOpts (MountArgId i) co = co {sCacheId = Just i}
secretOpts (MountArgRequired r) co = co {sIsRequired = Just r}
secretOpts (MountArgSource path) co = co {sSource = Just path}
secretOpts (MountArgEnv e) co = co {sEnv = Just e}
secretOpts (MountArgMode m) co = co {sMode = Just m}
secretOpts (MountArgUid u) co = co {sUid = Just u}
secretOpts (MountArgGid g) co = co {sGid = Just g}
Expand Down Expand Up @@ -223,7 +225,8 @@ mountChoices mountType =
mountArgSource,
mountArgMode,
mountArgUid,
mountArgGid
mountArgGid,
mountArgEnv
]

stringArg :: (?esc :: Char) => Parser Text
Expand All @@ -239,6 +242,9 @@ cacheSharing :: Parser CacheSharing
cacheSharing =
choice [Private <$ string "private", Shared <$ string "shared", Locked <$ string "locked"]

mountArgEnv :: (?esc :: Char) => Parser RunMountArg
mountArgEnv = MountArgEnv <$> key "env" stringArg

mountArgFromImage :: (?esc :: Char) => Parser RunMountArg
mountArgFromImage = MountArgFromImage <$> key "from" stringArg

Expand Down Expand Up @@ -317,6 +323,7 @@ mountArgUid :: (?esc :: Char) => Parser RunMountArg
mountArgUid = MountArgUid <$> key "uid" stringArg

toArgName :: RunMountArg -> Text
toArgName (MountArgEnv _) = "env"
toArgName (MountArgFromImage _) = "from"
toArgName (MountArgGid _) = "gid"
toArgName (MountArgId _) = "id"
Expand Down
3 changes: 2 additions & 1 deletion src/Language/Docker/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,15 @@ data SecretOpts
sCacheId :: !(Maybe Text),
sIsRequired :: !(Maybe Bool),
sSource :: !(Maybe SourcePath),
sEnv :: !(Maybe Text),
sMode :: !(Maybe Text),
sUid :: !(Maybe Text),
sGid :: !(Maybe Text)
}
deriving (Eq, Show, Ord)

instance Default SecretOpts where
def = SecretOpts Nothing Nothing Nothing Nothing Nothing Nothing Nothing
def = SecretOpts Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
aegypius marked this conversation as resolved.
Show resolved Hide resolved

data CacheSharing
= Shared
Expand Down
6 changes: 4 additions & 2 deletions test/Language/Docker/ParseRunSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,15 @@ spec = do
[ Run $ RunArgs (ArgumentsText "echo foo") flags
]
it "--mount=type=secret all modifiers" $
let file = Text.unlines ["RUN --mount=type=secret,target=/foo,id=a,required,source=/bar,mode=0700,uid=0,gid=0 echo foo"]
let file = Text.unlines ["RUN --mount=type=secret,target=/foo,env=baz,id=a,required,source=/bar,mode=0700,uid=0,gid=0 echo foo"]
flags =
def
{ mount =
Set.singleton $
SecretMount
( def
{ sTarget = Just "/foo",
sEnv = Just "baz",
sCacheId = Just "a",
sIsRequired = Just True,
sSource = Just "/bar",
Expand All @@ -208,14 +209,15 @@ spec = do
[ Run $ RunArgs (ArgumentsText "echo foo") flags
]
it "--mount=type=secret all modifiers, required explicit" $
let file = Text.unlines ["RUN --mount=type=secret,target=/foo,id=a,required=true,source=/bar,mode=0700,uid=0,gid=0 echo foo"]
let file = Text.unlines ["RUN --mount=type=secret,target=/foo,env=baz,id=a,required=true,source=/bar,mode=0700,uid=0,gid=0 echo foo"]
flags =
def
{ mount =
Set.singleton $
SecretMount
( def
{ sTarget = Just "/foo",
sEnv = Just "baz",
sCacheId = Just "a",
sIsRequired = Just True,
sSource = Just "/bar",
Expand Down