module Hadolint.Rule.DL3011 (rule) where

import Hadolint.Rule
import Language.Docker.Syntax

rule :: Rule args
rule :: forall args. Rule args
rule = RuleCode
-> DLSeverity -> Text -> (Instruction args -> Bool) -> Rule args
forall args.
RuleCode
-> DLSeverity -> Text -> (Instruction args -> Bool) -> Rule args
simpleRule RuleCode
code DLSeverity
severity Text
message Instruction args -> Bool
forall {args}. Instruction args -> Bool
check
  where
    code :: RuleCode
code = RuleCode
"DL3011"
    severity :: DLSeverity
severity = DLSeverity
DLErrorC
    message :: Text
message = Text
"Valid UNIX ports range from 0 to 65535"
    check :: Instruction args -> Bool
check (Expose (Ports [PortSpec]
ports)) =
      [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
65535 | PortSpec (Port Int
p Protocol
_) <- [PortSpec]
ports]
        Bool -> Bool -> Bool
&& [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and [Int
l Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
65535 Bool -> Bool -> Bool
&& Int
m Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
65535 | PortRangeSpec (PortRange (Port Int
l Protocol
_) (Port Int
m Protocol
_)) <- [PortSpec]
ports]
    check Instruction args
_ = Bool
True
{-# INLINEABLE rule #-}