module Hadolint.Rule.DL3022 (rule) where

import qualified Data.Set as Set
import qualified Data.Text as Text
import Hadolint.Rule
import Language.Docker.Syntax

rule :: Rule args
rule :: forall args. Rule args
rule = forall a args.
(Linenumber -> State a -> Instruction args -> State a)
-> State a -> Rule args
customRule forall {args}.
Linenumber
-> State (Set Text) -> Instruction args -> State (Set Text)
check (forall a. a -> State a
emptyState forall a. Set a
Set.empty)
  where
    code :: RuleCode
code = RuleCode
"DL3022"
    severity :: DLSeverity
severity = DLSeverity
DLWarningC
    message :: Text
message = Text
"`COPY --from` should reference a previously defined `FROM` alias"

    check :: Linenumber
-> State (Set Text) -> Instruction args -> State (Set Text)
check Linenumber
_ State (Set Text)
st (From BaseImage {$sel:alias:BaseImage :: BaseImage -> Maybe ImageAlias
alias = Just (ImageAlias Text
als)}) = State (Set Text)
st forall a b. a -> (a -> b) -> b
|> forall a. (a -> a) -> State a -> State a
modify (forall a. Ord a => a -> Set a -> Set a
Set.insert Text
als)
    check Linenumber
line State (Set Text)
st (Copy (CopyArgs NonEmpty SourcePath
_ TargetPath
_) (CopyFlags Chown
_ Chmod
_ Link
_ (CopySource Text
s)))
      | Text
":" Text -> Text -> Bool
`Text.isInfixOf` Text -> Text
dropQuotes Text
s = State (Set Text)
st
      | forall a. Ord a => a -> Set a -> Bool
Set.member Text
s (forall a. State a -> a
state State (Set Text)
st) = State (Set Text)
st
      | Bool
otherwise = State (Set Text)
st forall a b. a -> (a -> b) -> b
|> forall a. CheckFailure -> State a -> State a
addFail CheckFailure {Linenumber
Text
RuleCode
DLSeverity
line :: Linenumber
message :: Text
severity :: DLSeverity
code :: RuleCode
line :: Linenumber
message :: Text
severity :: DLSeverity
code :: RuleCode
..}
    check Linenumber
_ State (Set Text)
st Instruction args
_ = State (Set Text)
st
{-# INLINEABLE rule #-}