DNSManager messages: mostly done. Build is okay.

beta
Philippe Pittoli 2023-06-17 18:07:24 +02:00
parent 7f50ad1ffe
commit ffecb63c8d
4 changed files with 66 additions and 26 deletions

18
src/App/DNSZone.purs Normal file
View File

@ -0,0 +1,18 @@
module App.DNSZone where
import Prelude
import Data.Codec.Argonaut (JsonCodec)
import Data.Codec.Argonaut as CA
import Data.Newtype (class Newtype)
import Data.Profunctor (wrapIso)
newtype DNSZone = DNSZone String
derive instance newtypeDNSZone :: Newtype DNSZone _
derive instance eqDNSZone :: Eq DNSZone
derive instance ordDNSZone :: Ord DNSZone
-- | DNSZone.codec can be used to parse and encode email addresses.
codec :: JsonCodec DNSZone
codec = wrapIso DNSZone CA.string

View File

@ -13,7 +13,7 @@ codec =
where where
from :: String -> Maybe MaintenanceSubject from :: String -> Maybe MaintenanceSubject
from = case _ of from = case _ of
"verbosity" -> Just None "verbosity" -> Just Verbosity
_ -> Nothing _ -> Nothing
to :: MaintenanceSubject -> String to :: MaintenanceSubject -> String

View File

@ -15,28 +15,35 @@ import Data.Tuple (Tuple(..))
import Data.ArrayBuffer.Types (ArrayBuffer) import Data.ArrayBuffer.Types (ArrayBuffer)
-- import App.PermissionLevel as PermissionLevel -- import App.PermissionLevel as PermissionLevel
import App.MaintenanceSubject as MaintenanceSubject
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
import Data.Argonaut.Parser as JSONParser import Data.Argonaut.Parser as JSONParser
import Data.Bifunctor (lmap) import Data.Bifunctor (lmap)
import App.IPC as IPC import App.IPC as IPC
import App.DNSZone as DNSZone
import App.ResourceRecord as ResourceRecord
{- UserID should be in a separate module with a dedicated codec. -} {- UserID should be in a separate module with a dedicated codec. -}
type UserID = Int -- UserID is either a login or an uid number type UserID = Int -- UserID is either a login or an uid number
{- 7 -} {- 7 -}
data MaintenanceSubject = Verbosity type Maintenance = { subject :: MaintenanceSubject.MaintenanceSubject, value :: Maybe Int }
type Maintenance = { subject :: MaintenanceSubject, value :: Maybe Int } codecMaintenance = CA.object "Maintenance" (CAR.record { subject: MaintenanceSubject.codec, value: CAR.optional CA.int })
codecMaintenance = CA.object "Maintenance" (CAR.record { subject: CA.string, value: CA.int })
{- 0 -} {- 0 -}
type Login = { token :: String } type Login = { token :: String }
codecLogin = CA.object "Login" (CAR.record { token: CA.string }) codecLogin = CA.object "Login" (CAR.record { token: CA.string })
{- 9 -}
type NewDomain = { domain :: String }
codecNewDomain = CA.object "NewDomain" (CAR.record { domain: CA.string })
{- 10 -} {- 10 -}
-- type AddOrUpdateZone = { zone :: DNSManager::Storage::Zone } type AddOrUpdateZone = { zone :: DNSZone.DNSZone }
codecAddOrUpdateZone = CA.object "AddOrUpdateZone" (CAR.record { zone: DNSZone.codec })
{- 11 -} {- 11 -}
type DeleteZone = { domain :: String } type DeleteZone = { domain :: String }
@ -51,12 +58,12 @@ type UserDomains = {}
codecUserDomains = CA.object "UserDomains" (CAR.record {}) codecUserDomains = CA.object "UserDomains" (CAR.record {})
{- 14 -} {- 14 -}
-- type AddRR = { domain :: String, rr :: DNSManager::Storage::Zone::ResourceRecord } type AddRR = { domain :: String, rr :: ResourceRecord.ResourceRecord }
-- codecAddRR = CA.object "AddRR" (CAR.record { domain: CA.string, rr: ResourceRecord.codec }) codecAddRR = CA.object "AddRR" (CAR.record { domain: CA.string, rr: ResourceRecord.codec })
{- 15 -} {- 15 -}
-- type UpdateRR = { domain :: String, rr :: DNSManager::Storage::Zone::ResourceRecord } type UpdateRR = { domain :: String, rr :: ResourceRecord.ResourceRecord }
-- codecUpdateRR = CA.object "UpdateRR" (CAR.record { domain: CA.string, rr: ResourceRecord.codec }) codecUpdateRR = CA.object "UpdateRR" (CAR.record { domain: CA.string, rr: ResourceRecord.codec })
{- 16 -} {- 16 -}
type DeleteRR = { domain :: String, rrid :: Int } type DeleteRR = { domain :: String, rrid :: Int }
@ -68,14 +75,11 @@ codecDeleteRR = CA.object "DeleteRR" (CAR.record { domain: CA.string, rrid: CA.i
RESPONSES RESPONSES
-} -}
-- TODO: Zone actually is a complex data structure.
type DNSZone = String
{- 0 -} {- 0 -}
-- type Error = { reason :: String | Array(String) } -- type Error = { reason :: String | Array(String) }
type Error = { reason :: String } type Error = { reason :: String }
codecGotError ∷ CA.JsonCodec Error codecError ∷ CA.JsonCodec Error
codecGotError = CA.object "Error" (CAR.record { reason: CA.string }) codecError = CA.object "Error" (CAR.record { reason: CA.string })
{- 1 -} {- 1 -}
type Success = { } type Success = { }
@ -106,9 +110,9 @@ codecDomainChanged = CA.object "DomainChanged" (CAR.record { })
{- 12 -} {- 12 -}
-- TODO -- TODO
type Zone = { zone :: DNSZone } type Zone = { zone :: DNSZone.DNSZone }
codecZone ∷ CA.JsonCodec Zone codecZone ∷ CA.JsonCodec Zone
codecZone = CA.object "Zone" (CAR.record { zone: CA.string }) codecZone = CA.object "Zone" (CAR.record { zone: DNSZone.codec })
{- 13 -} {- 13 -}
type UnknownZone = { } type UnknownZone = { }

View File

@ -0,0 +1,18 @@
module App.ResourceRecord where
import Prelude
import Data.Codec.Argonaut (JsonCodec)
import Data.Codec.Argonaut as CA
import Data.Newtype (class Newtype)
import Data.Profunctor (wrapIso)
newtype ResourceRecord = ResourceRecord String
derive instance newtypeResourceRecord :: Newtype ResourceRecord _
derive instance eqResourceRecord :: Eq ResourceRecord
derive instance ordResourceRecord :: Ord ResourceRecord
-- | ResourceRecord.codec can be used to parse and encode email addresses.
codec :: JsonCodec ResourceRecord
codec = wrapIso ResourceRecord CA.string