/
Config.purs
90 lines (71 loc) · 2.67 KB
/
Config.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
module Kubernetes.Config where
import Prelude
import Data.Lens (Lens')
import Data.Lens.Record (prop)
import Data.Lens.Iso.Newtype (_Newtype)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
import Data.Symbol (SProxy(SProxy))
import Effect.Aff (Aff)
import Kubernetes.Default (class Default)
import Kubernetes.Request as Req
import Node.Encoding as Encoding
import Node.FS.Aff as FS
newtype Config = Config
{ basicAuth :: Maybe BasicAuth
, bearerToken :: Maybe String
, cluster :: ClusterConfig
, tls :: TLSConfig }
derive instance newtypeConfig :: Newtype Config _
derive instance genericConfig :: Generic Config _
instance defaultConfig :: Default Config where
default = Config $
{ basicAuth: Nothing
, bearerToken: Nothing
, cluster:
{ host: "localhost"
, port: 8080
, protocol: Req.ProtocolHTTP }
, tls:
{ caCert: Nothing
, clientCert: Nothing
, clientKey: Nothing
, verifyServerCert: true } }
-- | Basic authentication should be used for development/testing only.
type BasicAuth =
{ user :: String
, password :: String }
type ClusterConfig =
{ host :: String
, port :: Int
, protocol :: Req.Protocol }
type TLSConfig =
{ caCert :: Maybe String
, clientCert :: Maybe String
, clientKey :: Maybe String
, verifyServerCert :: Boolean }
loadFile :: String -> Aff String
loadFile = FS.readTextFile Encoding.UTF8
_basicAuth :: forall s a r. Newtype s { basicAuth :: a | r } => Lens' s a
_basicAuth = _Newtype <<< prop (SProxy :: SProxy "basicAuth")
_bearerToken :: forall s a r. Newtype s { bearerToken :: a | r } => Lens' s a
_bearerToken = _Newtype <<< prop (SProxy :: SProxy "bearerToken")
_cluster :: forall s a r. Newtype s { cluster :: a | r } => Lens' s a
_cluster = _Newtype <<< prop (SProxy :: SProxy "cluster")
_tls :: forall s a r. Newtype s { tls :: a | r } => Lens' s a
_tls = _Newtype <<< prop (SProxy :: SProxy "tls")
_host :: forall a r. Lens' { host :: a | r } a
_host = prop (SProxy :: SProxy "host")
_port :: forall a r. Lens' { port :: a | r } a
_port = prop (SProxy :: SProxy "port")
_protocol :: forall a r. Lens' { protocol :: a | r } a
_protocol = prop (SProxy :: SProxy "protocol")
_caCert :: forall a r. Lens' { caCert :: a | r } a
_caCert = prop (SProxy :: SProxy "caCert")
_clientCert :: forall a r. Lens' { clientCert :: a | r } a
_clientCert = prop (SProxy :: SProxy "clientCert")
_clientKey :: forall a r. Lens' { clientKey :: a | r } a
_clientKey = prop (SProxy :: SProxy "clientKey")
_verifyServerCert :: forall a r. Lens' { verifyServerCert :: a | r } a
_verifyServerCert = prop (SProxy :: SProxy "verifyServerCert")