module Hadolint.Rule.DL3054 (rule) where import Data.Either import qualified Data.Map as Map import qualified Data.Text as Text import Distribution.Parsec import Distribution.SPDX.Extra import Hadolint.Rule import Language.Docker.Syntax rule :: LabelSchema -> Rule args rule :: forall args. LabelSchema -> Rule args rule LabelSchema labelschema = forall a. Monoid a => [a] -> a mconcat forall a b. (a -> b) -> a -> b $ forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b fmap forall args. Text -> Rule args labelIsNotSPDXRule (forall k a. Map k a -> [k] Map.keys (forall a k. (a -> Bool) -> Map k a -> Map k a Map.filter (forall a. Eq a => a -> a -> Bool == LabelType Spdx) LabelSchema labelschema)) {-# INLINEABLE rule #-} labelIsNotSPDXRule :: LabelName -> Rule args labelIsNotSPDXRule :: forall args. Text -> Rule args labelIsNotSPDXRule Text label = forall args. RuleCode -> DLSeverity -> Text -> (Instruction args -> Bool) -> Rule args simpleRule RuleCode code DLSeverity severity Text message forall {args}. Instruction args -> Bool check where code :: RuleCode code = RuleCode "DL3054" severity :: DLSeverity severity = DLSeverity DLWarningC message :: Text message = Text "Label `" forall a. Semigroup a => a -> a -> a <> Text label forall a. Semigroup a => a -> a -> a <> Text "` is not a valid SPDX identifier." check :: Instruction args -> Bool check (Label Pairs ls) = forall (t :: * -> *) a. Foldable t => t a -> Bool null forall a b. (a -> b) -> a -> b $ Text -> Pairs -> Pairs getBadLicenseLabels Text label Pairs ls check Instruction args _ = Bool True getBadLicenseLabels :: LabelName -> Pairs -> Pairs getBadLicenseLabels :: Text -> Pairs -> Pairs getBadLicenseLabels Text lbl Pairs pairs = [ (Text l, Text v) | (Text l, Text v) <- Pairs pairs, Text l forall a. Eq a => a -> a -> Bool == Text lbl, forall a b. Either a b -> Bool isLeft (forall a. Parsec a => String -> Either String a eitherParsec (Text -> String Text.unpack Text v) :: Either String LicenseId) ]