{-# LANGUAGE CPP #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -fno-warn-unused-imports#-}
module Data.KeyStore.PasswordManager
( PMConfig(..)
, PW(..)
, PW_(..)
, SessionDescriptor(..)
, CollectConfig(..)
, defaultCollectConfig
, Password(..)
, PasswordName(..)
, PasswordText(..)
, SessionName(..)
, EnvVar(..)
, passwordManager
, defaultHashDescription
, defaultSampleScript
, hashMasterPassword
, bindMasterPassword
, setup
, login
, passwordValid
, passwordValid'
, isStorePresent
, amLoggedIn
, isBound
, import_
, load
, loadPlus
, psComment
, collect
, prime
, select
, deletePassword
, deletePasswordPlus
, deleteSession
, status
, prompt
, passwords
, passwordsPlus
, sessions
, infoPassword
, infoPassword_
, infoPasswordPlus
, infoPasswordPlus_
, dump
, collectShell
, passwordManager'
, PMCommand(..)
, pmCommandParser
, getStore
) where
import Data.KeyStore.Types.PasswordStoreModel
import Data.KeyStore.Types
import Data.KeyStore.KS.Crypto
import Data.KeyStore.KS.CPRNG
import Data.KeyStore.Version
import qualified Data.Aeson as A
import qualified Data.ByteString.Char8 as B
import qualified Data.ByteString.Lazy as BL
import qualified Data.ByteString.Base64 as B64
import qualified Data.Text as T
import qualified Data.Map as Map
import Data.Time
import Data.Monoid
import Data.API.Types
import Data.API.JSON
import Data.Maybe
import qualified Text.PrettyPrint.ANSI.Leijen as P
import Text.Printf
import qualified Control.Lens as L
import Control.Applicative
import Control.Exception
import Control.Monad
import System.Directory
import qualified System.Environment as E
import System.SetEnv
import System.Exit
import System.IO
import qualified Options.Applicative as O
import Options.Applicative
#if MIN_VERSION_time(1,5,0)
#else
import System.Locale (defaultTimeLocale)
#endif
data PMConfig p =
PMConfig
{ PMConfig p -> FilePath
_pmc_location :: FilePath
, PMConfig p -> EnvVar
_pmc_env_var :: EnvVar
, PMConfig p -> FilePath
_pmc_keystore_msg :: String
, PMConfig p -> FilePath
_pmc_password_msg :: String
, PMConfig p -> IO ()
_pmc_shell :: IO ()
, PMConfig p -> HashDescription
_pmc_hash_descr :: HashDescription
, PMConfig p -> Bool
_pmc_allow_dumps :: Bool
, PMConfig p -> FilePath
_pmc_dump_prefix :: String
, PMConfig p -> Maybe FilePath
_pmc_sample_script :: Maybe String
, PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
}
class (Bounded p,Enum p,Eq p, Ord p,Show p) => PW p where
pwName :: p -> PasswordName
pwName = Text -> PasswordName
PasswordName (Text -> PasswordName) -> (p -> Text) -> p -> PasswordName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
T.pack (FilePath -> Text) -> (p -> FilePath) -> p -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p -> FilePath
forall a. Show a => a -> FilePath
show
parsePwName :: PasswordName -> Maybe p
parsePwName = \PasswordName
pnm -> [p] -> Maybe p
forall a. [a] -> Maybe a
listToMaybe [ p
p | p
p<-[p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound], p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p PasswordName -> PasswordName -> Bool
forall a. Eq a => a -> a -> Bool
== PasswordName
pnm ]
isSession :: p -> Maybe (PasswordText -> Either String SessionDescriptor)
isSession = Maybe (PasswordText -> Either FilePath SessionDescriptor)
-> p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall a b. a -> b -> a
const Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall a. Maybe a
Nothing
isOneShot :: p -> Bool
isOneShot = Bool -> p -> Bool
forall a b. a -> b -> a
const Bool
False
enVar :: p -> EnvVar
enVar = Text -> EnvVar
EnvVar (Text -> EnvVar) -> (p -> Text) -> p -> EnvVar
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Text -> Text -> Text
T.append Text
"KEY_pw_") (Text -> Text) -> (p -> Text) -> p -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PasswordName -> Text
_PasswordName (PasswordName -> Text) -> (p -> PasswordName) -> p -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. p -> PasswordName
forall p. PW p => p -> PasswordName
pwName
summarize :: p -> String
summarize p
_ = FilePath
""
describe :: p -> String
describe p
p = (Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName (PasswordName -> Text) -> PasswordName -> Text
forall a b. (a -> b) -> a -> b
$ p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p) FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
": description to follow"
data PW_ p = PW_
cast_pmc :: PMConfig p -> p -> p
cast_pmc :: PMConfig p -> p -> p
cast_pmc PMConfig p
_ p
p = p
p
cast_pw :: PW_ p -> p -> p
cast_pw :: PW_ p -> p -> p
cast_pw PW_ p
_ p
p = p
p
data SessionDescriptor =
SessionDescriptor
{ SessionDescriptor -> SessionName
_sd_name :: SessionName
, SessionDescriptor -> Bool
_sd_isOneShot :: Bool
}
deriving (Int -> SessionDescriptor -> FilePath -> FilePath
[SessionDescriptor] -> FilePath -> FilePath
SessionDescriptor -> FilePath
(Int -> SessionDescriptor -> FilePath -> FilePath)
-> (SessionDescriptor -> FilePath)
-> ([SessionDescriptor] -> FilePath -> FilePath)
-> Show SessionDescriptor
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
showList :: [SessionDescriptor] -> FilePath -> FilePath
$cshowList :: [SessionDescriptor] -> FilePath -> FilePath
show :: SessionDescriptor -> FilePath
$cshow :: SessionDescriptor -> FilePath
showsPrec :: Int -> SessionDescriptor -> FilePath -> FilePath
$cshowsPrec :: Int -> SessionDescriptor -> FilePath -> FilePath
Show)
data CollectConfig p =
CollectConfig
{ CollectConfig p -> Bool
_cc_optional :: Bool
, CollectConfig p -> [p]
_cc_active :: [p]
}
defaultCollectConfig :: PW p => CollectConfig p
defaultCollectConfig :: CollectConfig p
defaultCollectConfig =
CollectConfig :: forall p. Bool -> [p] -> CollectConfig p
CollectConfig
{ _cc_optional :: Bool
_cc_optional = Bool
True
, _cc_active :: [p]
_cc_active = [p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound]
}
passwordManager :: PW p => PMConfig p -> [String] -> IO ()
passwordManager :: PMConfig p -> [FilePath] -> IO ()
passwordManager PMConfig p
pmc [FilePath]
args = PMConfig p -> [FilePath] -> IO (PMCommand p)
forall p. PW p => PMConfig p -> [FilePath] -> IO (PMCommand p)
parsePMCommand PMConfig p
pmc [FilePath]
args IO (PMCommand p) -> (PMCommand p -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PMConfig p -> PMCommand p -> IO ()
forall p. PW p => PMConfig p -> PMCommand p -> IO ()
passwordManager' PMConfig p
pmc
defaultHashDescription :: Salt -> HashDescription
defaultHashDescription :: Salt -> HashDescription
defaultHashDescription Salt
st =
HashDescription :: Comment
-> HashPRF
-> Iterations
-> Octets
-> Octets
-> Salt
-> HashDescription
HashDescription
{ _hashd_comment :: Comment
_hashd_comment = Comment
"PM master password"
, _hashd_prf :: HashPRF
_hashd_prf = HashPRF
PRF_sha512
, _hashd_iterations :: Iterations
_hashd_iterations = Iterations
5000
, _hashd_width_octets :: Octets
_hashd_width_octets = Octets
32
, _hashd_salt_octets :: Octets
_hashd_salt_octets = Int -> Octets
Octets (Int -> Octets) -> Int -> Octets
forall a b. (a -> b) -> a -> b
$ ByteString -> Int
B.length (ByteString -> Int) -> ByteString -> Int
forall a b. (a -> b) -> a -> b
$ Binary -> ByteString
_Binary (Binary -> ByteString) -> Binary -> ByteString
forall a b. (a -> b) -> a -> b
$ Salt -> Binary
_Salt Salt
st
, _hashd_salt :: Salt
_hashd_salt = Salt
st
}
defaultSampleScript :: PW p => PW_ p -> String -> String
defaultSampleScript :: PW_ p -> FilePath -> FilePath
defaultSampleScript PW_ p
pw_ FilePath
pfx = FilePath
-> PasswordStoreComment
-> [(p, PasswordText)]
-> [(p, SessionName)]
-> FilePath
forall p.
PW p =>
FilePath
-> PasswordStoreComment
-> [(p, PasswordText)]
-> [(p, SessionName)]
-> FilePath
format_dump FilePath
pfx PasswordStoreComment
cmt ((p -> (p, PasswordText)) -> [p] -> [(p, PasswordText)]
forall a b. (a -> b) -> [a] -> [b]
map p -> (p, PasswordText)
f [p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound]) []
where
f :: p -> (p, PasswordText)
f p
p = (,) p
p (PasswordText -> (p, PasswordText))
-> PasswordText -> (p, PasswordText)
forall a b. (a -> b) -> a -> b
$ Text -> PasswordText
PasswordText (Text -> PasswordText) -> Text -> PasswordText
forall a b. (a -> b) -> a -> b
$ Text
"secret-" Text -> Text -> Text
`T.append` PasswordName -> Text
_PasswordName (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName (p -> PasswordName) -> p -> PasswordName
forall a b. (a -> b) -> a -> b
$ PW_ p -> p -> p
forall p. PW_ p -> p -> p
cast_pw PW_ p
pw_ p
p)
cmt :: PasswordStoreComment
cmt = Text -> PasswordStoreComment
PasswordStoreComment (Text -> PasswordStoreComment) -> Text -> PasswordStoreComment
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack FilePath
"loaded by the sample script"
hashMasterPassword :: PW p => PMConfig p -> String -> PasswordText
hashMasterPassword :: PMConfig p -> FilePath -> PasswordText
hashMasterPassword PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} FilePath
pw =
Text -> PasswordText
PasswordText (Text -> PasswordText) -> Text -> PasswordText
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ ByteString -> FilePath
B.unpack (ByteString -> FilePath) -> ByteString -> FilePath
forall a b. (a -> b) -> a -> b
$
ByteString -> ByteString
B64.encode (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ Binary -> ByteString
_Binary (Binary -> ByteString) -> Binary -> ByteString
forall a b. (a -> b) -> a -> b
$ HashData -> Binary
_HashData (HashData -> Binary) -> HashData -> Binary
forall a b. (a -> b) -> a -> b
$ Hash -> HashData
_hash_hash (Hash -> HashData) -> Hash -> HashData
forall a b. (a -> b) -> a -> b
$
HashDescription -> ClearText -> Hash
hashKS_ HashDescription
_pmc_hash_descr (ClearText -> Hash) -> ClearText -> Hash
forall a b. (a -> b) -> a -> b
$ Binary -> ClearText
ClearText (Binary -> ClearText) -> Binary -> ClearText
forall a b. (a -> b) -> a -> b
$ ByteString -> Binary
Binary (ByteString -> Binary) -> ByteString -> Binary
forall a b. (a -> b) -> a -> b
$ FilePath -> ByteString
B.pack FilePath
pw
bindMasterPassword :: PW p => PMConfig p -> PasswordText -> IO ()
bindMasterPassword :: PMConfig p -> PasswordText -> IO ()
bindMasterPassword PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} = EnvVar -> PasswordText -> IO ()
set_env EnvVar
_pmc_env_var
setup :: PW p
=> PMConfig p
-> Bool
-> Maybe PasswordText
-> IO ()
setup :: PMConfig p -> Bool -> Maybe PasswordText -> IO ()
setup PMConfig p
pmc Bool
no_li Maybe PasswordText
mb_pwt = do
Bool
ex <- FilePath -> IO Bool
doesFileExist FilePath
_pmc_location
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
ex (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ()
forall a. HasCallStack => FilePath -> a
error (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath
"password store already exists in: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
_pmc_location
PasswordText
pwt <- IO PasswordText
-> (PasswordText -> IO PasswordText)
-> Maybe PasswordText
-> IO PasswordText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> PMConfig p -> IO PasswordText
forall p. PW p => Bool -> PMConfig p -> IO PasswordText
get_pw Bool
True PMConfig p
pmc) PasswordText -> IO PasswordText
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PasswordText
mb_pwt
PasswordText
pwt' <- IO PasswordText
-> (PasswordText -> IO PasswordText)
-> Maybe PasswordText
-> IO PasswordText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> PMConfig p -> IO PasswordText
forall p. PW p => Bool -> PMConfig p -> IO PasswordText
get_pw Bool
True PMConfig p
pmc) PasswordText -> IO PasswordText
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PasswordText
mb_pwt
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (PasswordText
pwtPasswordText -> PasswordText -> Bool
forall a. Eq a => a -> a -> Bool
/=PasswordText
pwt') (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ()
forall a. HasCallStack => FilePath -> a
error FilePath
"passwords do not match"
UTCTime
now <- IO UTCTime
getCurrentTime
let ps :: PasswordStore
ps =
PasswordStore :: PasswordStoreComment -> PasswordMap -> UTCTime -> PasswordStore
PasswordStore
{ _ps_comment :: PasswordStoreComment
_ps_comment = Text -> PasswordStoreComment
PasswordStoreComment (Text -> PasswordStoreComment) -> Text -> PasswordStoreComment
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ FilePath
"Created at " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ UTCTime -> FilePath
forall a. Show a => a -> FilePath
show UTCTime
now
, _ps_map :: PasswordMap
_ps_map = PasswordMap
forall k a. Map k a
Map.empty
, _ps_setup :: UTCTime
_ps_setup = UTCTime
now
}
PMConfig p -> AESKey -> PasswordStore -> IO ()
forall p. PW p => PMConfig p -> AESKey -> PasswordStore -> IO ()
save_ps PMConfig p
pmc (PasswordText -> AESKey
mk_aek PasswordText
pwt) PasswordStore
ps
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
no_li) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ PMConfig p -> Bool -> Maybe PasswordText -> IO ()
forall p. PW p => PMConfig p -> Bool -> Maybe PasswordText -> IO ()
login PMConfig p
pmc Bool
False (Maybe PasswordText -> IO ()) -> Maybe PasswordText -> IO ()
forall a b. (a -> b) -> a -> b
$ PasswordText -> Maybe PasswordText
forall a. a -> Maybe a
Just PasswordText
pwt
where
PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} = PMConfig p
pmc
login :: PW p => PMConfig p -> Bool -> Maybe PasswordText -> IO ()
login :: PMConfig p -> Bool -> Maybe PasswordText -> IO ()
login PMConfig p
pmc Bool
y Maybe PasswordText
mb = do
PasswordText
pwt <- IO PasswordText
-> (PasswordText -> IO PasswordText)
-> Maybe PasswordText
-> IO PasswordText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> PMConfig p -> IO PasswordText
forall p. PW p => Bool -> PMConfig p -> IO PasswordText
get_pw Bool
True PMConfig p
pmc) PasswordText -> IO PasswordText
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PasswordText
mb
Bool
ok <- PMConfig p -> PasswordText -> IO Bool
forall p. PW p => PMConfig p -> PasswordText -> IO Bool
passwordValid PMConfig p
pmc PasswordText
pwt
case Bool
ok of
Bool
True -> PMConfig p -> PasswordText -> IO ()
forall p. PW p => PMConfig p -> PasswordText -> IO ()
bindMasterPassword PMConfig p
pmc PasswordText
pwt IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> IO ()
good IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMConfig p -> IO ()
forall p. PMConfig p -> IO ()
_pmc_shell PMConfig p
pmc
Bool
False -> IO ()
bad IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMConfig p -> Bool -> Maybe PasswordText -> IO ()
forall p. PW p => PMConfig p -> Bool -> Maybe PasswordText -> IO ()
login PMConfig p
pmc Bool
y Maybe PasswordText
forall a. Maybe a
Nothing
where
good :: IO ()
good = FilePath -> IO ()
putStr FilePath
"*** Login Successful ***\n"
bad :: IO ()
bad = FilePath -> IO ()
bad_f FilePath
"*** Password Invalid ***\n"
bad_f :: FilePath -> IO ()
bad_f = if Bool
y then FilePath -> IO ()
putStr else FilePath -> IO ()
forall a. HasCallStack => FilePath -> a
error
passwordValid :: PW p => PMConfig p -> PasswordText -> IO Bool
passwordValid :: PMConfig p -> PasswordText -> IO Bool
passwordValid PMConfig p
pmc PasswordText
pwt = Maybe PasswordStore -> Bool
forall a. Maybe a -> Bool
isJust (Maybe PasswordStore -> Bool)
-> IO (Maybe PasswordStore) -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PMConfig p -> FilePath -> PasswordText -> IO (Maybe PasswordStore)
forall p.
PW p =>
PMConfig p -> FilePath -> PasswordText -> IO (Maybe PasswordStore)
passwordValid' PMConfig p
pmc (PMConfig p -> FilePath
forall p. PMConfig p -> FilePath
_pmc_location PMConfig p
pmc) PasswordText
pwt
passwordValid' :: PW p => PMConfig p -> FilePath -> PasswordText -> IO (Maybe PasswordStore)
passwordValid' :: PMConfig p -> FilePath -> PasswordText -> IO (Maybe PasswordStore)
passwordValid' PMConfig p
pmc FilePath
fp = PMConfig p -> FilePath -> AESKey -> IO (Maybe PasswordStore)
forall p.
PW p =>
PMConfig p -> FilePath -> AESKey -> IO (Maybe PasswordStore)
password_valid PMConfig p
pmc FilePath
fp (AESKey -> IO (Maybe PasswordStore))
-> (PasswordText -> AESKey)
-> PasswordText
-> IO (Maybe PasswordStore)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PasswordText -> AESKey
mk_aek
isStorePresent :: PW p => PMConfig p -> IO Bool
isStorePresent :: PMConfig p -> IO Bool
isStorePresent PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} = FilePath -> IO Bool
doesFileExist FilePath
_pmc_location
amLoggedIn :: PW p => PMConfig p -> IO Bool
amLoggedIn :: PMConfig p -> IO Bool
amLoggedIn PMConfig p
pmc = (IO Bool -> (SomeException -> IO Bool) -> IO Bool)
-> (SomeException -> IO Bool) -> IO Bool -> IO Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO Bool -> (SomeException -> IO Bool) -> IO Bool
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch SomeException -> IO Bool
forall (m :: * -> *). Monad m => SomeException -> m Bool
hdl (IO Bool -> IO Bool) -> IO Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$
Maybe PasswordStore -> Bool
forall a. Maybe a -> Bool
isJust (Maybe PasswordStore -> Bool)
-> IO (Maybe PasswordStore) -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (PMConfig p -> IO AESKey
forall p. PW p => PMConfig p -> IO AESKey
get_key PMConfig p
pmc IO AESKey
-> (AESKey -> IO (Maybe PasswordStore)) -> IO (Maybe PasswordStore)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PMConfig p -> FilePath -> AESKey -> IO (Maybe PasswordStore)
forall p.
PW p =>
PMConfig p -> FilePath -> AESKey -> IO (Maybe PasswordStore)
password_valid PMConfig p
pmc (PMConfig p -> FilePath
forall p. PMConfig p -> FilePath
_pmc_location PMConfig p
pmc))
where
hdl :: SomeException -> m Bool
hdl (SomeException
_::SomeException) = Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
isBound :: PW p => PMConfig p -> p -> Maybe SessionName -> IO Bool
isBound :: PMConfig p -> p -> Maybe SessionName -> IO Bool
isBound PMConfig p
pmc p
p Maybe SessionName
mb = PMConfig p -> (PasswordStore -> IO Bool) -> IO Bool
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc ((PasswordStore -> IO Bool) -> IO Bool)
-> (PasswordStore -> IO Bool) -> IO Bool
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IO Bool) -> Bool -> IO Bool
forall a b. (a -> b) -> a -> b
$
case PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p) (PasswordMap -> Maybe Password) -> PasswordMap -> Maybe Password
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps of
Maybe Password
Nothing -> Bool
False
Just Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
..} -> Bool -> (SessionName -> Bool) -> Maybe SessionName -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (\SessionName
snm->SessionName -> SessionMap -> Bool
forall k a. Ord k => k -> Map k a -> Bool
Map.member SessionName
snm (SessionMap -> Bool) -> SessionMap -> Bool
forall a b. (a -> b) -> a -> b
$ SessionMap
_pw_sessions) Maybe SessionName
mb
import_ :: PW p => PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
import_ :: PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
import_ = Bool -> PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
forall p.
PW p =>
Bool -> PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
import__ Bool
False
import__ :: PW p => Bool -> PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
import__ :: Bool -> PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
import__ Bool
x_pps PMConfig p
pmc FilePath
fp0 Maybe PasswordText
mb = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> do
FilePath
fp <- FilePath -> IO FilePath
tilde FilePath
fp0
Bool
ok <- FilePath -> IO Bool
doesFileExist FilePath
fp
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
ok) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath -> IO ()
forall a. HasCallStack => FilePath -> a
error FilePath
"*** password store not found ***"
PasswordText
pwt <- IO PasswordText
-> (PasswordText -> IO PasswordText)
-> Maybe PasswordText
-> IO PasswordText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> PMConfig p -> IO PasswordText
forall p. PW p => Bool -> PMConfig p -> IO PasswordText
get_pw Bool
True PMConfig p
pmc) PasswordText -> IO PasswordText
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PasswordText
mb
Maybe PasswordStore
mb_ps <- PMConfig p -> FilePath -> PasswordText -> IO (Maybe PasswordStore)
forall p.
PW p =>
PMConfig p -> FilePath -> PasswordText -> IO (Maybe PasswordStore)
passwordValid' PMConfig p
pmc FilePath
fp PasswordText
pwt
case Maybe PasswordStore
mb_ps of
Maybe PasswordStore
Nothing -> FilePath -> IO (Maybe PasswordStore)
forall a. HasCallStack => FilePath -> a
error FilePath
"*** Password Invalid ***\n"
Just PasswordStore
ps' -> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ Bool -> PasswordStore -> PasswordStore -> PasswordStore
merge_ps Bool
x_pps PasswordStore
ps PasswordStore
ps'
where
tilde :: FilePath -> IO FilePath
tilde (Char
'~':t :: FilePath
t@(Char
'/':FilePath
_)) = do
Maybe FilePath
mb_hm <- FilePath -> IO (Maybe FilePath)
E.lookupEnv FilePath
"HOME"
FilePath -> IO FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return (FilePath -> IO FilePath) -> FilePath -> IO FilePath
forall a b. (a -> b) -> a -> b
$ (FilePath -> Maybe FilePath -> FilePath
forall a. a -> Maybe a -> a
fromMaybe FilePath
"/" Maybe FilePath
mb_hm) FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
t
tilde FilePath
fp = FilePath -> IO FilePath
forall (m :: * -> *) a. Monad m => a -> m a
return FilePath
fp
load :: PW p => PMConfig p -> p -> Maybe PasswordText -> IO ()
load :: PMConfig p -> p -> Maybe PasswordText -> IO ()
load PMConfig p
pmc p
p Maybe PasswordText
mb = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> do
PasswordText
pwt <- IO PasswordText
-> (PasswordText -> IO PasswordText)
-> Maybe PasswordText
-> IO PasswordText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> PMConfig p -> IO PasswordText
forall p. PW p => Bool -> PMConfig p -> IO PasswordText
get_pw Bool
False PMConfig p
pmc) PasswordText -> IO PasswordText
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PasswordText
mb
UTCTime
now <- IO UTCTime
getCurrentTime
case p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession p
p of
Maybe (PasswordText -> Either FilePath SessionDescriptor)
Nothing -> PasswordStore -> Password -> IO (Maybe PasswordStore)
forall (m :: * -> *).
Monad m =>
PasswordStore -> Password -> m (Maybe PasswordStore)
load_pwd PasswordStore
ps
Password :: PasswordName
-> PasswordText
-> SessionMap
-> Bool
-> Bool
-> UTCTime
-> Password
Password
{ _pw_name :: PasswordName
_pw_name = PasswordName
pnm
, _pw_text :: PasswordText
_pw_text = PasswordText
pwt
, _pw_sessions :: SessionMap
_pw_sessions = SessionMap
forall k a. Map k a
Map.empty
, _pw_isOneShot :: Bool
_pw_isOneShot = p -> Bool
forall p. PW p => p -> Bool
isOneShot p
p
, _pw_primed :: Bool
_pw_primed = Bool
False
, _pw_setup :: UTCTime
_pw_setup = UTCTime
now
}
Just PasswordText -> Either FilePath SessionDescriptor
ext ->
case PasswordText -> Either FilePath SessionDescriptor
ext PasswordText
pwt of
Left FilePath
err -> FilePath -> IO (Maybe PasswordStore)
forall a. FilePath -> a
ssn_error (FilePath -> IO (Maybe PasswordStore))
-> FilePath -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ FilePath
"failed to load session: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
err
Right SessionDescriptor
sd -> UTCTime
-> PasswordStore
-> PasswordText
-> SessionDescriptor
-> IO (Maybe PasswordStore)
forall (m :: * -> *).
Monad m =>
UTCTime
-> PasswordStore
-> PasswordText
-> SessionDescriptor
-> m (Maybe PasswordStore)
load_ssn UTCTime
now PasswordStore
ps PasswordText
pwt SessionDescriptor
sd
where
load_ssn :: UTCTime
-> PasswordStore
-> PasswordText
-> SessionDescriptor
-> m (Maybe PasswordStore)
load_ssn UTCTime
now PasswordStore
ps PasswordText
pwt SessionDescriptor{Bool
SessionName
_sd_isOneShot :: Bool
_sd_name :: SessionName
_sd_isOneShot :: SessionDescriptor -> Bool
_sd_name :: SessionDescriptor -> SessionName
..} =
PasswordStore -> Password -> m (Maybe PasswordStore)
forall (m :: * -> *).
Monad m =>
PasswordStore -> Password -> m (Maybe PasswordStore)
load_pwd PasswordStore
ps (Password -> m (Maybe PasswordStore))
-> Password -> m (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$
ASetter Password Password PasswordText PasswordText
-> PasswordText -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password PasswordText PasswordText
Lens' Password PasswordText
pw_text PasswordText
pwt (Password -> Password) -> Password -> Password
forall a b. (a -> b) -> a -> b
$
ASetter Password Password SessionMap SessionMap
-> (SessionMap -> SessionMap) -> Password -> Password
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter Password Password SessionMap SessionMap
Lens' Password SessionMap
pw_sessions (SessionName -> Session -> SessionMap -> SessionMap
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert SessionName
_sd_name Session
ssn) (Password -> Password) -> Password -> Password
forall a b. (a -> b) -> a -> b
$
ASetter Password Password Bool Bool -> Bool -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password Bool Bool
Lens' Password Bool
pw_isOneShot Bool
ios (Password -> Password) -> Password -> Password
forall a b. (a -> b) -> a -> b
$
Password
pw
where
pw :: Password
pw = Password -> (Password -> Password) -> Maybe Password -> Password
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Password
pw0 Password -> Password
forall a. a -> a
id (Maybe Password -> Password) -> Maybe Password -> Password
forall a b. (a -> b) -> a -> b
$ PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup PasswordName
pnm (PasswordMap -> Maybe Password) -> PasswordMap -> Maybe Password
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
pw0 :: Password
pw0 =
Password :: PasswordName
-> PasswordText
-> SessionMap
-> Bool
-> Bool
-> UTCTime
-> Password
Password
{ _pw_name :: PasswordName
_pw_name = PasswordName
pnm
, _pw_text :: PasswordText
_pw_text = PasswordText
pwt
, _pw_sessions :: SessionMap
_pw_sessions = SessionMap
forall k a. Map k a
Map.empty
, _pw_isOneShot :: Bool
_pw_isOneShot = Bool
ios
, _pw_primed :: Bool
_pw_primed = Bool
False
, _pw_setup :: UTCTime
_pw_setup = UTCTime
now
}
ssn :: Session
ssn =
Session :: SessionName -> PasswordText -> Bool -> UTC -> Session
Session
{ _ssn_name :: SessionName
_ssn_name = SessionName
_sd_name
, _ssn_password :: PasswordText
_ssn_password = PasswordText
pwt
, _ssn_isOneShot :: Bool
_ssn_isOneShot = Bool
ios
, _ssn_setup :: UTC
_ssn_setup = UTCTime -> UTC
UTC UTCTime
now
}
ios :: Bool
ios = Bool
_sd_isOneShot
load_pwd :: PasswordStore -> Password -> m (Maybe PasswordStore)
load_pwd PasswordStore
ps Password
pw = Maybe PasswordStore -> m (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> m (Maybe PasswordStore))
-> Maybe PasswordStore -> m (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map (PasswordName -> Password -> PasswordMap -> PasswordMap
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert PasswordName
pnm Password
pw) PasswordStore
ps
pnm :: PasswordName
pnm = p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p
loadPlus :: PW p => PMConfig p -> PasswordName -> Maybe PasswordText -> IO ()
loadPlus :: PMConfig p -> PasswordName -> Maybe PasswordText -> IO ()
loadPlus PMConfig p
pmc PasswordName
pnm_ Maybe PasswordText
mb = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> do
PasswordText
pwt <- IO PasswordText
-> (PasswordText -> IO PasswordText)
-> Maybe PasswordText
-> IO PasswordText
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Bool -> PMConfig p -> IO PasswordText
forall p. PW p => Bool -> PMConfig p -> IO PasswordText
get_pw Bool
False PMConfig p
pmc) PasswordText -> IO PasswordText
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe PasswordText
mb
UTCTime
now <- IO UTCTime
getCurrentTime
PasswordStore -> Password -> IO (Maybe PasswordStore)
forall (m :: * -> *).
Monad m =>
PasswordStore -> Password -> m (Maybe PasswordStore)
load_pwd PasswordStore
ps
Password :: PasswordName
-> PasswordText
-> SessionMap
-> Bool
-> Bool
-> UTCTime
-> Password
Password
{ _pw_name :: PasswordName
_pw_name = PasswordName
pnm
, _pw_text :: PasswordText
_pw_text = PasswordText
pwt
, _pw_sessions :: SessionMap
_pw_sessions = SessionMap
forall k a. Map k a
Map.empty
, _pw_isOneShot :: Bool
_pw_isOneShot = Bool
False
, _pw_primed :: Bool
_pw_primed = Bool
False
, _pw_setup :: UTCTime
_pw_setup = UTCTime
now
}
where
pnm :: PasswordName
pnm = Text -> PasswordName
PasswordName (Text -> PasswordName) -> Text -> PasswordName
forall a b. (a -> b) -> a -> b
$ (Char -> Text -> Text
T.cons Char
'+') (Text -> Text) -> Text -> Text
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName PasswordName
pnm_
load_pwd :: PasswordStore -> Password -> m (Maybe PasswordStore)
load_pwd PasswordStore
ps Password
pw = Maybe PasswordStore -> m (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> m (Maybe PasswordStore))
-> Maybe PasswordStore -> m (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map (PasswordName -> Password -> PasswordMap -> PasswordMap
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert PasswordName
pnm Password
pw) PasswordStore
ps
psComment :: PW p => PMConfig p -> PasswordStoreComment -> IO ()
PMConfig p
pmc PasswordStoreComment
cmt = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter
PasswordStore
PasswordStore
PasswordStoreComment
PasswordStoreComment
-> PasswordStoreComment -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter
PasswordStore
PasswordStore
PasswordStoreComment
PasswordStoreComment
Lens' PasswordStore PasswordStoreComment
ps_comment PasswordStoreComment
cmt PasswordStore
ps
collect :: PW p => PMConfig p -> CollectConfig p -> IO ()
collect :: PMConfig p -> CollectConfig p -> IO ()
collect PMConfig p
pmc CollectConfig{Bool
[p]
_cc_active :: [p]
_cc_optional :: Bool
_cc_active :: forall p. CollectConfig p -> [p]
_cc_optional :: forall p. CollectConfig p -> Bool
..} = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap_ PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> do
(p -> IO ()) -> [p] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (PMConfig p -> PasswordStore -> p -> IO ()
forall p. PW p => PMConfig p -> PasswordStore -> p -> IO ()
clct PMConfig p
pmc PasswordStore
ps) [p]
_cc_active
[IO ()] -> IO ()
forall (t :: * -> *) (m :: * -> *) a.
(Foldable t, Monad m) =>
t (m a) -> m ()
sequence_
[ EnvVar -> PasswordText -> IO ()
set_env EnvVar
ev (PasswordText -> IO ()) -> PasswordText -> IO ()
forall a b. (a -> b) -> a -> b
$ Password -> PasswordText
_pw_text Password
pw
| (PasswordName
pnm_,Password
pw) <- PasswordMap -> [(PasswordName, Password)]
forall k a. Map k a -> [(k, a)]
Map.toList (PasswordMap -> [(PasswordName, Password)])
-> PasswordMap -> [(PasswordName, Password)]
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
, Just PasswordName
pnm <- [PasswordName -> Maybe PasswordName
is_plus PasswordName
pnm_]
, Just EnvVar
ev <- [PMConfig p -> PasswordName -> Maybe EnvVar
forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_plus_env_var PMConfig p
pmc PasswordName
pnm]
]
Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map ((Password -> Password) -> PasswordMap -> PasswordMap
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (ASetter Password Password Bool Bool -> Bool -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password Bool Bool
Lens' Password Bool
pw_primed Bool
False)) PasswordStore
ps
where
clct :: PW p => PMConfig p -> PasswordStore -> p -> IO ()
clct :: PMConfig p -> PasswordStore -> p -> IO ()
clct PMConfig p
_ PasswordStore
ps p
p = case PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p) (PasswordMap -> Maybe Password) -> PasswordMap -> Maybe Password
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps of
Just Password
pw | Password -> Bool
is_primed Password
pw -> EnvVar -> PasswordText -> IO ()
set_env (p -> EnvVar
forall p. PW p => p -> EnvVar
enVar p
p) (Password -> PasswordText
_pw_text Password
pw)
Maybe Password
_ -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
wrap_ :: PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap_ = if Bool
_cc_optional then PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap_def else PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap
prime :: PW p => PMConfig p -> Bool -> Maybe p -> IO ()
prime :: PMConfig p -> Bool -> Maybe p -> IO ()
prime PMConfig p
pmc Bool
u Maybe p
Nothing = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map ((Password -> Password) -> PasswordMap -> PasswordMap
forall a b k. (a -> b) -> Map k a -> Map k b
Map.map (ASetter Password Password Bool Bool -> Bool -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password Bool Bool
Lens' Password Bool
pw_primed (Bool -> Password -> Password) -> Bool -> Password -> Password
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
u) ) PasswordStore
ps
prime PMConfig p
pmc Bool
u (Just p
p) = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map ((Password -> Password)
-> PasswordName -> PasswordMap -> PasswordMap
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
Map.adjust (ASetter Password Password Bool Bool -> Bool -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password Bool Bool
Lens' Password Bool
pw_primed (Bool -> Password -> Password) -> Bool -> Password -> Password
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
u) (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p)) PasswordStore
ps
select :: PW p => PMConfig p -> Maybe p -> SessionName -> IO ()
select :: PMConfig p -> Maybe p -> SessionName -> IO ()
select PMConfig p
pmc Maybe p
mb SessionName
snm = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> PasswordStore -> (p, Password, Session) -> Maybe PasswordStore
forall p.
PW p =>
PasswordStore -> (p, Password, Session) -> Maybe PasswordStore
f PasswordStore
ps ((p, Password, Session) -> Maybe PasswordStore)
-> IO (p, Password, Session) -> IO (Maybe PasswordStore)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe p
-> SessionName -> PasswordStore -> IO (p, Password, Session)
forall p.
PW p =>
Maybe p
-> SessionName -> PasswordStore -> IO (p, Password, Session)
lookup_session Maybe p
mb SessionName
snm PasswordStore
ps
where
f :: PasswordStore -> (p, Password, Session) -> Maybe PasswordStore
f PasswordStore
ps (p
p,Password
pw,Session
ssn) = PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map (PasswordName -> Password -> PasswordMap -> PasswordMap
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p) (Password -> Session -> Password
upd Password
pw Session
ssn)) PasswordStore
ps
upd :: Password -> Session -> Password
upd Password
pw Session{Bool
UTC
SessionName
PasswordText
_ssn_setup :: UTC
_ssn_isOneShot :: Bool
_ssn_password :: PasswordText
_ssn_name :: SessionName
_ssn_setup :: Session -> UTC
_ssn_isOneShot :: Session -> Bool
_ssn_password :: Session -> PasswordText
_ssn_name :: Session -> SessionName
..} =
ASetter Password Password PasswordText PasswordText
-> PasswordText -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password PasswordText PasswordText
Lens' Password PasswordText
pw_text PasswordText
_ssn_password (Password -> Password) -> Password -> Password
forall a b. (a -> b) -> a -> b
$
ASetter Password Password Bool Bool -> Bool -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password Bool Bool
Lens' Password Bool
pw_isOneShot Bool
_ssn_isOneShot (Password -> Password) -> Password -> Password
forall a b. (a -> b) -> a -> b
$
ASetter Password Password Bool Bool -> Bool -> Password -> Password
forall s t a b. ASetter s t a b -> b -> s -> t
L.set ASetter Password Password Bool Bool
Lens' Password Bool
pw_primed Bool
False (Password -> Password) -> Password -> Password
forall a b. (a -> b) -> a -> b
$
Password
pw
deletePassword :: PW p => PMConfig p -> p -> IO ()
deletePassword :: PMConfig p -> p -> IO ()
deletePassword PMConfig p
pmc p
p = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map (PasswordName -> PasswordMap -> PasswordMap
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p)) PasswordStore
ps
deletePasswordPlus :: PW p => PMConfig p -> Maybe PasswordName -> IO ()
deletePasswordPlus :: PMConfig p -> Maybe PasswordName -> IO ()
deletePasswordPlus PMConfig p
pmc Maybe PasswordName
Nothing = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map ((Password -> Bool) -> PasswordMap -> PasswordMap
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter Password -> Bool
is_static_pw) PasswordStore
ps
deletePasswordPlus PMConfig p
pmc (Just PasswordName
pnm) = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map (PasswordName -> PasswordMap -> PasswordMap
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete (PasswordName -> PasswordName
plussify PasswordName
pnm)) PasswordStore
ps
deleteSession :: PW p => PMConfig p -> Maybe p -> SessionName -> IO ()
deleteSession :: PMConfig p -> Maybe p -> SessionName -> IO ()
deleteSession PMConfig p
pmc Maybe p
mb SessionName
snm = PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall p.
PW p =>
PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc ((PasswordStore -> IO (Maybe PasswordStore)) -> IO ())
-> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps -> do
(p, Password, Session)
trp <- Maybe p
-> SessionName -> PasswordStore -> IO (p, Password, Session)
forall p.
PW p =>
Maybe p
-> SessionName -> PasswordStore -> IO (p, Password, Session)
lookup_session Maybe p
mb SessionName
snm PasswordStore
ps
(p, Password, Session) -> IO ()
forall p (m :: * -> *).
(PW p, Monad m) =>
(p, Password, Session) -> m ()
chk (p, Password, Session)
trp
Maybe PasswordStore -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe PasswordStore -> IO (Maybe PasswordStore))
-> Maybe PasswordStore -> IO (Maybe PasswordStore)
forall a b. (a -> b) -> a -> b
$ PasswordStore -> (p, Password, Session) -> Maybe PasswordStore
forall p c.
PW p =>
PasswordStore -> (p, Password, c) -> Maybe PasswordStore
f PasswordStore
ps (p, Password, Session)
trp
where
chk :: (p, Password, Session) -> m ()
chk (p
p,Password
pw,Session
ssn)
| Just PasswordText -> Either FilePath SessionDescriptor
ext <- p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession p
p
, Right SessionDescriptor
sd <- PasswordText -> Either FilePath SessionDescriptor
ext (PasswordText -> Either FilePath SessionDescriptor)
-> PasswordText -> Either FilePath SessionDescriptor
forall a b. (a -> b) -> a -> b
$ Password -> PasswordText
_pw_text Password
pw
, SessionDescriptor -> SessionName
_sd_name SessionDescriptor
sd SessionName -> SessionName -> Bool
forall a. Eq a => a -> a -> Bool
/= Session -> SessionName
_ssn_name Session
ssn
= () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
| Bool
otherwise = FilePath -> m ()
forall a. HasCallStack => FilePath -> a
error FilePath
"cannot delete this session (is it selected?)"
f :: PasswordStore -> (p, Password, c) -> Maybe PasswordStore
f PasswordStore
ps (p
p,Password
pw,c
_) = PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> PasswordStore -> Maybe PasswordStore
forall a b. (a -> b) -> a -> b
$ ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map (PasswordName -> Password -> PasswordMap -> PasswordMap
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p) (ASetter Password Password SessionMap SessionMap
-> (SessionMap -> SessionMap) -> Password -> Password
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter Password Password SessionMap SessionMap
Lens' Password SessionMap
pw_sessions (SessionName -> SessionMap -> SessionMap
forall k a. Ord k => k -> Map k a -> Map k a
Map.delete SessionName
snm) Password
pw)) PasswordStore
ps
status :: PW p => PMConfig p -> Bool -> IO ()
status :: PMConfig p -> Bool -> IO ()
status PMConfig p
pmc Bool
q = (if Bool
q then (IO () -> (SomeException -> IO ()) -> IO ())
-> (SomeException -> IO ()) -> IO () -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO () -> (SomeException -> IO ()) -> IO ()
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch SomeException -> IO ()
forall a. SomeException -> IO a
hdl else IO () -> IO ()
forall a. a -> a
id) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ PMConfig p -> (PasswordStore -> IO ()) -> IO ()
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc PasswordStore -> IO ()
line
where
line :: PasswordStore -> IO ()
line PasswordStore
ps = FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$
FilePath
"Logged in [" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
[FilePath] -> FilePath
unwords [FilePath]
sns' FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"/" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ [FilePath] -> FilePath
unwords [FilePath]
pps' FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"] (" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
(Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordStoreComment -> Text
_PasswordStoreComment (PasswordStoreComment -> Text) -> PasswordStoreComment -> Text
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordStoreComment
_ps_comment PasswordStore
ps) FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
")"
where
sns' :: [FilePath]
sns' = [FilePath]
sns [FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ [FilePath
"+" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show (PMConfig p -> [(p, Password, Session)] -> Int
forall p. PMConfig p -> [(p, Password, Session)] -> Int
len PMConfig p
pmc (Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
forall p.
PW p =>
Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
lookup_sessions Maybe p
forall a. Maybe a
Nothing (Bool -> SessionName -> Bool
forall a b. a -> b -> a
const Bool
True) PasswordStore
ps) Int -> Int -> Int
forall a. Num a => a -> a -> a
- [FilePath] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [FilePath]
sns)]
pps' :: [FilePath]
pps' = [FilePath]
pps [FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++ [FilePath
"+" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> FilePath
forall a. Show a => a -> FilePath
show (PasswordMap -> Int
forall k a. Map k a -> Int
Map.size (PasswordStore -> PasswordMap
_ps_map PasswordStore
ps) Int -> Int -> Int
forall a. Num a => a -> a -> a
- [FilePath] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [FilePath]
pps)]
sns :: [FilePath]
sns =
[ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ SessionName -> Text
_SessionName (SessionName -> Text) -> SessionName -> Text
forall a b. (a -> b) -> a -> b
$ SessionDescriptor -> SessionName
_sd_name SessionDescriptor
sd
| Password
pw <- PasswordMap -> [Password]
forall k a. Map k a -> [a]
Map.elems (PasswordMap -> [Password]) -> PasswordMap -> [Password]
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
, let Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..} = Password
pw
, Just p
p <- [PasswordName -> Maybe p
forall p. PW p => PasswordName -> Maybe p
parsePwName PasswordName
_pw_name]
, Just PasswordText -> Either FilePath SessionDescriptor
prs <- [p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession (p -> Maybe (PasswordText -> Either FilePath SessionDescriptor))
-> p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall a b. (a -> b) -> a -> b
$ PMConfig p -> p -> p
forall p. PMConfig p -> p -> p
cast_pmc PMConfig p
pmc p
p]
, Right SessionDescriptor
sd <- [PasswordText -> Either FilePath SessionDescriptor
prs PasswordText
_pw_text]
, Password -> Bool
is_primed Password
pw
]
pps :: [FilePath]
pps =
[ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName (PasswordName -> Text) -> PasswordName -> Text
forall a b. (a -> b) -> a -> b
$ Password -> PasswordName
_pw_name Password
pw
| Password
pw <- PasswordMap -> [Password]
forall k a. Map k a -> [a]
Map.elems (PasswordMap -> [Password]) -> PasswordMap -> [Password]
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
, Password -> Bool
_pw_isOneShot Password
pw Bool -> Bool -> Bool
&& Password -> Bool
is_primed Password
pw
]
len :: PMConfig p -> [(p,Password,Session)] -> Int
len :: PMConfig p -> [(p, Password, Session)] -> Int
len PMConfig p
_ = [(p, Password, Session)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length
hdl :: SomeException -> IO a
hdl (SomeException
_::SomeException) = ExitCode -> IO a
forall a. ExitCode -> IO a
exitWith (ExitCode -> IO a) -> ExitCode -> IO a
forall a b. (a -> b) -> a -> b
$ Int -> ExitCode
ExitFailure Int
1
prompt :: PW p => PMConfig p -> IO ()
prompt :: PMConfig p -> IO ()
prompt PMConfig p
pmc = (IO () -> (SomeException -> IO ()) -> IO ())
-> (SomeException -> IO ()) -> IO () -> IO ()
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO () -> (SomeException -> IO ()) -> IO ()
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch SomeException -> IO ()
hdl (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
Bool
li <- PMConfig p -> IO Bool
forall p. PW p => PMConfig p -> IO Bool
amLoggedIn PMConfig p
pmc
case Bool
li of
Bool
True -> PMConfig p -> (PasswordStore -> IO ()) -> IO ()
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc PasswordStore -> IO ()
line
Bool
False -> FilePath -> IO ()
putStrLn FilePath
"*"
where
line :: PasswordStore -> IO ()
line PasswordStore
ps = FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath
"[" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ [FilePath] -> FilePath
unwords [FilePath]
sns FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"]"
where
sns :: [FilePath]
sns =
[ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ SessionName -> Text
_SessionName (SessionName -> Text) -> SessionName -> Text
forall a b. (a -> b) -> a -> b
$ SessionDescriptor -> SessionName
_sd_name SessionDescriptor
sd
| Password
pw <- PasswordMap -> [Password]
forall k a. Map k a -> [a]
Map.elems (PasswordMap -> [Password]) -> PasswordMap -> [Password]
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
, let Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..} = Password
pw
, Just p
p <- [PasswordName -> Maybe p
forall p. PW p => PasswordName -> Maybe p
parsePwName PasswordName
_pw_name]
, Just PasswordText -> Either FilePath SessionDescriptor
prs <- [p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession (p -> Maybe (PasswordText -> Either FilePath SessionDescriptor))
-> p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall a b. (a -> b) -> a -> b
$ PMConfig p -> p -> p
forall p. PMConfig p -> p -> p
cast_pmc PMConfig p
pmc p
p]
, Right SessionDescriptor
sd <- [PasswordText -> Either FilePath SessionDescriptor
prs PasswordText
_pw_text]
, Password -> Bool
is_primed Password
pw
]
hdl :: SomeException -> IO ()
hdl (SomeException
_::SomeException) = FilePath -> IO ()
putStrLn FilePath
"???"
passwords :: PW p => PMConfig p -> Bool -> IO ()
passwords :: PMConfig p -> Bool -> IO ()
passwords PMConfig p
pmc Bool
br = do
TimeZone
tz <- IO TimeZone
getCurrentTimeZone
PMConfig p -> (PasswordStore -> IO ()) -> IO ()
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc ((PasswordStore -> IO ()) -> IO ())
-> (PasswordStore -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps ->
FilePath -> IO ()
putStr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
unlines ([FilePath] -> FilePath) -> [FilePath] -> FilePath
forall a b. (a -> b) -> a -> b
$ ((p, Password) -> FilePath) -> [(p, Password)] -> [FilePath]
forall a b. (a -> b) -> [a] -> [b]
map (TimeZone -> (p, Password) -> FilePath
forall p. PW p => TimeZone -> (p, Password) -> FilePath
fmt TimeZone
tz) ([(p, Password)] -> [FilePath]) -> [(p, Password)] -> [FilePath]
forall a b. (a -> b) -> a -> b
$ PasswordStore -> [(p, Password)]
pws PasswordStore
ps
where
fmt :: PW p => TimeZone -> (p,Password) -> String
fmt :: TimeZone -> (p, Password) -> FilePath
fmt TimeZone
tz (p
p,Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..})
| Bool
br = FilePath
nm_s
| Bool
otherwise = FilePath
-> FilePath
-> Char
-> FilePath
-> FilePath
-> FilePath
-> FilePath
-> FilePath
forall r. PrintfType r => FilePath -> r
printf FilePath
"%-12s %c %2s $%-18s %s %s" FilePath
nm_s Char
p_c FilePath
sn_s FilePath
ev_s FilePath
su_s FilePath
cmt
where
nm_s :: FilePath
nm_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName PasswordName
_pw_name
p_c :: Char
p_c = if Bool
_pw_isOneShot then Bool -> Char
prime_char Bool
_pw_primed else Char
' '
sn_s :: FilePath
sn_s = case SessionMap -> Int
forall k a. Map k a -> Int
Map.size SessionMap
_pw_sessions of
Int
0 -> FilePath
""
Int
n -> Int -> FilePath
forall a. Show a => a -> FilePath
show Int
n
ev_s :: FilePath
ev_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ EnvVar -> Text
_EnvVar (EnvVar -> Text) -> EnvVar -> Text
forall a b. (a -> b) -> a -> b
$ p -> EnvVar
forall p. PW p => p -> EnvVar
enVar p
p
su_s :: FilePath
su_s = TimeZone -> UTCTime -> FilePath
pretty_setup TimeZone
tz UTCTime
_pw_setup
cmt :: FilePath
cmt = case p -> FilePath
forall p. PW p => p -> FilePath
summarize p
p of
FilePath
"" -> FilePath
""
FilePath
cs -> FilePath
"# " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
cs
pws :: PasswordStore -> [(p, Password)]
pws PasswordStore
ps =
[ (PMConfig p -> p -> p
forall p. PMConfig p -> p -> p
cast_pmc PMConfig p
pmc p
p,Password
pwd)
| p
p <- [p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound]
, Just Password
pwd <- [PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p) (PasswordMap -> Maybe Password) -> PasswordMap -> Maybe Password
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps]
]
passwordsPlus :: PW p => PMConfig p -> Bool -> IO ()
passwordsPlus :: PMConfig p -> Bool -> IO ()
passwordsPlus PMConfig p
pmc Bool
br = do
TimeZone
tz <- IO TimeZone
getCurrentTimeZone
PMConfig p -> (PasswordStore -> IO ()) -> IO ()
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc ((PasswordStore -> IO ()) -> IO ())
-> (PasswordStore -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps ->
FilePath -> IO ()
putStr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
unlines ([FilePath] -> FilePath) -> [FilePath] -> FilePath
forall a b. (a -> b) -> a -> b
$ ((PasswordName, Password) -> FilePath)
-> [(PasswordName, Password)] -> [FilePath]
forall a b. (a -> b) -> [a] -> [b]
map (TimeZone -> (PasswordName, Password) -> FilePath
fmt TimeZone
tz) ([(PasswordName, Password)] -> [FilePath])
-> [(PasswordName, Password)] -> [FilePath]
forall a b. (a -> b) -> a -> b
$ PasswordStore -> [(PasswordName, Password)]
pws PasswordStore
ps
where
fmt :: TimeZone -> (PasswordName, Password) -> FilePath
fmt TimeZone
tz (PasswordName
pnm,Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..})
| Bool
br = FilePath
nm_s
| Bool
otherwise = FilePath -> FilePath -> FilePath -> FilePath -> FilePath
forall r. PrintfType r => FilePath -> r
printf FilePath
"+%-12s $%-18s %s" FilePath
nm_s FilePath
ev_s FilePath
su_s
where
nm_s :: FilePath
nm_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName PasswordName
pnm
ev_s :: FilePath
ev_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ EnvVar -> Text
_EnvVar (EnvVar -> Text) -> EnvVar -> Text
forall a b. (a -> b) -> a -> b
$ EnvVar -> Maybe EnvVar -> EnvVar
forall a. a -> Maybe a -> a
fromMaybe EnvVar
"?" (Maybe EnvVar -> EnvVar) -> Maybe EnvVar -> EnvVar
forall a b. (a -> b) -> a -> b
$ PMConfig p -> PasswordName -> Maybe EnvVar
forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_plus_env_var PMConfig p
pmc PasswordName
pnm
su_s :: FilePath
su_s = TimeZone -> UTCTime -> FilePath
pretty_setup TimeZone
tz UTCTime
_pw_setup
pws :: PasswordStore -> [(PasswordName, Password)]
pws PasswordStore
ps =
[ (PasswordName
pnm,Password
pw)
| (PasswordName
pnm_,Password
pw) <- PasswordMap -> [(PasswordName, Password)]
forall k a. Map k a -> [(k, a)]
Map.toList (PasswordMap -> [(PasswordName, Password)])
-> PasswordMap -> [(PasswordName, Password)]
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
, Just PasswordName
pnm <- [PasswordName -> Maybe PasswordName
is_plus PasswordName
pnm_]
]
sessions :: PW p
=> PMConfig p
-> Bool
-> Bool
-> Maybe p
-> IO ()
sessions :: PMConfig p -> Bool -> Bool -> Maybe p -> IO ()
sessions PMConfig p
pmc Bool
a Bool
b Maybe p
mb = do
TimeZone
tz <- IO TimeZone
getCurrentTimeZone
PMConfig p -> (PasswordStore -> IO ()) -> IO ()
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc ((PasswordStore -> IO ()) -> IO ())
-> (PasswordStore -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps ->
let trps :: [(p, Password, Session)]
trps = case Bool
a of
Bool
True -> [ (p, Password, Session)
trp | trp :: (p, Password, Session)
trp@(p
_,Password
pw,Session
_)<-[(p, Password, Session)]
trps_, (p, Password, Session) -> Bool
forall p. PW p => (p, Password, Session) -> Bool
active_session (p, Password, Session)
trp Bool -> Bool -> Bool
&& Password -> Bool
is_primed Password
pw]
Bool
False -> [(p, Password, Session)]
trps_
trps_ :: [(p, Password, Session)]
trps_ = Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
forall p.
PW p =>
Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
lookup_sessions Maybe p
mb (Bool -> SessionName -> Bool
forall a b. a -> b -> a
const Bool
True) PasswordStore
ps
in
FilePath -> IO ()
putStr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ [FilePath] -> FilePath
unlines ([FilePath] -> FilePath) -> [FilePath] -> FilePath
forall a b. (a -> b) -> a -> b
$ ((p, Password, Session) -> FilePath)
-> [(p, Password, Session)] -> [FilePath]
forall a b. (a -> b) -> [a] -> [b]
map (TimeZone -> (p, Password, Session) -> FilePath
forall p a.
(PrintfType p, PW a) =>
TimeZone -> (a, Password, Session) -> p
fmt TimeZone
tz) [(p, Password, Session)]
trps
where
fmt :: TimeZone -> (a, Password, Session) -> p
fmt TimeZone
tz trp :: (a, Password, Session)
trp@(a
_,Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..},Session{Bool
UTC
SessionName
PasswordText
_ssn_setup :: UTC
_ssn_isOneShot :: Bool
_ssn_password :: PasswordText
_ssn_name :: SessionName
_ssn_setup :: Session -> UTC
_ssn_isOneShot :: Session -> Bool
_ssn_password :: Session -> PasswordText
_ssn_name :: Session -> SessionName
..}) =
case Bool
b of
Bool
True -> FilePath -> FilePath -> p
forall r. PrintfType r => FilePath -> r
printf FilePath
"%s" FilePath
sn_s
Bool
False ->
case Bool
sgl of
Bool
True -> FilePath -> FilePath -> Char -> FilePath -> FilePath -> p
forall r. PrintfType r => FilePath -> r
printf FilePath
"%-16s %c %s %s" FilePath
sn_s Char
p_c FilePath
su_s FilePath
a_s
Bool
False -> FilePath
-> FilePath -> FilePath -> Char -> FilePath -> FilePath -> p
forall r. PrintfType r => FilePath -> r
printf FilePath
"%-12s %-16s %c %s %s" FilePath
pn_s FilePath
sn_s Char
p_c FilePath
su_s FilePath
a_s
where
pn_s :: FilePath
pn_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName PasswordName
_pw_name
sn_s :: FilePath
sn_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ SessionName -> Text
_SessionName SessionName
_ssn_name
p_c :: Char
p_c = if Bool
_ssn_isOneShot then Bool -> Char
prime_char Bool
False else Char
' '
su_s :: FilePath
su_s = TimeZone -> UTCTime -> FilePath
pretty_setup TimeZone
tz (UTCTime -> FilePath) -> UTCTime -> FilePath
forall a b. (a -> b) -> a -> b
$ UTC -> UTCTime
_UTC UTC
_ssn_setup
a_s :: FilePath
a_s = if (a, Password, Session) -> Bool
forall p. PW p => (p, Password, Session) -> Bool
active_session (a, Password, Session)
trp then FilePath
"[ACTIVE]" else FilePath
"" :: String
sgl :: Bool
sgl = [()] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ () | p
p<-[p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound], Maybe (PasswordText -> Either FilePath SessionDescriptor) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (PasswordText -> Either FilePath SessionDescriptor) -> Bool)
-> Maybe (PasswordText -> Either FilePath SessionDescriptor)
-> Bool
forall a b. (a -> b) -> a -> b
$ p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession (p -> Maybe (PasswordText -> Either FilePath SessionDescriptor))
-> p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall a b. (a -> b) -> a -> b
$ PMConfig p -> p -> p
forall p. PMConfig p -> p -> p
cast_pmc PMConfig p
pmc p
p ] Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
infoPassword :: PW p
=> PMConfig p
-> Bool
-> p
-> IO ()
infoPassword :: PMConfig p -> Bool -> p -> IO ()
infoPassword PMConfig p
pmc Bool
sh_s p
p = do
Doc
doc <- PMConfig p -> Bool -> p -> IO Doc
forall p. PW p => PMConfig p -> Bool -> p -> IO Doc
infoPassword_ PMConfig p
pmc Bool
sh_s p
p
FilePath -> IO ()
putStr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ SimpleDoc -> FilePath -> FilePath
P.displayS (Float -> Int -> Doc -> SimpleDoc
P.renderPretty Float
0.75 Int
120 Doc
doc) FilePath
""
infoPassword_ :: PW p => PMConfig p -> Bool -> p -> IO P.Doc
infoPassword_ :: PMConfig p -> Bool -> p -> IO Doc
infoPassword_ PMConfig p
pmc Bool
sh_s p
p = do
TimeZone
tz <- IO TimeZone
getCurrentTimeZone
PMConfig p -> (PasswordStore -> IO Doc) -> IO Doc
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc ((PasswordStore -> IO Doc) -> IO Doc)
-> (PasswordStore -> IO Doc) -> IO Doc
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps ->
Doc -> IO Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> IO Doc) -> Doc -> IO Doc
forall a b. (a -> b) -> a -> b
$ Doc -> (Password -> Doc) -> Maybe Password -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
P.empty (TimeZone -> Password -> Doc
mk TimeZone
tz) (Maybe Password -> Doc) -> Maybe Password -> Doc
forall a b. (a -> b) -> a -> b
$ PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup PasswordName
pnm (PasswordMap -> Maybe Password) -> PasswordMap -> Maybe Password
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
where
mk :: TimeZone -> Password -> Doc
mk TimeZone
tz pw :: Password
pw@Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..} =
Doc
heading Doc -> Doc -> Doc
P.<$$> Int -> Doc -> Doc
P.indent Int
4 (
Doc
sssions Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<>
Doc
primed Doc -> Doc -> Doc
P.<$$>
Doc
evar Doc -> Doc -> Doc
P.<$$>
Doc
secret Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<>
Doc
loaded Doc -> Doc -> Doc
P.<$$>
Doc
P.empty Doc -> Doc -> Doc
P.<$$>
Doc
descr
) Doc -> Doc -> Doc
P.<$$>
Doc
P.empty
where
heading :: Doc
heading = Doc -> Doc
P.bold (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ FilePath -> Doc
P.string (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName PasswordName
pnm
sssions :: Doc
sssions = case p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession p
p of
Maybe (PasswordText -> Either FilePath SessionDescriptor)
Nothing -> Doc
P.empty
Just PasswordText -> Either FilePath SessionDescriptor
xt -> (FilePath -> FilePath -> Doc
line FilePath
"sessions" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ (PasswordText -> Either FilePath SessionDescriptor) -> FilePath
fmt_sns PasswordText -> Either FilePath SessionDescriptor
xt) Doc -> Doc -> Doc
P.<$$> Doc
P.empty
primed :: Doc
primed = FilePath -> FilePath -> Doc
line FilePath
"primed" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ if Password -> Bool
is_primed Password
pw then FilePath
"yes" else FilePath
"no"
evar :: Doc
evar = FilePath -> FilePath -> Doc
line FilePath
"env var" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ EnvVar -> Text
_EnvVar (EnvVar -> Text) -> EnvVar -> Text
forall a b. (a -> b) -> a -> b
$ p -> EnvVar
forall p. PW p => p -> EnvVar
enVar p
p
loaded :: Doc
loaded = FilePath -> FilePath -> Doc
line FilePath
"loaded" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ TimeZone -> UTCTime -> FilePath
pretty_setup TimeZone
tz (UTCTime -> FilePath) -> UTCTime -> FilePath
forall a b. (a -> b) -> a -> b
$ UTCTime
_pw_setup
descr :: Doc
descr = FilePath -> Doc
P.string (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ p -> FilePath
forall p. PW p => p -> FilePath
describe p
p
secret :: Doc
secret = case Bool
sh_s of
Bool
True -> (FilePath -> FilePath -> Doc
line FilePath
"secret" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordText -> Text
_PasswordText PasswordText
_pw_text) Doc -> Doc -> Doc
P.<$$> Doc
P.empty
Bool
False -> Doc
P.empty
fmt_sns :: (PasswordText -> Either FilePath SessionDescriptor) -> FilePath
fmt_sns PasswordText -> Either FilePath SessionDescriptor
xt = FilePath
sn FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
" / " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ [FilePath] -> FilePath
unwords ((SessionName -> FilePath) -> [SessionName] -> [FilePath]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> FilePath
T.unpack (Text -> FilePath)
-> (SessionName -> Text) -> SessionName -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SessionName -> Text
_SessionName) ([SessionName] -> [FilePath]) -> [SessionName] -> [FilePath]
forall a b. (a -> b) -> a -> b
$ (SessionName -> Bool) -> [SessionName] -> [SessionName]
forall a. (a -> Bool) -> [a] -> [a]
filter SessionName -> Bool
fl [SessionName]
sns)
where
sn :: FilePath
sn = (FilePath -> FilePath)
-> (SessionDescriptor -> FilePath)
-> Either FilePath SessionDescriptor
-> FilePath
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\FilePath
s->FilePath
"<<"FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++FilePath
sFilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++FilePath
">>") (Text -> FilePath
T.unpack (Text -> FilePath)
-> (SessionDescriptor -> Text) -> SessionDescriptor -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SessionName -> Text
_SessionName (SessionName -> Text)
-> (SessionDescriptor -> SessionName) -> SessionDescriptor -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SessionDescriptor -> SessionName
_sd_name ) Either FilePath SessionDescriptor
ei
fl :: SessionName -> Bool
fl = (FilePath -> SessionName -> Bool)
-> (SessionDescriptor -> SessionName -> Bool)
-> Either FilePath SessionDescriptor
-> SessionName
-> Bool
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\FilePath
_ SessionName
_->Bool
False) (\SessionDescriptor
sd SessionName
sn'->SessionDescriptor -> SessionName
_sd_name SessionDescriptor
sdSessionName -> SessionName -> Bool
forall a. Eq a => a -> a -> Bool
/=SessionName
sn') Either FilePath SessionDescriptor
ei
ei :: Either FilePath SessionDescriptor
ei = PasswordText -> Either FilePath SessionDescriptor
xt PasswordText
_pw_text
sns :: [SessionName]
sns = SessionMap -> [SessionName]
forall k a. Map k a -> [k]
Map.keys SessionMap
_pw_sessions
line :: String -> String -> P.Doc
line :: FilePath -> FilePath -> Doc
line FilePath
nm FilePath
vl = Doc -> Doc
P.bold(FilePath -> Doc
P.string (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ Int -> FilePath -> FilePath
ljust Int
8 FilePath
nm) Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<> FilePath -> Doc
P.string FilePath
" : " Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<>
Int -> Doc -> Doc
P.hang Int
8 (FilePath -> Doc
P.string FilePath
vl)
pnm :: PasswordName
pnm = p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p
ljust :: Int -> FilePath -> FilePath
ljust Int
n FilePath
s = FilePath
s FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> Char -> FilePath
forall a. Int -> a -> [a]
replicate (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-FilePath -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
s)) Char
' '
infoPasswordPlus :: PW p => PMConfig p -> Bool -> PasswordName -> IO ()
infoPasswordPlus :: PMConfig p -> Bool -> PasswordName -> IO ()
infoPasswordPlus PMConfig p
pmc Bool
sh_s PasswordName
pnm = do
Doc
doc <- PMConfig p -> Bool -> PasswordName -> IO Doc
forall p. PW p => PMConfig p -> Bool -> PasswordName -> IO Doc
infoPasswordPlus_ PMConfig p
pmc Bool
sh_s PasswordName
pnm
FilePath -> IO ()
putStr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ SimpleDoc -> FilePath -> FilePath
P.displayS (Float -> Int -> Doc -> SimpleDoc
P.renderPretty Float
0.75 Int
120 Doc
doc) FilePath
""
infoPasswordPlus_ :: PW p => PMConfig p -> Bool -> PasswordName -> IO P.Doc
infoPasswordPlus_ :: PMConfig p -> Bool -> PasswordName -> IO Doc
infoPasswordPlus_ PMConfig p
pmc Bool
sh_s PasswordName
pnm = do
TimeZone
tz <- IO TimeZone
getCurrentTimeZone
PMConfig p -> (PasswordStore -> IO Doc) -> IO Doc
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc ((PasswordStore -> IO Doc) -> IO Doc)
-> (PasswordStore -> IO Doc) -> IO Doc
forall a b. (a -> b) -> a -> b
$ \PasswordStore
ps ->
Doc -> IO Doc
forall (m :: * -> *) a. Monad m => a -> m a
return (Doc -> IO Doc) -> Doc -> IO Doc
forall a b. (a -> b) -> a -> b
$ Doc -> (Password -> Doc) -> Maybe Password -> Doc
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
P.empty (TimeZone -> Password -> Doc
mk TimeZone
tz) (Maybe Password -> Doc) -> Maybe Password -> Doc
forall a b. (a -> b) -> a -> b
$ PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (PasswordName -> PasswordName
plussify PasswordName
pnm) (PasswordMap -> Maybe Password) -> PasswordMap -> Maybe Password
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps
where
mk :: TimeZone -> Password -> Doc
mk TimeZone
tz Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..} =
Doc
heading Doc -> Doc -> Doc
P.<$$> Int -> Doc -> Doc
P.indent Int
4 (
Doc
evar Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<>
Doc
secret Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<>
Doc
loaded
) Doc -> Doc -> Doc
P.<$$>
Doc
P.empty
where
heading :: Doc
heading = Doc -> Doc
P.bold (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ FilePath -> Doc
P.string (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ FilePath
"+" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
T.unpack (PasswordName -> Text
_PasswordName PasswordName
pnm)
evar :: Doc
evar = case PMConfig p -> PasswordName -> Maybe EnvVar
forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_plus_env_var PMConfig p
pmc PasswordName
pnm of
Maybe EnvVar
Nothing -> Doc
P.empty
Just EnvVar
ev -> (FilePath -> FilePath -> Doc
line FilePath
"env var" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ EnvVar -> Text
_EnvVar (EnvVar -> Text) -> EnvVar -> Text
forall a b. (a -> b) -> a -> b
$ EnvVar
ev ) Doc -> Doc -> Doc
P.<$$> Doc
P.empty
loaded :: Doc
loaded = FilePath -> FilePath -> Doc
line FilePath
"loaded" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ TimeZone -> UTCTime -> FilePath
pretty_setup TimeZone
tz (UTCTime -> FilePath) -> UTCTime -> FilePath
forall a b. (a -> b) -> a -> b
$ UTCTime
_pw_setup
secret :: Doc
secret = case Bool
sh_s of
Bool
True -> (FilePath -> FilePath -> Doc
line FilePath
"secret" (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordText -> Text
_PasswordText PasswordText
_pw_text) Doc -> Doc -> Doc
P.<$$> Doc
P.empty
Bool
False -> Doc
P.empty
line :: String -> String -> P.Doc
line :: FilePath -> FilePath -> Doc
line FilePath
nm FilePath
vl = Doc -> Doc
P.bold(FilePath -> Doc
P.string (FilePath -> Doc) -> FilePath -> Doc
forall a b. (a -> b) -> a -> b
$ Int -> FilePath -> FilePath
ljust Int
8 FilePath
nm) Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<> FilePath -> Doc
P.string FilePath
" : " Doc -> Doc -> Doc
forall a. Semigroup a => a -> a -> a
P.<>
Int -> Doc -> Doc
P.hang Int
8 (FilePath -> Doc
P.string FilePath
vl)
ljust :: Int -> FilePath -> FilePath
ljust Int
n FilePath
s = FilePath
s FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Int -> Char -> FilePath
forall a. Int -> a -> [a]
replicate (Int -> Int -> Int
forall a. Ord a => a -> a -> a
max Int
0 (Int
nInt -> Int -> Int
forall a. Num a => a -> a -> a
-FilePath -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
s)) Char
' '
dump :: PW p => PMConfig p -> Bool -> IO ()
dump :: PMConfig p -> Bool -> IO ()
dump PMConfig p
pmc Bool
inc_ssns = PMConfig p -> (PasswordStore -> IO ()) -> IO ()
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc PasswordStore -> IO ()
dmp IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMConfig p -> Bool -> Maybe p -> IO ()
forall p. PW p => PMConfig p -> Bool -> Maybe p -> IO ()
prime PMConfig p
pmc Bool
True Maybe p
forall a. Maybe a
Nothing
where
dmp :: PasswordStore -> IO ()
dmp ps :: PasswordStore
ps@PasswordStore{UTCTime
PasswordMap
PasswordStoreComment
_ps_setup :: UTCTime
_ps_map :: PasswordMap
_ps_comment :: PasswordStoreComment
_ps_setup :: PasswordStore -> UTCTime
_ps_map :: PasswordStore -> PasswordMap
_ps_comment :: PasswordStore -> PasswordStoreComment
..} = FilePath -> IO ()
putStr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath
-> PasswordStoreComment
-> [(p, PasswordText)]
-> [(p, SessionName)]
-> FilePath
forall p.
PW p =>
FilePath
-> PasswordStoreComment
-> [(p, PasswordText)]
-> [(p, SessionName)]
-> FilePath
format_dump (PMConfig p -> FilePath
forall p. PMConfig p -> FilePath
_pmc_dump_prefix PMConfig p
pmc) PasswordStoreComment
_ps_comment [(p, PasswordText)]
al_l [(p, SessionName)]
al_s
where
al_l :: [(p, PasswordText)]
al_l =
[ (p
p,Password -> PasswordText
_pw_text Password
pw)
| p
p <- [p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound]
, Just Password
pw <- [PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName (p -> PasswordName) -> p -> PasswordName
forall a b. (a -> b) -> a -> b
$ PMConfig p -> p -> p
forall p. PMConfig p -> p -> p
cast_pmc PMConfig p
pmc p
p) PasswordMap
_ps_map]
, Maybe (PasswordText -> Either FilePath SessionDescriptor) -> Bool
forall a. Maybe a -> Bool
isNothing (Maybe (PasswordText -> Either FilePath SessionDescriptor) -> Bool)
-> Maybe (PasswordText -> Either FilePath SessionDescriptor)
-> Bool
forall a b. (a -> b) -> a -> b
$ p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession p
p
, Password -> Bool
is_primed Password
pw
] [(p, PasswordText)] -> [(p, PasswordText)] -> [(p, PasswordText)]
forall a. [a] -> [a] -> [a]
++
[ (p
p,Session -> PasswordText
_ssn_password Session
ssn)
| Bool
inc_ssns
, (p
p,Password
_,Session
ssn) <- Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
forall p.
PW p =>
Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
lookup_sessions Maybe p
forall a. Maybe a
Nothing (Bool -> SessionName -> Bool
forall a b. a -> b -> a
const Bool
True) PasswordStore
ps
]
al_s :: [(p, SessionName)]
al_s =
[ (p
p,SessionDescriptor -> SessionName
_sd_name SessionDescriptor
sd)
| Bool
inc_ssns
, p
p <- [p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound]
, Just Password
pw <- [PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup (p -> PasswordName
forall p. PW p => p -> PasswordName
pwName (p -> PasswordName) -> p -> PasswordName
forall a b. (a -> b) -> a -> b
$ PMConfig p -> p -> p
forall p. PMConfig p -> p -> p
cast_pmc PMConfig p
pmc p
p) PasswordMap
_ps_map]
, Just PasswordText -> Either FilePath SessionDescriptor
ext <- [p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession p
p]
, Right SessionDescriptor
sd <- [PasswordText -> Either FilePath SessionDescriptor
ext (PasswordText -> Either FilePath SessionDescriptor)
-> PasswordText -> Either FilePath SessionDescriptor
forall a b. (a -> b) -> a -> b
$ Password -> PasswordText
_pw_text Password
pw]
]
collectShell :: PW p => PMConfig p -> IO ()
collectShell :: PMConfig p -> IO ()
collectShell PMConfig p
pmc = PMConfig p -> CollectConfig p -> IO ()
forall p. PW p => PMConfig p -> CollectConfig p -> IO ()
collect PMConfig p
pmc CollectConfig p
forall p. PW p => CollectConfig p
defaultCollectConfig IO () -> IO () -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> PMConfig p -> IO ()
forall p. PMConfig p -> IO ()
_pmc_shell PMConfig p
pmc
is_primed :: Password -> Bool
is_primed :: Password -> Bool
is_primed Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..} = Bool -> Bool
not Bool
_pw_isOneShot Bool -> Bool -> Bool
|| Bool
_pw_primed
lookup_session :: PW p => Maybe p -> SessionName -> PasswordStore -> IO (p,Password,Session)
lookup_session :: Maybe p
-> SessionName -> PasswordStore -> IO (p, Password, Session)
lookup_session Maybe p
mb SessionName
snm PasswordStore
ps =
case Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
forall p.
PW p =>
Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
lookup_sessions Maybe p
mb (SessionName -> SessionName -> Bool
forall a. Eq a => a -> a -> Bool
==SessionName
snm) PasswordStore
ps of
[] -> FilePath -> IO (p, Password, Session)
forall a. FilePath -> a
err FilePath
"session not loaded"
[(p, Password, Session)
r] -> (p, Password, Session) -> IO (p, Password, Session)
forall (m :: * -> *) a. Monad m => a -> m a
return (p, Password, Session)
r
[(p, Password, Session)]
_ -> FilePath -> IO (p, Password, Session)
forall a. FilePath -> a
err FilePath
"matches multiple sessions"
where
err :: FilePath -> a
err FilePath
msg = FilePath -> a
forall a. FilePath -> a
ssn_error (FilePath -> a) -> FilePath -> a
forall a b. (a -> b) -> a -> b
$ FilePath
"lookup_session: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ Text -> FilePath
T.unpack(SessionName -> Text
_SessionName SessionName
snm) FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
": " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
msg
lookup_sessions :: PW p => Maybe p -> (SessionName->Bool) -> PasswordStore -> [(p,Password,Session)]
lookup_sessions :: Maybe p
-> (SessionName -> Bool)
-> PasswordStore
-> [(p, Password, Session)]
lookup_sessions Maybe p
mb SessionName -> Bool
f PasswordStore
ps =
[ (p
p,Password
pw,Session
ssn)
| p
p <- [p
forall a. Bounded a => a
minBound..p
forall a. Bounded a => a
maxBound]
, Bool -> (p -> Bool) -> Maybe p -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True (p
pp -> p -> Bool
forall a. Eq a => a -> a -> Bool
==) Maybe p
mb
, Maybe (PasswordText -> Either FilePath SessionDescriptor) -> Bool
forall a. Maybe a -> Bool
isJust (Maybe (PasswordText -> Either FilePath SessionDescriptor) -> Bool)
-> Maybe (PasswordText -> Either FilePath SessionDescriptor)
-> Bool
forall a b. (a -> b) -> a -> b
$ p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession p
p
, let pnm :: PasswordName
pnm = p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p
, Just Password
pw <- [PasswordName -> PasswordMap -> Maybe Password
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup PasswordName
pnm (PasswordMap -> Maybe Password) -> PasswordMap -> Maybe Password
forall a b. (a -> b) -> a -> b
$ PasswordStore -> PasswordMap
_ps_map PasswordStore
ps]
, Session
ssn <- (Session -> Bool) -> [Session] -> [Session]
forall a. (a -> Bool) -> [a] -> [a]
filter (SessionName -> Bool
f (SessionName -> Bool)
-> (Session -> SessionName) -> Session -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Session -> SessionName
_ssn_name) ([Session] -> [Session]) -> [Session] -> [Session]
forall a b. (a -> b) -> a -> b
$ SessionMap -> [Session]
forall k a. Map k a -> [a]
Map.elems (SessionMap -> [Session]) -> SessionMap -> [Session]
forall a b. (a -> b) -> a -> b
$ Password -> SessionMap
_pw_sessions Password
pw
]
active_session :: PW p => (p,Password,Session) -> Bool
active_session :: (p, Password, Session) -> Bool
active_session (p
p,Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..},Session{Bool
UTC
SessionName
PasswordText
_ssn_setup :: UTC
_ssn_isOneShot :: Bool
_ssn_password :: PasswordText
_ssn_name :: SessionName
_ssn_setup :: Session -> UTC
_ssn_isOneShot :: Session -> Bool
_ssn_password :: Session -> PasswordText
_ssn_name :: Session -> SessionName
..}) = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ [()] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null
[ ()
| Just PasswordText -> Either FilePath SessionDescriptor
ext <- [p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
forall p.
PW p =>
p -> Maybe (PasswordText -> Either FilePath SessionDescriptor)
isSession p
p]
, Right SessionDescriptor
sd <- [PasswordText -> Either FilePath SessionDescriptor
ext PasswordText
_pw_text]
, SessionDescriptor -> SessionName
_sd_name SessionDescriptor
sd SessionName -> SessionName -> Bool
forall a. Eq a => a -> a -> Bool
== SessionName
_ssn_name
]
get_pw :: PW p => Bool -> PMConfig p -> IO PasswordText
get_pw :: Bool -> PMConfig p -> IO PasswordText
get_pw Bool
hp PMConfig p
pmc = do
Handle -> Bool -> IO ()
hSetEcho Handle
stdin Bool
False
FilePath -> IO ()
putStr FilePath
"Password: "
Handle -> IO ()
hFlush Handle
stdout
FilePath
pw <- IO FilePath
getLine
Char -> IO ()
putChar Char
'\n'
Handle -> Bool -> IO ()
hSetEcho Handle
stdin Bool
True
PasswordText -> IO PasswordText
forall (m :: * -> *) a. Monad m => a -> m a
return (PasswordText -> IO PasswordText)
-> PasswordText -> IO PasswordText
forall a b. (a -> b) -> a -> b
$ Bool -> PMConfig p -> FilePath -> PasswordText
forall p. PW p => Bool -> PMConfig p -> FilePath -> PasswordText
cond_hash Bool
hp PMConfig p
pmc FilePath
pw
cond_hash :: PW p => Bool -> PMConfig p -> String -> PasswordText
cond_hash :: Bool -> PMConfig p -> FilePath -> PasswordText
cond_hash Bool
False PMConfig p
_ = Text -> PasswordText
PasswordText (Text -> PasswordText)
-> (FilePath -> Text) -> FilePath -> PasswordText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
T.pack
cond_hash Bool
True PMConfig p
pmc = PMConfig p -> FilePath -> PasswordText
forall p. PW p => PMConfig p -> FilePath -> PasswordText
hashMasterPassword PMConfig p
pmc
prime_char :: Bool -> Char
prime_char :: Bool -> Char
prime_char Bool
is_p = if Bool
is_p then Char
'+' else Char
'-'
format_dump :: PW p
=> String
-> PasswordStoreComment
-> [(p,PasswordText)]
-> [(p,SessionName)]
-> String
format_dump :: FilePath
-> PasswordStoreComment
-> [(p, PasswordText)]
-> [(p, SessionName)]
-> FilePath
format_dump FilePath
pfx PasswordStoreComment
ps_cmt [(p, PasswordText)]
al_l [(p, SessionName)]
al_s =
[FilePath] -> FilePath
unlines ([FilePath] -> FilePath) -> [FilePath] -> FilePath
forall a b. (a -> b) -> a -> b
$
(FilePath -> FilePath -> FilePath -> FilePath
forall r. PrintfType r => FilePath -> r
printf FilePath
"%s comment %s ;" FilePath
pfx (FilePath -> FilePath) -> FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
forall (t :: * -> *). Foldable t => t Char -> FilePath
esc (FilePath -> FilePath) -> FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordStoreComment -> Text
_PasswordStoreComment PasswordStoreComment
ps_cmt) FilePath -> [FilePath] -> [FilePath]
forall a. a -> [a] -> [a]
:
[ FilePath
-> FilePath -> FilePath -> FilePath -> FilePath -> FilePath
forall r. PrintfType r => FilePath -> r
printf FilePath
"%s load %-12s %-20s %-30s ;" FilePath
pfx FilePath
pnm_s FilePath
ptx_s (FilePath -> FilePath) -> FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ p -> FilePath
forall p. PW p => p -> FilePath
cmt_s p
p
| (p
p,PasswordText
ptx) <- [(p, PasswordText)]
al_l
, let pnm_s :: FilePath
pnm_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName (PasswordName -> Text) -> PasswordName -> Text
forall a b. (a -> b) -> a -> b
$ p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p
, let ptx_s :: FilePath
ptx_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordText -> Text
_PasswordText PasswordText
ptx
] [FilePath] -> [FilePath] -> [FilePath]
forall a. [a] -> [a] -> [a]
++
[ FilePath -> FilePath -> FilePath -> FilePath -> FilePath
forall r. PrintfType r => FilePath -> r
printf FilePath
"%s select -p %s %s ;" FilePath
pfx FilePath
pnm_s FilePath
snm_s
| (p
p,SessionName
snm) <- [(p, SessionName)]
al_s
, let pnm_s :: FilePath
pnm_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName (PasswordName -> Text) -> PasswordName -> Text
forall a b. (a -> b) -> a -> b
$ p -> PasswordName
forall p. PW p => p -> PasswordName
pwName p
p
, let snm_s :: FilePath
snm_s = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ SessionName -> Text
_SessionName SessionName
snm
]
where
cmt_s :: p -> FilePath
cmt_s p
p = case p -> FilePath
forall p. PW p => p -> FilePath
summarize p
p of
FilePath
"" -> FilePath
""
FilePath
s -> FilePath
"# " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath -> FilePath
forall (t :: * -> *). Foldable t => t Char -> FilePath
esc FilePath
s
esc :: t Char -> FilePath
esc t Char
s = Char
'\'' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: (Char -> FilePath -> FilePath) -> FilePath -> t Char -> FilePath
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Char -> FilePath -> FilePath
tr FilePath
"\'" t Char
s
where
tr :: Char -> FilePath -> FilePath
tr Char
'\'' FilePath
t = Char
'\\' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: Char
'\'' Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: FilePath
t
tr Char
c FilePath
t = Char
c Char -> FilePath -> FilePath
forall a. a -> [a] -> [a]
: FilePath
t
wrap_def :: PW p => PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap_def :: PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap_def PMConfig p
pmc PasswordStore -> IO (Maybe PasswordStore)
f = IO () -> (AESKey -> IO ()) -> Maybe AESKey -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (PMConfig p
-> (PasswordStore -> IO (Maybe PasswordStore)) -> AESKey -> IO ()
forall p.
PW p =>
PMConfig p
-> (PasswordStore -> IO (Maybe PasswordStore)) -> AESKey -> IO ()
wrap' PMConfig p
pmc PasswordStore -> IO (Maybe PasswordStore)
f) (Maybe AESKey -> IO ()) -> IO (Maybe AESKey) -> IO ()
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< PMConfig p -> IO (Maybe AESKey)
forall p. PW p => PMConfig p -> IO (Maybe AESKey)
get_key' PMConfig p
pmc
wrap :: PW p => PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap :: PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> IO ()
wrap PMConfig p
pmc PasswordStore -> IO (Maybe PasswordStore)
f = PMConfig p -> IO AESKey
forall p. PW p => PMConfig p -> IO AESKey
get_key PMConfig p
pmc IO AESKey -> (AESKey -> IO ()) -> IO ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PMConfig p
-> (PasswordStore -> IO (Maybe PasswordStore)) -> AESKey -> IO ()
forall p.
PW p =>
PMConfig p
-> (PasswordStore -> IO (Maybe PasswordStore)) -> AESKey -> IO ()
wrap' PMConfig p
pmc PasswordStore -> IO (Maybe PasswordStore)
f
wrap' :: PW p => PMConfig p -> (PasswordStore -> IO (Maybe PasswordStore)) -> AESKey -> IO ()
wrap' :: PMConfig p
-> (PasswordStore -> IO (Maybe PasswordStore)) -> AESKey -> IO ()
wrap' PMConfig p
pmc PasswordStore -> IO (Maybe PasswordStore)
f AESKey
aek = do
PasswordStore
pws <- PMConfig p -> AESKey -> IO PasswordStore
forall p. PW p => PMConfig p -> AESKey -> IO PasswordStore
load_ps PMConfig p
pmc AESKey
aek
Maybe PasswordStore
mb <- PasswordStore -> IO (Maybe PasswordStore)
f PasswordStore
pws
IO () -> (PasswordStore -> IO ()) -> Maybe PasswordStore -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()) (PMConfig p -> AESKey -> PasswordStore -> IO ()
forall p. PW p => PMConfig p -> AESKey -> PasswordStore -> IO ()
save_ps PMConfig p
pmc AESKey
aek) Maybe PasswordStore
mb
getStore :: PW p => PMConfig p -> IO PasswordStore
getStore :: PMConfig p -> IO PasswordStore
getStore PMConfig p
pmc = PMConfig p
-> (PasswordStore -> IO PasswordStore) -> IO PasswordStore
forall p a. PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc PasswordStore -> IO PasswordStore
forall (m :: * -> *) a. Monad m => a -> m a
return
enquire :: PW p => PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire :: PMConfig p -> (PasswordStore -> IO a) -> IO a
enquire PMConfig p
pmc PasswordStore -> IO a
f = do
AESKey
aek <- PMConfig p -> IO AESKey
forall p. PW p => PMConfig p -> IO AESKey
get_key PMConfig p
pmc
PMConfig p -> AESKey -> IO PasswordStore
forall p. PW p => PMConfig p -> AESKey -> IO PasswordStore
load_ps PMConfig p
pmc AESKey
aek IO PasswordStore -> (PasswordStore -> IO a) -> IO a
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= PasswordStore -> IO a
f
password_valid :: PW p => PMConfig p -> FilePath -> AESKey -> IO (Maybe PasswordStore)
password_valid :: PMConfig p -> FilePath -> AESKey -> IO (Maybe PasswordStore)
password_valid PMConfig p
pmc FilePath
fp AESKey
aek = IO (Maybe PasswordStore)
-> (SomeException -> IO (Maybe PasswordStore))
-> IO (Maybe PasswordStore)
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch IO (Maybe PasswordStore)
ld SomeException -> IO (Maybe PasswordStore)
forall (m :: * -> *) a. Monad m => SomeException -> m (Maybe a)
hd
where
ld :: IO (Maybe PasswordStore)
ld = PasswordStore -> Maybe PasswordStore
forall a. a -> Maybe a
Just (PasswordStore -> Maybe PasswordStore)
-> IO PasswordStore -> IO (Maybe PasswordStore)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PMConfig p -> FilePath -> AESKey -> IO PasswordStore
forall p.
PW p =>
PMConfig p -> FilePath -> AESKey -> IO PasswordStore
load_ps_ PMConfig p
pmc FilePath
fp AESKey
aek
hd :: SomeException -> m (Maybe a)
hd (SomeException
_::SomeException) = Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
load_ps :: PW p => PMConfig p -> AESKey -> IO PasswordStore
load_ps :: PMConfig p -> AESKey -> IO PasswordStore
load_ps PMConfig p
pmc = PMConfig p -> FilePath -> AESKey -> IO PasswordStore
forall p.
PW p =>
PMConfig p -> FilePath -> AESKey -> IO PasswordStore
load_ps_ PMConfig p
pmc (PMConfig p -> FilePath
forall p. PMConfig p -> FilePath
_pmc_location PMConfig p
pmc)
load_ps_ :: PW p => PMConfig p -> FilePath -> AESKey -> IO PasswordStore
load_ps_ :: PMConfig p -> FilePath -> AESKey -> IO PasswordStore
load_ps_ PMConfig p
pmc FilePath
fp AESKey
aek = do
AESSecretData
aed <- PMConfig p -> FilePath -> IO AESSecretData
forall p. PW p => PMConfig p -> FilePath -> IO AESSecretData
load_ps' PMConfig p
pmc FilePath
fp
case ByteString -> Either [(JSONError, Position)] PasswordStore
forall a.
FromJSONWithErrs a =>
ByteString -> Either [(JSONError, Position)] a
decodeWithErrs (ByteString -> Either [(JSONError, Position)] PasswordStore)
-> ByteString -> Either [(JSONError, Position)] PasswordStore
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ByteString
BL.fromChunks [Binary -> ByteString
_Binary (Binary -> ByteString) -> Binary -> ByteString
forall a b. (a -> b) -> a -> b
$ ClearText -> Binary
_ClearText (ClearText -> Binary) -> ClearText -> Binary
forall a b. (a -> b) -> a -> b
$ AESKey -> AESSecretData -> ClearText
decryptAES AESKey
aek AESSecretData
aed] of
Right PasswordStore
pws -> PasswordStore -> IO PasswordStore
forall (m :: * -> *) a. Monad m => a -> m a
return PasswordStore
pws
Left [(JSONError, Position)]
ers -> FilePath -> IO PasswordStore
forall a. HasCallStack => FilePath -> a
error (FilePath -> IO PasswordStore) -> FilePath -> IO PasswordStore
forall a b. (a -> b) -> a -> b
$ [(JSONError, Position)] -> FilePath
prettyJSONErrorPositions [(JSONError, Position)]
ers
save_ps :: PW p => PMConfig p -> AESKey -> PasswordStore -> IO ()
save_ps :: PMConfig p -> AESKey -> PasswordStore -> IO ()
save_ps PMConfig p
pmc AESKey
aek PasswordStore
pws = do
IV
iv <- Octets -> (Binary -> IV) -> IO IV
forall a. Octets -> (Binary -> a) -> IO a
random_bytes Octets
sizeAesIV Binary -> IV
IV
PMConfig p -> AESSecretData -> IO ()
forall p. PW p => PMConfig p -> AESSecretData -> IO ()
save_ps' PMConfig p
pmc (AESSecretData -> IO ()) -> AESSecretData -> IO ()
forall a b. (a -> b) -> a -> b
$ AESKey -> IV -> ClearText -> AESSecretData
encryptAES AESKey
aek IV
iv (ClearText -> AESSecretData) -> ClearText -> AESSecretData
forall a b. (a -> b) -> a -> b
$ Binary -> ClearText
ClearText (Binary -> ClearText) -> Binary -> ClearText
forall a b. (a -> b) -> a -> b
$ ByteString -> Binary
Binary (ByteString -> Binary) -> ByteString -> Binary
forall a b. (a -> b) -> a -> b
$ ByteString -> ByteString
BL.toStrict (ByteString -> ByteString) -> ByteString -> ByteString
forall a b. (a -> b) -> a -> b
$ PasswordStore -> ByteString
forall a. ToJSON a => a -> ByteString
A.encode PasswordStore
pws
load_ps' :: PW p => PMConfig p -> FilePath -> IO AESSecretData
load_ps' :: PMConfig p -> FilePath -> IO AESSecretData
load_ps' PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} FilePath
fp = (IO AESSecretData
-> (SomeException -> IO AESSecretData) -> IO AESSecretData)
-> (SomeException -> IO AESSecretData)
-> IO AESSecretData
-> IO AESSecretData
forall a b c. (a -> b -> c) -> b -> a -> c
flip IO AESSecretData
-> (SomeException -> IO AESSecretData) -> IO AESSecretData
forall e a. Exception e => IO a -> (e -> IO a) -> IO a
catch SomeException -> IO AESSecretData
forall a. SomeException -> a
hdl (IO AESSecretData -> IO AESSecretData)
-> IO AESSecretData -> IO AESSecretData
forall a b. (a -> b) -> a -> b
$ do
(ByteString
iv,ByteString
ct) <- Int -> ByteString -> (ByteString, ByteString)
B.splitAt (Octets -> Int
_Octets Octets
sizeAesIV) (ByteString -> (ByteString, ByteString))
-> IO ByteString -> IO (ByteString, ByteString)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> IO ByteString
B.readFile FilePath
fp
AESSecretData -> IO AESSecretData
forall (m :: * -> *) a. Monad m => a -> m a
return
AESSecretData :: IV -> SecretData -> AESSecretData
AESSecretData
{ _asd_iv :: IV
_asd_iv = Binary -> IV
IV (Binary -> IV) -> Binary -> IV
forall a b. (a -> b) -> a -> b
$ ByteString -> Binary
Binary ByteString
iv
, _asd_secret_data :: SecretData
_asd_secret_data = Binary -> SecretData
SecretData (Binary -> SecretData) -> Binary -> SecretData
forall a b. (a -> b) -> a -> b
$ ByteString -> Binary
Binary ByteString
ct
}
where
hdl :: SomeException -> a
hdl (SomeException
_::SomeException) = FilePath -> a
forall a. HasCallStack => FilePath -> a
error FilePath
_pmc_keystore_msg
merge_ps :: Bool -> PasswordStore -> PasswordStore -> PasswordStore
merge_ps :: Bool -> PasswordStore -> PasswordStore -> PasswordStore
merge_ps Bool
x_pps PasswordStore
ps PasswordStore
ps0' =
PasswordStore :: PasswordStoreComment -> PasswordMap -> UTCTime -> PasswordStore
PasswordStore
{ _ps_comment :: PasswordStoreComment
_ps_comment = PasswordStore -> PasswordStoreComment
_ps_comment PasswordStore
ps'
, _ps_map :: PasswordMap
_ps_map = (Password -> Password -> Password)
-> PasswordMap -> PasswordMap -> PasswordMap
forall k a. Ord k => (a -> a -> a) -> Map k a -> Map k a -> Map k a
Map.unionWith Password -> Password -> Password
f (PasswordStore -> PasswordMap
_ps_map PasswordStore
ps) (PasswordStore -> PasswordMap
_ps_map PasswordStore
ps')
, _ps_setup :: UTCTime
_ps_setup = PasswordStore -> UTCTime
_ps_setup PasswordStore
ps
}
where
f :: Password -> Password -> Password
f Password
pw Password
pw' = ASetter Password Password SessionMap SessionMap
-> (SessionMap -> SessionMap) -> Password -> Password
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter Password Password SessionMap SessionMap
Lens' Password SessionMap
pw_sessions ((SessionMap -> SessionMap -> SessionMap)
-> SessionMap -> SessionMap -> SessionMap
forall a b c. (a -> b -> c) -> b -> a -> c
flip SessionMap -> SessionMap -> SessionMap
forall k a. Ord k => Map k a -> Map k a -> Map k a
Map.union (SessionMap -> SessionMap -> SessionMap)
-> SessionMap -> SessionMap -> SessionMap
forall a b. (a -> b) -> a -> b
$ Password -> SessionMap
_pw_sessions Password
pw) Password
pw'
ps' :: PasswordStore
ps' = case Bool
x_pps of
Bool
True -> ASetter PasswordStore PasswordStore PasswordMap PasswordMap
-> (PasswordMap -> PasswordMap) -> PasswordStore -> PasswordStore
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
L.over ASetter PasswordStore PasswordStore PasswordMap PasswordMap
Lens' PasswordStore PasswordMap
ps_map ((Password -> Bool) -> PasswordMap -> PasswordMap
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter Password -> Bool
is_static_pw) PasswordStore
ps0'
Bool
False -> PasswordStore
ps0'
is_static_pw :: Password -> Bool
is_static_pw :: Password -> Bool
is_static_pw Password{Bool
UTCTime
SessionMap
PasswordText
PasswordName
_pw_setup :: UTCTime
_pw_primed :: Bool
_pw_isOneShot :: Bool
_pw_sessions :: SessionMap
_pw_text :: PasswordText
_pw_name :: PasswordName
_pw_setup :: Password -> UTCTime
_pw_primed :: Password -> Bool
_pw_isOneShot :: Password -> Bool
_pw_sessions :: Password -> SessionMap
_pw_text :: Password -> PasswordText
_pw_name :: Password -> PasswordName
..} = case Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName PasswordName
_pw_name of
Char
'+':FilePath
_ -> Bool
False
FilePath
_ -> Bool
True
random_bytes :: Octets -> (Binary->a) -> IO a
random_bytes :: Octets -> (Binary -> a) -> IO a
random_bytes Octets
sz Binary -> a
f = Binary -> a
f (Binary -> a) -> (CPRNG -> Binary) -> CPRNG -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Binary
Binary (ByteString -> Binary) -> (CPRNG -> ByteString) -> CPRNG -> Binary
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ByteString, CPRNG) -> ByteString
forall a b. (a, b) -> a
fst ((ByteString, CPRNG) -> ByteString)
-> (CPRNG -> (ByteString, CPRNG)) -> CPRNG -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> CPRNG -> (ByteString, CPRNG)
forall ba. ByteArray ba => Int -> CPRNG -> (ba, CPRNG)
generateCPRNG (Octets -> Int
_Octets Octets
sz) (CPRNG -> a) -> IO CPRNG -> IO a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> IO CPRNG
newCPRNG
save_ps' :: PW p => PMConfig p -> AESSecretData -> IO ()
save_ps' :: PMConfig p -> AESSecretData -> IO ()
save_ps' PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} AESSecretData{SecretData
IV
_asd_secret_data :: SecretData
_asd_iv :: IV
_asd_secret_data :: AESSecretData -> SecretData
_asd_iv :: AESSecretData -> IV
..} = FilePath -> ByteString -> IO ()
B.writeFile FilePath
_pmc_location (ByteString -> IO ()) -> ByteString -> IO ()
forall a b. (a -> b) -> a -> b
$ [ByteString] -> ByteString
B.concat [ByteString
iv_bs,ByteString
ct_bs]
where
iv_bs :: ByteString
iv_bs = Binary -> ByteString
_Binary (Binary -> ByteString) -> Binary -> ByteString
forall a b. (a -> b) -> a -> b
$ IV -> Binary
_IV IV
_asd_iv
ct_bs :: ByteString
ct_bs = Binary -> ByteString
_Binary (Binary -> ByteString) -> Binary -> ByteString
forall a b. (a -> b) -> a -> b
$ SecretData -> Binary
_SecretData SecretData
_asd_secret_data
get_key :: PW p => PMConfig p -> IO AESKey
get_key :: PMConfig p -> IO AESKey
get_key PMConfig p
pmc = PMConfig p -> IO (Maybe AESKey)
forall p. PW p => PMConfig p -> IO (Maybe AESKey)
get_key' PMConfig p
pmc IO (Maybe AESKey) -> (Maybe AESKey -> IO AESKey) -> IO AESKey
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= IO AESKey -> (AESKey -> IO AESKey) -> Maybe AESKey -> IO AESKey
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (PMConfig p -> IO AESKey
forall p a. PW p => PMConfig p -> IO a
not_logged_in_err PMConfig p
pmc) AESKey -> IO AESKey
forall (m :: * -> *) a. Monad m => a -> m a
return
not_logged_in_err :: PW p => PMConfig p -> IO a
not_logged_in_err :: PMConfig p -> IO a
not_logged_in_err pmc :: PMConfig p
pmc@PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} = do
Bool
ex <- PMConfig p -> IO Bool
forall p. PW p => PMConfig p -> IO Bool
isStorePresent PMConfig p
pmc
FilePath -> IO a
forall a. HasCallStack => FilePath -> a
error (FilePath -> IO a) -> FilePath -> IO a
forall a b. (a -> b) -> a -> b
$ if Bool
ex then FilePath
_pmc_password_msg else FilePath
_pmc_keystore_msg
get_key' :: PW p => PMConfig p -> IO (Maybe AESKey)
get_key' :: PMConfig p -> IO (Maybe AESKey)
get_key' PMConfig{Bool
FilePath
Maybe FilePath
IO ()
EnvVar
HashDescription
PasswordName -> Maybe EnvVar
_pmc_plus_env_var :: PasswordName -> Maybe EnvVar
_pmc_sample_script :: Maybe FilePath
_pmc_dump_prefix :: FilePath
_pmc_allow_dumps :: Bool
_pmc_hash_descr :: HashDescription
_pmc_shell :: IO ()
_pmc_password_msg :: FilePath
_pmc_keystore_msg :: FilePath
_pmc_env_var :: EnvVar
_pmc_location :: FilePath
_pmc_plus_env_var :: forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_sample_script :: forall p. PMConfig p -> Maybe FilePath
_pmc_dump_prefix :: forall p. PMConfig p -> FilePath
_pmc_allow_dumps :: forall p. PMConfig p -> Bool
_pmc_hash_descr :: forall p. PMConfig p -> HashDescription
_pmc_shell :: forall p. PMConfig p -> IO ()
_pmc_password_msg :: forall p. PMConfig p -> FilePath
_pmc_keystore_msg :: forall p. PMConfig p -> FilePath
_pmc_env_var :: forall p. PMConfig p -> EnvVar
_pmc_location :: forall p. PMConfig p -> FilePath
..} = (FilePath -> AESKey) -> Maybe FilePath -> Maybe AESKey
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap FilePath -> AESKey
mk_aek' (Maybe FilePath -> Maybe AESKey)
-> IO (Maybe FilePath) -> IO (Maybe AESKey)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> IO (Maybe FilePath)
E.lookupEnv FilePath
var
where
var :: FilePath
var = Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ EnvVar -> Text
_EnvVar EnvVar
_pmc_env_var
mk_aek :: PasswordText -> AESKey
mk_aek :: PasswordText -> AESKey
mk_aek = FilePath -> AESKey
mk_aek' (FilePath -> AESKey)
-> (PasswordText -> FilePath) -> PasswordText -> AESKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> FilePath
T.unpack (Text -> FilePath)
-> (PasswordText -> Text) -> PasswordText -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PasswordText -> Text
_PasswordText
mk_aek' :: String -> AESKey
mk_aek' :: FilePath -> AESKey
mk_aek' = Binary -> AESKey
AESKey (Binary -> AESKey) -> (FilePath -> Binary) -> FilePath -> AESKey
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Binary
Binary (ByteString -> Binary)
-> (FilePath -> ByteString) -> FilePath -> Binary
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FilePath -> ByteString)
-> (ByteString -> ByteString)
-> Either FilePath ByteString
-> ByteString
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either FilePath -> ByteString
forall a. a
err ByteString -> ByteString
forall a. a -> a
id (Either FilePath ByteString -> ByteString)
-> (FilePath -> Either FilePath ByteString)
-> FilePath
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either FilePath ByteString
B64.decode (ByteString -> Either FilePath ByteString)
-> (FilePath -> ByteString)
-> FilePath
-> Either FilePath ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> ByteString
B.pack
where
err :: a
err = FilePath -> a
forall a. HasCallStack => FilePath -> a
error FilePath
"bad format for the master password"
pretty_setup :: TimeZone -> UTCTime -> String
pretty_setup :: TimeZone -> UTCTime -> FilePath
pretty_setup TimeZone
tz = TimeLocale -> FilePath -> ZonedTime -> FilePath
forall t. FormatTime t => TimeLocale -> FilePath -> t -> FilePath
formatTime TimeLocale
defaultTimeLocale FilePath
"%F %H:%M" (ZonedTime -> FilePath)
-> (UTCTime -> ZonedTime) -> UTCTime -> FilePath
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeZone -> UTCTime -> ZonedTime
utcToZonedTime TimeZone
tz
set_env :: EnvVar -> PasswordText -> IO ()
set_env :: EnvVar -> PasswordText -> IO ()
set_env (EnvVar Text
ev) (PasswordText Text
pt) = FilePath -> FilePath -> IO ()
setEnv (Text -> FilePath
T.unpack Text
ev) (Text -> FilePath
T.unpack Text
pt)
ssn_error :: String -> a
ssn_error :: FilePath -> a
ssn_error FilePath
msg = FilePath -> a
forall a. HasCallStack => FilePath -> a
error (FilePath -> a) -> FilePath -> a
forall a b. (a -> b) -> a -> b
$ FilePath
"session manager error: " FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
msg
passwordManager' :: PW p => PMConfig p -> PMCommand p -> IO ()
passwordManager' :: PMConfig p -> PMCommand p -> IO ()
passwordManager' PMConfig p
pmc PMCommand p
pmcd =
case PMCommand p
pmcd of
PMCommand p
PMCD_version -> FilePath -> IO ()
putStrLn FilePath
version
PMCD_setup Bool
nl Maybe PasswordText
mb_t -> PMConfig p -> Bool -> Maybe PasswordText -> IO ()
forall p. PW p => PMConfig p -> Bool -> Maybe PasswordText -> IO ()
setup PMConfig p
pmc Bool
nl Maybe PasswordText
mb_t
PMCD_login Bool
y Maybe PasswordText
mb_t -> PMConfig p -> Bool -> Maybe PasswordText -> IO ()
forall p. PW p => PMConfig p -> Bool -> Maybe PasswordText -> IO ()
login PMConfig p
pmc Bool
y Maybe PasswordText
mb_t
PMCD_import Bool
x_pps FilePath
fp Maybe PasswordText
mb_t -> Bool -> PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
forall p.
PW p =>
Bool -> PMConfig p -> FilePath -> Maybe PasswordText -> IO ()
import__ Bool
x_pps PMConfig p
pmc FilePath
fp Maybe PasswordText
mb_t
PMCD_load p
p Maybe PasswordText
mb_t -> PMConfig p -> p -> Maybe PasswordText -> IO ()
forall p. PW p => PMConfig p -> p -> Maybe PasswordText -> IO ()
load PMConfig p
pmc p
p Maybe PasswordText
mb_t
PMCD_load_plus PasswordName
pnm Maybe PasswordText
mb_t -> PMConfig p -> PasswordName -> Maybe PasswordText -> IO ()
forall p.
PW p =>
PMConfig p -> PasswordName -> Maybe PasswordText -> IO ()
loadPlus PMConfig p
pmc PasswordName
pnm Maybe PasswordText
mb_t
PMCD_comment PasswordStoreComment
cmt -> PMConfig p -> PasswordStoreComment -> IO ()
forall p. PW p => PMConfig p -> PasswordStoreComment -> IO ()
psComment PMConfig p
pmc PasswordStoreComment
cmt
PMCD_prime Bool
u p
p -> PMConfig p -> Bool -> Maybe p -> IO ()
forall p. PW p => PMConfig p -> Bool -> Maybe p -> IO ()
prime PMConfig p
pmc Bool
u (Maybe p -> IO ()) -> Maybe p -> IO ()
forall a b. (a -> b) -> a -> b
$ p -> Maybe p
forall a. a -> Maybe a
Just p
p
PMCD_prime_all Bool
u -> PMConfig p -> Bool -> Maybe p -> IO ()
forall p. PW p => PMConfig p -> Bool -> Maybe p -> IO ()
prime PMConfig p
pmc Bool
u Maybe p
forall a. Maybe a
Nothing
PMCD_select Maybe p
mb SessionName
snm -> PMConfig p -> Maybe p -> SessionName -> IO ()
forall p. PW p => PMConfig p -> Maybe p -> SessionName -> IO ()
select PMConfig p
pmc Maybe p
mb SessionName
snm
PMCD_delete_password p
p -> PMConfig p -> p -> IO ()
forall p. PW p => PMConfig p -> p -> IO ()
deletePassword PMConfig p
pmc p
p
PMCD_delete_password_plus Maybe PasswordName
pnm -> PMConfig p -> Maybe PasswordName -> IO ()
forall p. PW p => PMConfig p -> Maybe PasswordName -> IO ()
deletePasswordPlus PMConfig p
pmc Maybe PasswordName
pnm
PMCD_delete_session Maybe p
mb SessionName
snm -> PMConfig p -> Maybe p -> SessionName -> IO ()
forall p. PW p => PMConfig p -> Maybe p -> SessionName -> IO ()
deleteSession PMConfig p
pmc Maybe p
mb SessionName
snm
PMCD_status Bool
q -> PMConfig p -> Bool -> IO ()
forall p. PW p => PMConfig p -> Bool -> IO ()
status PMConfig p
pmc Bool
q
PMCommand p
PMCD_prompt -> PMConfig p -> IO ()
forall p. PW p => PMConfig p -> IO ()
prompt PMConfig p
pmc
PMCD_passwords Bool
b -> PMConfig p -> Bool -> IO ()
forall p. PW p => PMConfig p -> Bool -> IO ()
passwords PMConfig p
pmc Bool
b
PMCD_passwords_plus Bool
b -> PMConfig p -> Bool -> IO ()
forall p. PW p => PMConfig p -> Bool -> IO ()
passwordsPlus PMConfig p
pmc Bool
b
PMCD_session Bool
b -> PMConfig p -> Bool -> Bool -> Maybe p -> IO ()
forall p. PW p => PMConfig p -> Bool -> Bool -> Maybe p -> IO ()
sessions PMConfig p
pmc Bool
True Bool
b Maybe p
forall a. Maybe a
Nothing
PMCD_sessions Bool
b Maybe p
mb -> PMConfig p -> Bool -> Bool -> Maybe p -> IO ()
forall p. PW p => PMConfig p -> Bool -> Bool -> Maybe p -> IO ()
sessions PMConfig p
pmc Bool
False Bool
b Maybe p
mb
PMCD_info Bool
s p
p -> PMConfig p -> Bool -> p -> IO ()
forall p. PW p => PMConfig p -> Bool -> p -> IO ()
infoPassword PMConfig p
pmc Bool
s p
p
PMCD_info_plus Bool
s PasswordName
pnm -> PMConfig p -> Bool -> PasswordName -> IO ()
forall p. PW p => PMConfig p -> Bool -> PasswordName -> IO ()
infoPasswordPlus PMConfig p
pmc Bool
s PasswordName
pnm
PMCD_dump Bool
s -> PMConfig p -> Bool -> IO ()
forall p. PW p => PMConfig p -> Bool -> IO ()
dump PMConfig p
pmc Bool
s
PMCommand p
PMCD_collect -> PMConfig p -> IO ()
forall p. PW p => PMConfig p -> IO ()
collectShell PMConfig p
pmc
PMCommand p
PMCD_sample_script -> FilePath -> IO ()
putStr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ FilePath -> (FilePath -> FilePath) -> Maybe FilePath -> FilePath
forall b a. b -> (a -> b) -> Maybe a -> b
maybe FilePath
"" FilePath -> FilePath
forall a. a -> a
id (Maybe FilePath -> FilePath) -> Maybe FilePath -> FilePath
forall a b. (a -> b) -> a -> b
$ PMConfig p -> Maybe FilePath
forall p. PMConfig p -> Maybe FilePath
_pmc_sample_script PMConfig p
pmc
data PMCommand p
= PMCD_version
| PMCD_setup Bool (Maybe PasswordText)
| PMCD_login Bool (Maybe PasswordText)
| PMCD_import Bool FilePath (Maybe PasswordText)
| PMCD_load p (Maybe PasswordText)
| PMCD_load_plus PasswordName (Maybe PasswordText)
| PasswordStoreComment
| PMCD_prime Bool p
| PMCD_prime_all Bool
| PMCD_select (Maybe p) SessionName
| PMCD_delete_password p
| PMCD_delete_password_plus (Maybe PasswordName)
| PMCD_delete_session (Maybe p) SessionName
| PMCD_status Bool
| PMCD_prompt
| PMCD_passwords Bool
| PMCD_passwords_plus Bool
| PMCD_session Bool
| PMCD_sessions Bool (Maybe p)
| PMCD_info Bool p
| PMCD_info_plus Bool PasswordName
| PMCD_dump Bool
| PMCD_collect
| PMCD_sample_script
deriving (Int -> PMCommand p -> FilePath -> FilePath
[PMCommand p] -> FilePath -> FilePath
PMCommand p -> FilePath
(Int -> PMCommand p -> FilePath -> FilePath)
-> (PMCommand p -> FilePath)
-> ([PMCommand p] -> FilePath -> FilePath)
-> Show (PMCommand p)
forall p. Show p => Int -> PMCommand p -> FilePath -> FilePath
forall p. Show p => [PMCommand p] -> FilePath -> FilePath
forall p. Show p => PMCommand p -> FilePath
forall a.
(Int -> a -> FilePath -> FilePath)
-> (a -> FilePath) -> ([a] -> FilePath -> FilePath) -> Show a
showList :: [PMCommand p] -> FilePath -> FilePath
$cshowList :: forall p. Show p => [PMCommand p] -> FilePath -> FilePath
show :: PMCommand p -> FilePath
$cshow :: forall p. Show p => PMCommand p -> FilePath
showsPrec :: Int -> PMCommand p -> FilePath -> FilePath
$cshowsPrec :: forall p. Show p => Int -> PMCommand p -> FilePath -> FilePath
Show)
parsePMCommand :: PW p => PMConfig p -> [String] -> IO (PMCommand p)
parsePMCommand :: PMConfig p -> [FilePath] -> IO (PMCommand p)
parsePMCommand PMConfig p
pmc = ParserInfo (PMCommand p) -> [FilePath] -> IO (PMCommand p)
forall a. ParserInfo a -> [FilePath] -> IO a
run_parse (ParserInfo (PMCommand p) -> [FilePath] -> IO (PMCommand p))
-> ParserInfo (PMCommand p) -> [FilePath] -> IO (PMCommand p)
forall a b. (a -> b) -> a -> b
$ PMConfig p -> ParserInfo (PMCommand p)
forall p. PW p => PMConfig p -> ParserInfo (PMCommand p)
command_info PMConfig p
pmc
command_info :: PW p => PMConfig p -> ParserInfo (PMCommand p)
command_info :: PMConfig p -> ParserInfo (PMCommand p)
command_info PMConfig p
pmc =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info (Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PMConfig p -> Parser (PMCommand p)
forall p. PW p => PMConfig p -> Parser (PMCommand p)
pmCommandParser PMConfig p
pmc)
( InfoMod (PMCommand p)
forall a. InfoMod a
fullDesc
InfoMod (PMCommand p)
-> InfoMod (PMCommand p) -> InfoMod (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"a simple password manager"
InfoMod (PMCommand p)
-> InfoMod (PMCommand p) -> InfoMod (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
header FilePath
"pm - sub-command for managing the password store"
InfoMod (PMCommand p)
-> InfoMod (PMCommand p) -> InfoMod (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
footer FilePath
"'ks COMMAND --help' to get help on each command")
pmCommandParser :: PW p => PMConfig p -> Parser (PMCommand p)
pmCommandParser :: PMConfig p -> Parser (PMCommand p)
pmCommandParser PMConfig p
pmc =
Mod CommandFields (PMCommand p) -> Parser (PMCommand p)
forall a. Mod CommandFields a -> Parser a
subparser (Mod CommandFields (PMCommand p) -> Parser (PMCommand p))
-> Mod CommandFields (PMCommand p) -> Parser (PMCommand p)
forall a b. (a -> b) -> a -> b
$ Mod CommandFields (PMCommand p) -> Mod CommandFields (PMCommand p)
forall p.
Mod CommandFields (PMCommand p) -> Mod CommandFields (PMCommand p)
f (Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p))
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a b. (a -> b) -> a -> b
$ Mod CommandFields (PMCommand p) -> Mod CommandFields (PMCommand p)
g
(Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p))
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a b. (a -> b) -> a -> b
$ FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"version" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_version
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"setup" (PMConfig p -> ParserInfo (PMCommand p)
forall p. PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_setup PMConfig p
pmc)
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"login" (PMConfig p -> ParserInfo (PMCommand p)
forall p. PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_login PMConfig p
pmc)
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"import" (PMConfig p -> ParserInfo (PMCommand p)
forall p. PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_import PMConfig p
pmc)
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"load" (PMConfig p -> ParserInfo (PMCommand p)
forall p. PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_load PMConfig p
pmc)
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"comment" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_comment
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"prime" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_prime
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"prime-all" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_prime_all
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"select" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_select
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"delete-password" (PMConfig p -> ParserInfo (PMCommand p)
forall p. PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_delete_password PMConfig p
pmc)
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"delete-all-plus-passwords" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_delete_all_plus_passwords
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"delete-session" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_delete_session
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"status" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_status
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"prompt" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_prompt
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"passwords" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_passwords
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"passwords-plus" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_passwords_plus
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"session" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_session
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"sessions" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_sessions
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"info" (PMConfig p -> ParserInfo (PMCommand p)
forall p. PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_info PMConfig p
pmc)
Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"collect" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_collect
where
s :: Mod CommandFields (PMCommand p)
s = FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"sample-load-script" ParserInfo (PMCommand p)
forall p. ParserInfo (PMCommand p)
pi_sample_script
d :: Mod CommandFields (PMCommand p)
d = FilePath
-> ParserInfo (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. FilePath -> ParserInfo a -> Mod CommandFields a
command FilePath
"dump" ParserInfo (PMCommand p)
forall p. PW p => ParserInfo (PMCommand p)
pi_dump
f :: Mod CommandFields (PMCommand p) -> Mod CommandFields (PMCommand p)
f = case PMConfig p -> Maybe FilePath
forall p. PMConfig p -> Maybe FilePath
_pmc_sample_script PMConfig p
pmc of
Maybe FilePath
Nothing -> Mod CommandFields (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. a -> a
id
Just FilePath
_ -> (Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields (PMCommand p)
forall p. Mod CommandFields (PMCommand p)
s)
g :: Mod CommandFields (PMCommand p) -> Mod CommandFields (PMCommand p)
g = case PMConfig p -> Bool
forall p. PMConfig p -> Bool
_pmc_allow_dumps PMConfig p
pmc of
Bool
True -> (Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
-> Mod CommandFields (PMCommand p)
forall a. Semigroup a => a -> a -> a
<> Mod CommandFields (PMCommand p)
d)
Bool
False -> Mod CommandFields (PMCommand p) -> Mod CommandFields (PMCommand p)
forall a. a -> a
id
pi_version :: ParserInfo (PMCommand p)
pi_version :: ParserInfo (PMCommand p)
pi_version =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PMCommand p -> Parser (PMCommand p)
forall (f :: * -> *) a. Applicative f => a -> f a
pure PMCommand p
forall p. PMCommand p
PMCD_version)
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"report the version of this package")
pi_setup :: PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_setup :: PMConfig p -> ParserInfo (PMCommand p)
pi_setup PMConfig p
pmc =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> Maybe PasswordText -> PMCommand p
forall p. Bool -> Maybe PasswordText -> PMCommand p
PMCD_setup (Bool -> Maybe PasswordText -> PMCommand p)
-> Parser Bool -> Parser (Maybe PasswordText -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_no_login_sw Parser (Maybe PasswordText -> PMCommand p)
-> Parser (Maybe PasswordText) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PasswordText -> Parser (Maybe PasswordText)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Bool -> PMConfig p -> Parser PasswordText
forall p. PW p => Bool -> PMConfig p -> Parser PasswordText
p_password_text Bool
True PMConfig p
pmc)))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"setup the password store")
pi_login :: PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_login :: PMConfig p -> ParserInfo (PMCommand p)
pi_login PMConfig p
pmc =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> Maybe PasswordText -> PMCommand p
forall p. Bool -> Maybe PasswordText -> PMCommand p
PMCD_login (Bool -> Maybe PasswordText -> PMCommand p)
-> Parser Bool -> Parser (Maybe PasswordText -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_loop_sw Parser (Maybe PasswordText -> PMCommand p)
-> Parser (Maybe PasswordText) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PasswordText -> Parser (Maybe PasswordText)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Bool -> PMConfig p -> Parser PasswordText
forall p. PW p => Bool -> PMConfig p -> Parser PasswordText
p_password_text Bool
True PMConfig p
pmc)))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"login to the password manager")
pi_import :: PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_import :: PMConfig p -> ParserInfo (PMCommand p)
pi_import PMConfig p
pmc =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> FilePath -> Maybe PasswordText -> PMCommand p
forall p. Bool -> FilePath -> Maybe PasswordText -> PMCommand p
PMCD_import (Bool -> FilePath -> Maybe PasswordText -> PMCommand p)
-> Parser Bool
-> Parser (FilePath -> Maybe PasswordText -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_x_pps Parser (FilePath -> Maybe PasswordText -> PMCommand p)
-> Parser FilePath -> Parser (Maybe PasswordText -> PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser FilePath
p_store_fp Parser (Maybe PasswordText -> PMCommand p)
-> Parser (Maybe PasswordText) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PasswordText -> Parser (Maybe PasswordText)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Bool -> PMConfig p -> Parser PasswordText
forall p. PW p => Bool -> PMConfig p -> Parser PasswordText
p_password_text Bool
True PMConfig p
pmc)))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"import the contents of another store")
pi_load :: PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_load :: PMConfig p -> ParserInfo (PMCommand p)
pi_load PMConfig p
pmc =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PMConfig p -> Parser (PMCommand p)
forall p. PW p => PMConfig p -> Parser (PMCommand p)
p_load_command PMConfig p
pmc)
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"load a password into the store")
pi_comment :: PW p => ParserInfo (PMCommand p)
=
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (PasswordStoreComment -> PMCommand p
forall p. PasswordStoreComment -> PMCommand p
PMCD_comment (PasswordStoreComment -> PMCommand p)
-> Parser PasswordStoreComment -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser PasswordStoreComment
p_ps_comment))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"load a password into the store")
pi_prime :: PW p => ParserInfo (PMCommand p)
pi_prime :: ParserInfo (PMCommand p)
pi_prime =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> p -> PMCommand p
forall p. Bool -> p -> PMCommand p
PMCD_prime (Bool -> p -> PMCommand p)
-> Parser Bool -> Parser (p -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_unprime_sw Parser (p -> PMCommand p) -> Parser p -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser p
forall p. PW p => Parser p
p_pw_id))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"(un) prime a password for use")
pi_prime_all :: ParserInfo (PMCommand p)
pi_prime_all :: ParserInfo (PMCommand p)
pi_prime_all =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> PMCommand p
forall p. Bool -> PMCommand p
PMCD_prime_all (Bool -> PMCommand p) -> Parser Bool -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_unprime_sw))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"(un)prime all of the passwords")
pi_select :: PW p => ParserInfo (PMCommand p)
pi_select :: ParserInfo (PMCommand p)
pi_select =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe p -> SessionName -> PMCommand p
forall p. Maybe p -> SessionName -> PMCommand p
PMCD_select (Maybe p -> SessionName -> PMCommand p)
-> Parser (Maybe p) -> Parser (SessionName -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser p -> Parser (Maybe p)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser p
forall p. PW p => Parser p
p_pw_id_opt Parser (SessionName -> PMCommand p)
-> Parser SessionName -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SessionName
p_session_name))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"select a client session")
pi_delete_password :: PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_delete_password :: PMConfig p -> ParserInfo (PMCommand p)
pi_delete_password PMConfig p
pmc =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PMConfig p -> Parser (PMCommand p)
forall p. PW p => PMConfig p -> Parser (PMCommand p)
p_delete_password PMConfig p
pmc)
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"delete a password from the store")
pi_delete_all_plus_passwords :: ParserInfo (PMCommand p)
pi_delete_all_plus_passwords :: ParserInfo (PMCommand p)
pi_delete_all_plus_passwords =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PMCommand p -> Parser (PMCommand p)
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe PasswordName -> PMCommand p
forall p. Maybe PasswordName -> PMCommand p
PMCD_delete_password_plus Maybe PasswordName
forall a. Maybe a
Nothing))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"delete all dynamic (plus) passwords forom the store")
pi_delete_session :: PW p => ParserInfo (PMCommand p)
pi_delete_session :: ParserInfo (PMCommand p)
pi_delete_session =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Maybe p -> SessionName -> PMCommand p
forall p. Maybe p -> SessionName -> PMCommand p
PMCD_delete_session (Maybe p -> SessionName -> PMCommand p)
-> Parser (Maybe p) -> Parser (SessionName -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser p -> Parser (Maybe p)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser p
forall p. PW p => Parser p
p_pw_id_opt Parser (SessionName -> PMCommand p)
-> Parser SessionName -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser SessionName
p_session_name))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"delete a client session")
pi_status :: ParserInfo (PMCommand p)
pi_status :: ParserInfo (PMCommand p)
pi_status =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> PMCommand p
forall p. Bool -> PMCommand p
PMCD_status (Bool -> PMCommand p) -> Parser Bool -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_quiet_sw))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"report the status of the password manager")
pi_prompt :: ParserInfo (PMCommand p)
pi_prompt :: ParserInfo (PMCommand p)
pi_prompt =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (PMCommand p -> Parser (PMCommand p)
forall (f :: * -> *) a. Applicative f => a -> f a
pure PMCommand p
forall p. PMCommand p
PMCD_prompt))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc (FilePath -> InfoMod (PMCommand p))
-> FilePath -> InfoMod (PMCommand p)
forall a b. (a -> b) -> a -> b
$ FilePath
"report the condensed status of the password manager"FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++
FilePath
" (suitable for embedding in a shell prompt")
pi_passwords :: ParserInfo (PMCommand p)
pi_passwords :: ParserInfo (PMCommand p)
pi_passwords =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> PMCommand p
forall p. Bool -> PMCommand p
PMCD_passwords (Bool -> PMCommand p) -> Parser Bool -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_brief_sw))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"list the passwords")
pi_passwords_plus :: ParserInfo (PMCommand p)
pi_passwords_plus :: ParserInfo (PMCommand p)
pi_passwords_plus =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> PMCommand p
forall p. Bool -> PMCommand p
PMCD_passwords_plus (Bool -> PMCommand p) -> Parser Bool -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_brief_sw))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"list the dynamic ('+'') passwords")
pi_session :: PW p => ParserInfo (PMCommand p)
pi_session :: ParserInfo (PMCommand p)
pi_session =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> PMCommand p
forall p. Bool -> PMCommand p
PMCD_session (Bool -> PMCommand p) -> Parser Bool -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_brief_sw))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"list the sessions")
pi_sessions :: PW p => ParserInfo (PMCommand p)
pi_sessions :: ParserInfo (PMCommand p)
pi_sessions =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> Maybe p -> PMCommand p
forall p. Bool -> Maybe p -> PMCommand p
PMCD_sessions (Bool -> Maybe p -> PMCommand p)
-> Parser Bool -> Parser (Maybe p -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_brief_sw Parser (Maybe p -> PMCommand p)
-> Parser (Maybe p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser p -> Parser (Maybe p)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser p
forall p. PW p => Parser p
p_pw_id))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"list the sessions")
pi_info :: PW p => PMConfig p -> ParserInfo (PMCommand p)
pi_info :: PMConfig p -> ParserInfo (PMCommand p)
pi_info PMConfig p
pmc =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PMConfig p -> Parser (PMCommand p)
forall p. PW p => PMConfig p -> Parser (PMCommand p)
p_info PMConfig p
pmc)
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"print out the info on a password, including desriptive text")
pi_dump :: PW p => ParserInfo (PMCommand p)
pi_dump :: ParserInfo (PMCommand p)
pi_dump =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Bool -> PMCommand p
forall p. Bool -> PMCommand p
PMCD_dump (Bool -> PMCommand p) -> Parser Bool -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_sessions_sw))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"dump the passwords on the output as a load script")
pi_collect :: PW p => ParserInfo (PMCommand p)
pi_collect :: ParserInfo (PMCommand p)
pi_collect =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (PMCommand p -> Parser (PMCommand p)
forall (f :: * -> *) a. Applicative f => a -> f a
pure PMCommand p
forall p. PMCommand p
PMCD_collect))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"collect the passwords and launch an interacive shell")
pi_sample_script :: ParserInfo (PMCommand p)
pi_sample_script :: ParserInfo (PMCommand p)
pi_sample_script =
Parser (PMCommand p)
-> InfoMod (PMCommand p) -> ParserInfo (PMCommand p)
forall a. Parser a -> InfoMod a -> ParserInfo a
h_info
(Parser (PMCommand p -> PMCommand p)
forall a. Parser (a -> a)
helper Parser (PMCommand p -> PMCommand p)
-> Parser (PMCommand p) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (PMCommand p -> Parser (PMCommand p)
forall (f :: * -> *) a. Applicative f => a -> f a
pure PMCommand p
forall p. PMCommand p
PMCD_sample_script))
(FilePath -> InfoMod (PMCommand p)
forall a. FilePath -> InfoMod a
progDesc FilePath
"print a sample script to define keystore passwords in the environment (PM edition)")
p_load_command, p_delete_password, p_info :: PW p => PMConfig p -> Parser (PMCommand p)
p_load_command :: PMConfig p -> Parser (PMCommand p)
p_load_command PMConfig p
pmc = Either p PasswordName -> Maybe PasswordText -> PMCommand p
forall p.
Either p PasswordName -> Maybe PasswordText -> PMCommand p
f (Either p PasswordName -> Maybe PasswordText -> PMCommand p)
-> Parser (Either p PasswordName)
-> Parser (Maybe PasswordText -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PMConfig p -> Parser (Either p PasswordName)
forall p. PW p => PMConfig p -> Parser (Either p PasswordName)
p_pw PMConfig p
pmc Parser (Maybe PasswordText -> PMCommand p)
-> Parser (Maybe PasswordText) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser PasswordText -> Parser (Maybe PasswordText)
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Bool -> PMConfig p -> Parser PasswordText
forall p. PW p => Bool -> PMConfig p -> Parser PasswordText
p_password_text Bool
False PMConfig p
pmc) Parser (PMCommand p) -> Parser (Maybe ()) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser () -> Parser (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional Parser ()
p_load_comment
where
f :: Either p PasswordName -> Maybe PasswordText -> PMCommand p
f Either p PasswordName
ei Maybe PasswordText
op_p = (p -> PMCommand p)
-> (PasswordName -> PMCommand p)
-> Either p PasswordName
-> PMCommand p
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ((p -> Maybe PasswordText -> PMCommand p)
-> Maybe PasswordText -> p -> PMCommand p
forall a b c. (a -> b -> c) -> b -> a -> c
flip p -> Maybe PasswordText -> PMCommand p
forall p. p -> Maybe PasswordText -> PMCommand p
PMCD_load Maybe PasswordText
op_p) ((PasswordName -> Maybe PasswordText -> PMCommand p)
-> Maybe PasswordText -> PasswordName -> PMCommand p
forall a b c. (a -> b -> c) -> b -> a -> c
flip PasswordName -> Maybe PasswordText -> PMCommand p
forall p. PasswordName -> Maybe PasswordText -> PMCommand p
PMCD_load_plus Maybe PasswordText
op_p) Either p PasswordName
ei
p_delete_password :: PMConfig p -> Parser (PMCommand p)
p_delete_password PMConfig p
pmc = (p -> PMCommand p)
-> (PasswordName -> PMCommand p)
-> Either p PasswordName
-> PMCommand p
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either p -> PMCommand p
forall p. p -> PMCommand p
PMCD_delete_password (Maybe PasswordName -> PMCommand p
forall p. Maybe PasswordName -> PMCommand p
PMCD_delete_password_plus (Maybe PasswordName -> PMCommand p)
-> (PasswordName -> Maybe PasswordName)
-> PasswordName
-> PMCommand p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PasswordName -> Maybe PasswordName
forall a. a -> Maybe a
Just) (Either p PasswordName -> PMCommand p)
-> Parser (Either p PasswordName) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PMConfig p -> Parser (Either p PasswordName)
forall p. PW p => PMConfig p -> Parser (Either p PasswordName)
p_pw PMConfig p
pmc
p_info :: PMConfig p -> Parser (PMCommand p)
p_info PMConfig p
pmc = Bool -> Either p PasswordName -> PMCommand p
forall p. Bool -> Either p PasswordName -> PMCommand p
f (Bool -> Either p PasswordName -> PMCommand p)
-> Parser Bool -> Parser (Either p PasswordName -> PMCommand p)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser Bool
p_secret_sw Parser (Either p PasswordName -> PMCommand p)
-> Parser (Either p PasswordName) -> Parser (PMCommand p)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> PMConfig p -> Parser (Either p PasswordName)
forall p. PW p => PMConfig p -> Parser (Either p PasswordName)
p_pw PMConfig p
pmc
where
f :: Bool -> Either p PasswordName -> PMCommand p
f Bool
s_sw (Left p
p ) = Bool -> p -> PMCommand p
forall p. Bool -> p -> PMCommand p
PMCD_info Bool
s_sw p
p
f Bool
s_sw (Right PasswordName
pnm) = Bool -> PasswordName -> PMCommand p
forall p. Bool -> PasswordName -> PMCommand p
PMCD_info_plus Bool
s_sw PasswordName
pnm
p_brief_sw :: Parser Bool
p_brief_sw :: Parser Bool
p_brief_sw =
Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'b' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"brief" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"list the identifiers only")
p_loop_sw :: Parser Bool
p_loop_sw :: Parser Bool
p_loop_sw =
Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'l' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"loop" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"on failure prompt for a new password and try again")
p_no_login_sw :: Parser Bool
p_no_login_sw :: Parser Bool
p_no_login_sw =
Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'n' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"no-login" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"do not launch an interactive shell")
p_quiet_sw :: Parser Bool
p_quiet_sw :: Parser Bool
p_quiet_sw =
Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'q' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"quiet" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"don't print anything but report with error codes (0=>logged in)")
p_secret_sw :: Parser Bool
p_secret_sw :: Parser Bool
p_secret_sw =
Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
's' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"secret" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"show the secret password")
p_sessions_sw :: Parser Bool
p_sessions_sw :: Parser Bool
p_sessions_sw =
Mod FlagFields Bool -> Parser Bool
switch
(FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"sessions" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"include the sessions")
p_unprime_sw :: Parser Bool
p_unprime_sw :: Parser Bool
p_unprime_sw =
Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'u' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"unprime" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"clear the prime status")
p_x_pps :: Parser Bool
p_x_pps :: Parser Bool
p_x_pps =
Mod FlagFields Bool -> Parser Bool
switch
(Char -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'x' Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"exclude-plus-passwords" Mod FlagFields Bool -> Mod FlagFields Bool -> Mod FlagFields Bool
forall a. Semigroup a => a -> a -> a
<>
FilePath -> Mod FlagFields Bool
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"exclude the dynamic (plus) passwords")
p_pw_id_opt :: PW p => Parser p
p_pw_id_opt :: Parser p
p_pw_id_opt =
ReadM p -> Mod OptionFields p -> Parser p
forall a. ReadM a -> Mod OptionFields a -> Parser a
option ((FilePath -> Either FilePath p) -> ReadM p
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((FilePath -> Either FilePath p) -> ReadM p)
-> (FilePath -> Either FilePath p) -> ReadM p
forall a b. (a -> b) -> a -> b
$ Either FilePath p
-> (p -> Either FilePath p) -> Maybe p -> Either FilePath p
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (FilePath -> Either FilePath p
forall a b. a -> Either a b
Left FilePath
"password-id not recognised") p -> Either FilePath p
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe p -> Either FilePath p)
-> (FilePath -> Maybe p) -> FilePath -> Either FilePath p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PasswordName -> Maybe p
forall p. PW p => PasswordName -> Maybe p
parsePwName (PasswordName -> Maybe p)
-> (FilePath -> PasswordName) -> FilePath -> Maybe p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PasswordName
PasswordName (Text -> PasswordName)
-> (FilePath -> Text) -> FilePath -> PasswordName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
T.pack)
(Mod OptionFields p -> Parser p) -> Mod OptionFields p -> Parser p
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod OptionFields p
forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"id"
Mod OptionFields p -> Mod OptionFields p -> Mod OptionFields p
forall a. Semigroup a => a -> a -> a
<> Char -> Mod OptionFields p
forall (f :: * -> *) a. HasName f => Char -> Mod f a
short Char
'p'
Mod OptionFields p -> Mod OptionFields p -> Mod OptionFields p
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields p
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"PASSWORD-ID"
Mod OptionFields p -> Mod OptionFields p -> Mod OptionFields p
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod OptionFields p
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"a password ID"
p_comment :: Parser String
= [FilePath] -> FilePath
unwords ([FilePath] -> FilePath) -> Parser [FilePath] -> Parser FilePath
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FilePath -> Parser [FilePath]
forall (f :: * -> *) a. Alternative f => f a -> f [a]
many Parser FilePath
p_word
p_hash :: Parser ()
p_hash :: Parser ()
p_hash = ReadM () -> Mod ArgumentFields () -> Parser ()
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ((FilePath -> Either FilePath ()) -> ReadM ()
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((FilePath -> Either FilePath ()) -> ReadM ())
-> (FilePath -> Either FilePath ()) -> ReadM ()
forall a b. (a -> b) -> a -> b
$ \FilePath
s->if FilePath
sFilePath -> FilePath -> Bool
forall a. Eq a => a -> a -> Bool
==FilePath
"#" then () -> Either FilePath ()
forall (m :: * -> *) a. Monad m => a -> m a
return () else FilePath -> Either FilePath ()
forall a b. a -> Either a b
Left FilePath
"# expected") (Mod ArgumentFields () -> Parser ())
-> Mod ArgumentFields () -> Parser ()
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod ArgumentFields ()
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"#"
h_info :: Parser a -> InfoMod a -> ParserInfo a
h_info :: Parser a -> InfoMod a -> ParserInfo a
h_info Parser a
pr = Parser a -> InfoMod a -> ParserInfo a
forall a. Parser a -> InfoMod a -> ParserInfo a
O.info (Parser (a -> a)
forall a. Parser (a -> a)
helper Parser (a -> a) -> Parser a -> Parser a
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Parser a
pr)
p_load_comment :: Parser ()
= () -> Maybe () -> ()
forall a b. a -> b -> a
const () (Maybe () -> ()) -> Parser (Maybe ()) -> Parser ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser () -> Parser (Maybe ())
forall (f :: * -> *) a. Alternative f => f a -> f (Maybe a)
optional (Parser ()
p_hash Parser () -> Parser FilePath -> Parser ()
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* Parser FilePath
p_comment)
p_password_text :: PW p => Bool -> PMConfig p -> Parser PasswordText
p_password_text :: Bool -> PMConfig p -> Parser PasswordText
p_password_text Bool
hp PMConfig p
pmc =
ReadM PasswordText
-> Mod ArgumentFields PasswordText -> Parser PasswordText
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ((FilePath -> Either FilePath PasswordText) -> ReadM PasswordText
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((FilePath -> Either FilePath PasswordText) -> ReadM PasswordText)
-> (FilePath -> Either FilePath PasswordText) -> ReadM PasswordText
forall a b. (a -> b) -> a -> b
$ PasswordText -> Either FilePath PasswordText
forall a b. b -> Either a b
Right (PasswordText -> Either FilePath PasswordText)
-> (FilePath -> PasswordText)
-> FilePath
-> Either FilePath PasswordText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> PMConfig p -> FilePath -> PasswordText
forall p. PW p => Bool -> PMConfig p -> FilePath -> PasswordText
cond_hash Bool
hp PMConfig p
pmc)
(Mod ArgumentFields PasswordText -> Parser PasswordText)
-> Mod ArgumentFields PasswordText -> Parser PasswordText
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod ArgumentFields PasswordText
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"PASSWORD-TEXT"
Mod ArgumentFields PasswordText
-> Mod ArgumentFields PasswordText
-> Mod ArgumentFields PasswordText
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod ArgumentFields PasswordText
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"the text of the password"
p_pw :: PW p => PMConfig p -> Parser (Either p PasswordName)
p_pw :: PMConfig p -> Parser (Either p PasswordName)
p_pw PMConfig p
pmc =
ReadM (Either p PasswordName)
-> Mod ArgumentFields (Either p PasswordName)
-> Parser (Either p PasswordName)
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ((FilePath -> Either FilePath (Either p PasswordName))
-> ReadM (Either p PasswordName)
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((FilePath -> Either FilePath (Either p PasswordName))
-> ReadM (Either p PasswordName))
-> (FilePath -> Either FilePath (Either p PasswordName))
-> ReadM (Either p PasswordName)
forall a b. (a -> b) -> a -> b
$ Either FilePath (Either p PasswordName)
-> (Either p PasswordName
-> Either FilePath (Either p PasswordName))
-> Maybe (Either p PasswordName)
-> Either FilePath (Either p PasswordName)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (FilePath -> Either FilePath (Either p PasswordName)
forall a b. a -> Either a b
Left FilePath
"bad password syntax") Either p PasswordName -> Either FilePath (Either p PasswordName)
forall a b. b -> Either a b
Right (Maybe (Either p PasswordName)
-> Either FilePath (Either p PasswordName))
-> (FilePath -> Maybe (Either p PasswordName))
-> FilePath
-> Either FilePath (Either p PasswordName)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Maybe (Either p PasswordName)
forall a. PW a => FilePath -> Maybe (Either a PasswordName)
prs)
(Mod ArgumentFields (Either p PasswordName)
-> Parser (Either p PasswordName))
-> Mod ArgumentFields (Either p PasswordName)
-> Parser (Either p PasswordName)
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod ArgumentFields (Either p PasswordName)
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"PASSWORD"
Mod ArgumentFields (Either p PasswordName)
-> Mod ArgumentFields (Either p PasswordName)
-> Mod ArgumentFields (Either p PasswordName)
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod ArgumentFields (Either p PasswordName)
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"a static or dynamic (+) password name"
where
prs :: FilePath -> Maybe (Either a PasswordName)
prs FilePath
s =
a -> Either a PasswordName
forall a b. a -> Either a b
Left (a -> Either a PasswordName)
-> Maybe a -> Maybe (Either a PasswordName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (PasswordName -> Maybe a
forall p. PW p => PasswordName -> Maybe p
parsePwName (PasswordName -> Maybe a) -> PasswordName -> Maybe a
forall a b. (a -> b) -> a -> b
$ Text -> PasswordName
PasswordName (Text -> PasswordName) -> Text -> PasswordName
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack FilePath
s) Maybe (Either a PasswordName)
-> Maybe (Either a PasswordName) -> Maybe (Either a PasswordName)
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|>
PasswordName -> Either a PasswordName
forall a b. b -> Either a b
Right (PasswordName -> Either a PasswordName)
-> Maybe PasswordName -> Maybe (Either a PasswordName)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (PMConfig p -> FilePath -> Maybe PasswordName
forall p. PW p => PMConfig p -> FilePath -> Maybe PasswordName
parse_plus_pw PMConfig p
pmc FilePath
s)
p_pw_id :: PW p => Parser p
p_pw_id :: Parser p
p_pw_id =
ReadM p -> Mod ArgumentFields p -> Parser p
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ((FilePath -> Either FilePath p) -> ReadM p
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((FilePath -> Either FilePath p) -> ReadM p)
-> (FilePath -> Either FilePath p) -> ReadM p
forall a b. (a -> b) -> a -> b
$ Either FilePath p
-> (p -> Either FilePath p) -> Maybe p -> Either FilePath p
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (FilePath -> Either FilePath p
forall a b. a -> Either a b
Left FilePath
"bad password syntax") p -> Either FilePath p
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe p -> Either FilePath p)
-> (FilePath -> Maybe p) -> FilePath -> Either FilePath p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PasswordName -> Maybe p
forall p. PW p => PasswordName -> Maybe p
parsePwName (PasswordName -> Maybe p)
-> (FilePath -> PasswordName) -> FilePath -> Maybe p
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PasswordName
PasswordName (Text -> PasswordName)
-> (FilePath -> Text) -> FilePath -> PasswordName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
T.pack)
(Mod ArgumentFields p -> Parser p)
-> Mod ArgumentFields p -> Parser p
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod ArgumentFields p
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"PASSWORD-ID"
Mod ArgumentFields p
-> Mod ArgumentFields p -> Mod ArgumentFields p
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod ArgumentFields p
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"a password ID"
p_ps_comment :: Parser PasswordStoreComment
= Text -> PasswordStoreComment
PasswordStoreComment (Text -> PasswordStoreComment)
-> (FilePath -> Text) -> FilePath -> PasswordStoreComment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
T.pack (FilePath -> PasswordStoreComment)
-> Parser FilePath -> Parser PasswordStoreComment
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Parser FilePath
p_comment
p_session_name :: Parser SessionName
p_session_name :: Parser SessionName
p_session_name =
ReadM SessionName
-> Mod ArgumentFields SessionName -> Parser SessionName
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ((FilePath -> Either FilePath SessionName) -> ReadM SessionName
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader ((FilePath -> Either FilePath SessionName) -> ReadM SessionName)
-> (FilePath -> Either FilePath SessionName) -> ReadM SessionName
forall a b. (a -> b) -> a -> b
$ SessionName -> Either FilePath SessionName
forall a b. b -> Either a b
Right (SessionName -> Either FilePath SessionName)
-> (FilePath -> SessionName)
-> FilePath
-> Either FilePath SessionName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> SessionName
SessionName (Text -> SessionName)
-> (FilePath -> Text) -> FilePath -> SessionName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Text
T.pack)
(Mod ArgumentFields SessionName -> Parser SessionName)
-> Mod ArgumentFields SessionName -> Parser SessionName
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod ArgumentFields SessionName
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"SESSION"
Mod ArgumentFields SessionName
-> Mod ArgumentFields SessionName -> Mod ArgumentFields SessionName
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod ArgumentFields SessionName
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"a session name"
p_store_fp :: Parser FilePath
p_store_fp :: Parser FilePath
p_store_fp =
ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ((FilePath -> Either FilePath FilePath) -> ReadM FilePath
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader FilePath -> Either FilePath FilePath
forall a b. b -> Either a b
Right)
(Mod ArgumentFields FilePath -> Parser FilePath)
-> Mod ArgumentFields FilePath -> Parser FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"STORE"
Mod ArgumentFields FilePath
-> Mod ArgumentFields FilePath -> Mod ArgumentFields FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"file containing the password store to import"
p_word :: Parser String
p_word :: Parser FilePath
p_word = ReadM FilePath -> Mod ArgumentFields FilePath -> Parser FilePath
forall a. ReadM a -> Mod ArgumentFields a -> Parser a
argument ((FilePath -> Either FilePath FilePath) -> ReadM FilePath
forall a. (FilePath -> Either FilePath a) -> ReadM a
eitherReader FilePath -> Either FilePath FilePath
forall a b. b -> Either a b
Right) (Mod ArgumentFields FilePath -> Parser FilePath)
-> Mod ArgumentFields FilePath -> Parser FilePath
forall a b. (a -> b) -> a -> b
$ FilePath -> Mod ArgumentFields FilePath
forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"WORD"
run_parse :: ParserInfo a -> [String] -> IO a
run_parse :: ParserInfo a -> [FilePath] -> IO a
run_parse ParserInfo a
pinfo [FilePath]
args =
case ParserPrefs -> ParserInfo a -> [FilePath] -> ParserResult a
forall a.
ParserPrefs -> ParserInfo a -> [FilePath] -> ParserResult a
execParserPure (PrefsMod -> ParserPrefs
prefs PrefsMod
forall m. Monoid m => m
idm) ParserInfo a
pinfo [FilePath]
args of
Success a
a -> a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return a
a
Failure ParserFailure ParserHelp
failure -> do
FilePath
progn <- IO FilePath
E.getProgName
let (ParserHelp
msg, ExitCode
exit, Int
_) = ParserFailure ParserHelp -> FilePath -> (ParserHelp, ExitCode, Int)
forall h. ParserFailure h -> FilePath -> (h, ExitCode, Int)
execFailure ParserFailure ParserHelp
failure FilePath
progn
case ExitCode
exit of
ExitCode
ExitSuccess -> FilePath -> IO ()
putStrLn (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ ParserHelp -> FilePath
forall a. Show a => a -> FilePath
show ParserHelp
msg
ExitCode
_ -> Handle -> FilePath -> IO ()
hPutStrLn Handle
stderr (FilePath -> IO ()) -> FilePath -> IO ()
forall a b. (a -> b) -> a -> b
$ ParserHelp -> FilePath
forall a. Show a => a -> FilePath
show ParserHelp
msg
ExitCode -> IO a
forall a. ExitCode -> IO a
exitWith ExitCode
exit
CompletionInvoked CompletionResult
compl -> do
FilePath
progn <- IO FilePath
E.getProgName
FilePath
msg <- CompletionResult -> FilePath -> IO FilePath
execCompletion CompletionResult
compl FilePath
progn
FilePath -> IO ()
putStr FilePath
msg
ExitCode -> IO a
forall a. ExitCode -> IO a
exitWith ExitCode
ExitSuccess
parse_plus_pw :: PW p => PMConfig p -> String -> Maybe PasswordName
parse_plus_pw :: PMConfig p -> FilePath -> Maybe PasswordName
parse_plus_pw PMConfig p
pmc FilePath
s_ = case FilePath
s_ of
Char
'+':FilePath
s | Maybe EnvVar -> Bool
forall a. Maybe a -> Bool
isJust (Maybe EnvVar -> Bool) -> Maybe EnvVar -> Bool
forall a b. (a -> b) -> a -> b
$ PMConfig p -> PasswordName -> Maybe EnvVar
forall p. PMConfig p -> PasswordName -> Maybe EnvVar
_pmc_plus_env_var PMConfig p
pmc PasswordName
pnm
-> PasswordName -> Maybe PasswordName
forall a. a -> Maybe a
Just PasswordName
pnm
where
pnm :: PasswordName
pnm = Text -> PasswordName
PasswordName (Text -> PasswordName) -> Text -> PasswordName
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack FilePath
s
FilePath
_ -> Maybe PasswordName
forall a. Maybe a
Nothing
plussify :: PasswordName -> PasswordName
plussify :: PasswordName -> PasswordName
plussify = Text -> PasswordName
PasswordName (Text -> PasswordName)
-> (PasswordName -> Text) -> PasswordName -> PasswordName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Text -> Text
T.cons Char
'+') (Text -> Text) -> (PasswordName -> Text) -> PasswordName -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PasswordName -> Text
_PasswordName
is_plus :: PasswordName -> Maybe PasswordName
is_plus :: PasswordName -> Maybe PasswordName
is_plus PasswordName
pnm = case Text -> FilePath
T.unpack (Text -> FilePath) -> Text -> FilePath
forall a b. (a -> b) -> a -> b
$ PasswordName -> Text
_PasswordName PasswordName
pnm of
Char
'+':FilePath
s -> PasswordName -> Maybe PasswordName
forall a. a -> Maybe a
Just (PasswordName -> Maybe PasswordName)
-> PasswordName -> Maybe PasswordName
forall a b. (a -> b) -> a -> b
$ Text -> PasswordName
PasswordName (Text -> PasswordName) -> Text -> PasswordName
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack FilePath
s
FilePath
_ -> Maybe PasswordName
forall a. Maybe a
Nothing