Merge pull request #34 from ozkutuk/add-password-file
Add `--userPasswordFile` option to migration utility
This commit is contained in:
commit
ade826d826
|
@ -12,12 +12,42 @@ import ClassyPrelude
|
|||
import Lens.Micro
|
||||
|
||||
import Options.Generic
|
||||
import qualified Options.Applicative as OA
|
||||
import qualified Data.Text as T
|
||||
|
||||
data Password
|
||||
= PasswordText Text
|
||||
| PasswordFile FilePath
|
||||
deriving (Show, Read)
|
||||
|
||||
parsePassword :: OA.Parser Password
|
||||
parsePassword = passwordText <|> passwordFile
|
||||
where
|
||||
passwordText = PasswordText <$> OA.strOption
|
||||
( OA.long "userPassword"
|
||||
<> OA.metavar "PASSWORD"
|
||||
<> OA.help "Password in plain-text"
|
||||
)
|
||||
|
||||
passwordFile = PasswordFile <$> OA.strOption
|
||||
( OA.long "userPasswordFile"
|
||||
<> OA.metavar "FILE"
|
||||
<> OA.help "Password file"
|
||||
)
|
||||
|
||||
instance ParseFields Password
|
||||
|
||||
instance ParseRecord Password where
|
||||
parseRecord = fmap getOnly parseRecord
|
||||
|
||||
instance ParseField Password where
|
||||
parseField _ _ _ _ = parsePassword
|
||||
|
||||
data MigrationOpts
|
||||
= CreateDB { conn :: Text }
|
||||
| CreateUser { conn :: Text
|
||||
, userName :: Text
|
||||
, userPassword :: Text
|
||||
, userPassword :: Password
|
||||
, privateDefault :: Maybe Bool
|
||||
, archiveDefault :: Maybe Bool
|
||||
, privacyLock :: Maybe Bool }
|
||||
|
@ -54,7 +84,10 @@ main = do
|
|||
|
||||
CreateUser{..} ->
|
||||
P.runSqlite conn $ do
|
||||
hash' <- liftIO (hashPassword userPassword)
|
||||
passwordText <- liftIO . fmap T.strip $ case userPassword of
|
||||
PasswordText s -> pure s
|
||||
PasswordFile f -> readFileUtf8 f
|
||||
hash' <- liftIO (hashPassword passwordText)
|
||||
void $ P.upsertBy
|
||||
(UniqueUserName userName)
|
||||
(User userName hash' Nothing False False False)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
cabal-version: 1.12
|
||||
|
||||
-- This file has been generated from package.yaml by hpack version 0.34.4.
|
||||
-- This file has been generated from package.yaml by hpack version 0.34.6.
|
||||
--
|
||||
-- see: https://github.com/sol/hpack
|
||||
--
|
||||
-- hash: 6176e4be5a9b09fa50173b5bb2f280e5d8bc4c70374c91f1eac67ab03a49426f
|
||||
-- hash: 2d724440a0ea54ad278837400547fc97cde79d5998c51d59b4882db32eeb5372
|
||||
|
||||
name: espial
|
||||
version: 0.0.9
|
||||
|
@ -412,6 +412,7 @@ executable migration
|
|||
, microlens
|
||||
, monad-logger ==0.3.*
|
||||
, mtl
|
||||
, optparse-applicative
|
||||
, optparse-generic >=1.2.3
|
||||
, parser-combinators
|
||||
, persistent >=2.8 && <2.14
|
||||
|
|
|
@ -185,6 +185,7 @@ executables:
|
|||
dependencies:
|
||||
- espial
|
||||
- optparse-generic >= 1.2.3
|
||||
- optparse-applicative
|
||||
|
||||
# Test suite
|
||||
tests:
|
||||
|
|
Loading…
Reference in a new issue