module Hadolint.Rule.DL3011 (rule) where

import Hadolint.Rule
import Language.Docker.Syntax

rule :: Rule args
rule :: 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 [Port]
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 | Port Int
p Protocol
_ <- [Port]
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 | PortRange Int
l Int
m Protocol
_ <- [Port]
ports]
    check Instruction args
_ = Bool
True
{-# INLINEABLE rule #-}