@@ -1,140 +0,0 @@
1−module Types where
2−
3−import Data.Bifunctor
4−import Data.ByteString (ByteString)
5−import Data.String
6−import Data.Text as T
7−import Data.Traversable
8−import Database.PostgreSQL.Simple.FromField (FromField)
9−import Database.PostgreSQL.Simple.ToField (ToField)
10−import Deriving.Aeson.Stock
11−import Web.HttpApiData
12−
13−
14−type EnvPair = (Text, Text)
15−
16−type EnvPairs = [EnvPair]
17−
18−-- | Format for command arguments
19−concatPair :: EnvPair -> Text
20−concatPair (k, v) = k <> "=" <> v
21−
22−-- | Format for b2b-helm-tool / helm
23−concatPairWithAppEnv :: EnvPair -> Text
24−concatPairWithAppEnv pair = "b2b-app.env." <> concatPair pair
25−
26−-- | Format for output
27−formatEnvPairs :: EnvPairs -> Text
28−formatEnvPairs = T.unlines . fmap concatPair
29−
30−parseEnvs :: [Text] -> IO [(Text, Text)]
31−parseEnvs texts =
32− for texts $ \t ->
33− case T.findIndex (== '=') t of
34− Just i -> pure $ bimap strip (T.tail . strip) $ T.splitAt i t
35− -- ^ T.splitAt returns pair with not empty Texts, e.g. ("X", "=Y")
36− Nothing -> error $
37− "Malformed environment key-value pair " <> T.unpack t <>
38− ", should be similar to FOO=bar"
39−
40−newtype DeploymentName = DeploymentName { unDeploymentName :: Text }
41− deriving
42− ( Show, Read, FromJSON, ToJSON, FromField, ToField
43− , ToHttpApiData, FromHttpApiData)
44−
45−newtype DeploymentTag = DeploymentTag { unDeploymentTag :: Text }
46− deriving
47− ( Show, FromJSON, ToJSON, FromField, ToField
48− , ToHttpApiData, FromHttpApiData)
49−
50−newtype Action = Action { unAction :: Text }
51− deriving (Show, FromJSON, ToJSON, FromField, ToField, IsString)
52−
53−newtype ArchivedFlag = ArchivedFlag { unArchivedFlag :: Bool }
54− deriving (Show, FromJSON, ToJSON, FromField, ToField)
55−
56−data Deployment = Deployment
57− { name :: DeploymentName
58− , tag :: DeploymentTag
59− , envs :: EnvPairs
60− }
61− deriving (Generic, Show)
62− deriving (FromJSON, ToJSON) via Snake Deployment
63−
64−data DeploymentLog = DeploymentLog
65− { action :: Action
66− , deploymentTag :: DeploymentTag
67− , deploymentEnvs :: EnvPairs
68− , exitCode :: Int
69− , createdAt :: Int
70− }
71− deriving (Generic, Show)
72− deriving (FromJSON, ToJSON) via Snake DeploymentLog
73−
74−data DeploymentInfo = DeploymentInfo
75− { deployment :: Deployment
76− , logs :: [DeploymentLog]
77− }
78− deriving (Generic, Show)
79− deriving (FromJSON, ToJSON) via Snake DeploymentInfo
80−
81−data DeploymentFullInfo = DeploymentFullInfo
82− { deployment :: Deployment
83− , archived :: Bool
84− , createdAt :: Int
85− , updatedAt :: Int
86− , urls :: [(Text, Text)]
87− }
88− deriving (Generic, Show)
89− deriving (FromJSON, ToJSON) via Snake DeploymentFullInfo
90−
91−data DeploymentUpdate = DeploymentUpdate
92− { newTag :: DeploymentTag
93− , newEnvs :: Maybe EnvPairs
94− }
95− deriving (Generic, Show)
96− deriving (FromJSON, ToJSON) via Snake DeploymentUpdate
97−
98−data Status
99− = Ok
100− | Error
101− deriving (Generic, Show)
102− deriving (FromJSON, ToJSON) via Snake Status
103−
104−newtype DeploymentStatus = DeploymentStatus { status :: Status }
105− deriving (Generic, Show)
106− deriving (FromJSON, ToJSON) via Snake DeploymentStatus
107−
108−newtype ServerPort = ServerPort { unServerPort :: Int }
109− deriving (Show)
110−
111−newtype DBPoolSize = DBPoolSize { unDBPoolSize :: Int }
112− deriving (Show)
113−
114−newtype DBConnectionString = DbConnectionString
115− { unDBConnectionString :: ByteString }
116− deriving (Show)
117−
118−newtype TLSCertPath = TLSCertPath { unTLSCertPath :: ByteString }
119− deriving (Show)
120−
121−newtype TLSKeyPath = TLSKeyPath { unTLSKeyPath :: ByteString }
122− deriving (Show)
123−
124−newtype TLSStorePath = TLSStore { unTLSStorePath :: ByteString }
125− deriving (Show)
126−
127−newtype ProjectName = ProjectName { unProjectName :: Text }
128− deriving (Show)
129−
130−newtype Domain = Domain { unDomain :: Text }
131− deriving (Show)
132−
133−newtype Namespace = Namespace { unNamespace :: Text }
134− deriving (Show)
135−
136−newtype ArchiveRetention = ArchiveRetention { unArchiveRetention :: Int }
137− deriving (Show)
138−
139−newtype Command = Command { unCommand :: Text }
140− deriving (Show)