Simplify the Host datatype.
This commit is contained in:
parent
ce4e99b7d6
commit
f2d0a73aa8
@ -55,7 +55,7 @@ main = do
|
||||
|
||||
login :: Conf -> IO (Either LdapError ())
|
||||
login conf =
|
||||
Ldap.with (Ldap.Secure (host conf)) (port conf) $ \l -> do
|
||||
Ldap.with (Ldap.Tls (host conf) Ldap.defaultTlsSettings) (port conf) $ \l -> do
|
||||
Ldap.bind l (dn conf) (password conf)
|
||||
fix $ \loop -> do
|
||||
uid <- prompt "Username: "
|
||||
|
||||
@ -10,6 +10,8 @@
|
||||
module Ldap.Client
|
||||
( with
|
||||
, Host(..)
|
||||
, defaultTlsSettings
|
||||
, insecureTlsSettings
|
||||
, PortNumber
|
||||
, Ldap
|
||||
, LdapError(..)
|
||||
@ -162,26 +164,28 @@ with host port f = do
|
||||
{ Conn.connectionHostname =
|
||||
case host of
|
||||
Plain h -> h
|
||||
Secure h -> h
|
||||
SecureWithTLSSettings h _ -> h
|
||||
Insecure h -> h
|
||||
Tls h _ -> h
|
||||
, Conn.connectionPort = port
|
||||
, Conn.connectionUseSecure =
|
||||
case host of
|
||||
Plain _ -> Nothing
|
||||
Secure _ -> Just Conn.TLSSettingsSimple
|
||||
Tls _ settings -> pure settings
|
||||
, Conn.connectionUseSocks = Nothing
|
||||
}
|
||||
|
||||
defaultTlsSettings :: Conn.TLSSettings
|
||||
defaultTlsSettings = Conn.TLSSettingsSimple
|
||||
{ Conn.settingDisableCertificateValidation = False
|
||||
, Conn.settingDisableSession = False
|
||||
, Conn.settingUseServerName = False
|
||||
}
|
||||
SecureWithTLSSettings _ settings -> Just settings
|
||||
Insecure _ -> Just Conn.TLSSettingsSimple
|
||||
|
||||
insecureTlsSettings :: Conn.TLSSettings
|
||||
insecureTlsSettings = Conn.TLSSettingsSimple
|
||||
{ Conn.settingDisableCertificateValidation = True
|
||||
, Conn.settingDisableSession = False
|
||||
, Conn.settingUseServerName = False
|
||||
}
|
||||
, Conn.connectionUseSocks = Nothing
|
||||
}
|
||||
|
||||
input :: FromAsn1 a => TQueue a -> Connection -> IO b
|
||||
input inq conn = wrap . flip fix [] $ \loop chunks -> do
|
||||
|
||||
@ -44,10 +44,7 @@ import qualified Ldap.Asn1.Type as Type
|
||||
-- | LDAP host.
|
||||
data Host =
|
||||
Plain String -- ^ Plain LDAP.
|
||||
| Insecure String -- ^ LDAP over TLS without the certificate validity check.
|
||||
| Secure String -- ^ LDAP over TLS.
|
||||
| SecureWithTLSSettings String TLSSettings
|
||||
-- ^ LDAP over TLS with the ability to specify detailed TLS settings.
|
||||
| Tls String TLSSettings -- ^ LDAP over TLS.
|
||||
deriving (Show)
|
||||
|
||||
-- | A token. All functions that interact with the Directory require one.
|
||||
|
||||
@ -53,7 +53,7 @@ locally f =
|
||||
(\_ -> Ldap.with localhost port f)
|
||||
|
||||
localhost :: Host
|
||||
localhost = Insecure "localhost"
|
||||
localhost = Tls "localhost" insecureTlsSettings
|
||||
|
||||
port :: Num a => a
|
||||
port = 24620
|
||||
|
||||
Loading…
Reference in New Issue
Block a user