Skip to content
Snippets Groups Projects
Commit 71f89c1a authored by Eduardo Trujillo's avatar Eduardo Trujillo
Browse files

Make CSP directives more Yaml/Json friendly

parent 7eb4928f
No related branches found
No related tags found
Loading
Checking pipeline status
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
{-# LANGUAGE ApplicativeDo #-} {-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
-- | -- |
-- --
...@@ -40,15 +41,21 @@ type Parser = Parsec Void Text ...@@ -40,15 +41,21 @@ type Parser = Parsec Void Text
data SchemePart = SchemePart Text deriving (Show, Eq, Generic) data SchemePart = SchemePart Text deriving (Show, Eq, Generic)
data PortPart = SpecificPort Integer | AnyPort deriving (Show, Eq, Generic) data PortPart = SpecificPort Integer | AnyPort deriving (Show, Eq, Generic)
data HostPart = AnyHostPart | DomainHostPart Bool Text deriving (Show, Eq, Generic) data HostPart
= AnyHostPart
| DomainHostPart
{ wildcard :: Bool
, domain :: Text
}
deriving (Show, Eq, Generic)
data PathPart = PathPart Text deriving (Show, Eq, Generic) data PathPart = PathPart Text deriving (Show, Eq, Generic)
instance ToCSP SchemePart where instance ToCSP SchemePart where
toCSP (SchemePart scheme) = scheme toCSP (SchemePart scheme_) = scheme_
instance FromJSON SchemePart instance FromJSON SchemePart
instance ToCSP PortPart where instance ToCSP PortPart where
toCSP (SpecificPort port) = T.pack . show $ port toCSP (SpecificPort port_) = T.pack . show $ port_
toCSP AnyPort = "*" toCSP AnyPort = "*"
instance FromJSON PortPart instance FromJSON PortPart
...@@ -60,7 +67,7 @@ instance ToCSP HostPart where ...@@ -60,7 +67,7 @@ instance ToCSP HostPart where
instance FromJSON HostPart instance FromJSON HostPart
instance ToCSP PathPart where instance ToCSP PathPart where
toCSP (PathPart path) = path toCSP (PathPart path_) = path_
instance FromJSON PathPart instance FromJSON PathPart
alphaChar :: Parser Char alphaChar :: Parser Char
...@@ -198,7 +205,12 @@ pHashAlgorithm = choice ...@@ -198,7 +205,12 @@ pHashAlgorithm = choice
data SourceExpression data SourceExpression
= SchemeSource SchemePart = SchemeSource SchemePart
| HostSource (Maybe SchemePart) HostPart (Maybe PortPart) (Maybe PathPart) | HostSource
{ scheme :: Maybe SchemePart
, host :: HostPart
, port :: Maybe PortPart
, path :: Maybe PathPart
}
| KeywordSource Keyword | KeywordSource Keyword
| NonceSource Text | NonceSource Text
| HashSource HashAlgorithm Text | HashSource HashAlgorithm Text
...@@ -247,7 +259,12 @@ pSourceExpression = choice ...@@ -247,7 +259,12 @@ pSourceExpression = choice
data AncestorSource data AncestorSource
= AncestorSchemeSource SchemePart = AncestorSchemeSource SchemePart
| AncestorHostSource (Maybe SchemePart) HostPart (Maybe PortPart) (Maybe PathPart) | AncestorHostSource
{ scheme :: Maybe SchemePart
, host :: HostPart
, port :: Maybe PortPart
, path :: Maybe PathPart
}
| AncestorSelfSource | AncestorSelfSource
deriving (Show, Eq, Generic) deriving (Show, Eq, Generic)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment