diff --git a/src/App/Validation.purs b/src/App/Validation.purs index f379c50..d00fd1b 100644 --- a/src/App/Validation.purs +++ b/src/App/Validation.purs @@ -1,11 +1,11 @@ module App.Validation where -import Prelude +import Prelude (apply, map, otherwise, pure, show, ($), (&&), (<), (<<<), (<=), (<>), (>=)) -import Data.Validation.Semigroup -import Data.Array as A -import Data.Maybe -import Data.Either +import Data.Validation.Semigroup (V, andThen, invalid, toEither) +-- import Data.Array as A +import Data.Maybe (Maybe(..)) +import Data.Either (Either(..)) import Data.Tuple (Tuple(..)) import Data.String.Regex as R import Data.String.Regex.Flags as RF @@ -32,12 +32,19 @@ data Attribute type Errors = Array (Tuple Attribute String) -- | Totally garbage value at the moment. Please fix. +min_ttl :: Int min_ttl = 30 +max_ttl :: Int max_ttl = 86000 +name_min_len :: Int name_min_len = 1 +name_max_len :: Int name_max_len = 50 +target_min_len :: Int target_min_len = 1 +target_max_len :: Int target_max_len = 50 +name_format :: String name_format = "[a-zA-Z]+" -- name_format = "[a-zA-Z][a-zA-Z0-9_-]*" @@ -80,9 +87,9 @@ validate_name :: String -> V Errors String validate_name name = case R.regex name_format RF.unicode of Left error_string -> invalid [Tuple NotAnAttribute $ "error in name regex: " <> error_string] - Right regex -> verify_length !> (matches Name regex) + Right regex -> verify_length name !> (matches Name regex) where - verify_length = lengthIsBetween Name name_min_len name_max_len name + verify_length = lengthIsBetween Name name_min_len name_max_len validate_ttl :: String -> V Errors Int validate_ttl str_ttl @@ -146,6 +153,9 @@ validateMXRR = toEither <<< validateMXRR_ validateSRVRR :: forall l. SRVRR (|l) -> Either Errors ResourceRecord validateSRVRR = toEither <<< validateSRVRR_ + +-- Full zone validations. + -- type ZoneErrors = Array (Tuple Errors RRId) -- type Zone l = String -> Array (SimpleRR (|l)) -> Array (MXRR (|l)) -> Array (SRVRR (|l)) @@ -222,66 +232,3 @@ toRR_srv :: Int -> Boolean -> String -> String -> Int -> String -> Int -> Int -> toRR_srv rrid readonly rrtype rrname ttl target priority port protocol weight = toRR rrid readonly rrtype rrname ttl target (Just priority) (Just port) (Just protocol) (Just weight) Nothing Nothing Nothing Nothing Nothing Nothing Nothing - -fromLocalSimpleRRRepresentationToResourceRecord :: forall l. SimpleRR (|l) -> ResourceRecord -fromLocalSimpleRRRepresentationToResourceRecord form - = { rrtype: form.rrtype - , rrid: form.rrid - , name: form.name - , ttl: fromMaybe 3600 $ fromString form.ttl - , target: form.target - , readonly: form.readonly - , priority: Nothing - , port: Nothing - , protocol: Nothing - , weight: Nothing - , mname: Nothing - , rname: Nothing - , serial: Nothing - , refresh: Nothing - , retry: Nothing - , expire: Nothing - , minttl: Nothing - } - -fromLocalMXRRRepresentationToResourceRecord :: forall l. MXRR (|l) -> ResourceRecord -fromLocalMXRRRepresentationToResourceRecord form - = { rrtype: form.rrtype - , rrid: form.rrid - , name: form.name - , ttl: fromMaybe 3600 $ fromString form.ttl - , target: form.target - , readonly: form.readonly - , priority: Just $ fromMaybe 10 $ fromString form.priority - , port: Nothing - , protocol: Nothing - , weight: Nothing - , mname: Nothing - , rname: Nothing - , serial: Nothing - , refresh: Nothing - , retry: Nothing - , expire: Nothing - , minttl: Nothing - } - -fromLocalSRVRRepresentationToResourceRecord :: forall l. SRVRR (|l) -> ResourceRecord -fromLocalSRVRRepresentationToResourceRecord form - = { rrtype: form.rrtype - , rrid: form.rrid - , name: form.name - , ttl: fromMaybe 3600 $ fromString form.ttl - , target: form.target - , readonly: form.readonly - , priority: Just $ fromMaybe 10 $ fromString form.priority - , port: Just $ fromMaybe 10 $ fromString form.port - , protocol: Just form.protocol - , weight: Just $ fromMaybe 10 $ fromString form.weight - , mname: Nothing - , rname: Nothing - , serial: Nothing - , refresh: Nothing - , retry: Nothing - , expire: Nothing - , minttl: Nothing - }