mirror of https://github.com/voidlizard/hbs2
Update command `export`
This commit is contained in:
parent
51597c58cb
commit
67892fca02
|
@ -27,9 +27,9 @@ main = join . customExecParser (prefs showHelpOnError) $
|
||||||
)
|
)
|
||||||
|
|
||||||
pExport = do
|
pExport = do
|
||||||
ref <- strArgument (metavar "HASH-REF")
|
keyfile <- strArgument (metavar "KEIRING-FILE")
|
||||||
kr <- optional $ strOption (short 'k' <> long "keyring" <> metavar "KEYRING-FILE")
|
pure $ runApp WithLog do
|
||||||
pure $ runApp WithLog (runExport kr ref)
|
runExport' keyfile
|
||||||
|
|
||||||
pListRefs = do
|
pListRefs = do
|
||||||
pure $ runApp NoLog runListRefs
|
pure $ runApp NoLog runListRefs
|
||||||
|
|
|
@ -80,6 +80,7 @@ common shared-properties
|
||||||
, prettyprinter-ansi-terminal
|
, prettyprinter-ansi-terminal
|
||||||
, resourcet
|
, resourcet
|
||||||
, safe
|
, safe
|
||||||
|
, saltine
|
||||||
, serialise
|
, serialise
|
||||||
, split
|
, split
|
||||||
, sqlite-simple
|
, sqlite-simple
|
||||||
|
|
|
@ -14,6 +14,7 @@ import HBS2.OrDie
|
||||||
import HBS2.Hash
|
import HBS2.Hash
|
||||||
import HBS2.System.Logger.Simple
|
import HBS2.System.Logger.Simple
|
||||||
import HBS2.Merkle
|
import HBS2.Merkle
|
||||||
|
import HBS2.Net.Proto.Types
|
||||||
import HBS2.Git.Types
|
import HBS2.Git.Types
|
||||||
import HBS2.Net.Proto.Definition()
|
import HBS2.Net.Proto.Definition()
|
||||||
import HBS2.Net.Auth.Credentials hiding (getCredentials)
|
import HBS2.Net.Auth.Credentials hiding (getCredentials)
|
||||||
|
@ -29,6 +30,7 @@ import Control.Monad.Trans.Maybe
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
import Data.Either
|
import Data.Either
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
|
import Crypto.Saltine.Core.Sign qualified as Sign
|
||||||
import Data.ByteString.Lazy.Char8 (ByteString)
|
import Data.ByteString.Lazy.Char8 (ByteString)
|
||||||
import Data.ByteString.Char8 qualified as B8
|
import Data.ByteString.Char8 qualified as B8
|
||||||
import Data.ByteString.Lazy.Char8 qualified as LBS
|
import Data.ByteString.Lazy.Char8 qualified as LBS
|
||||||
|
@ -447,13 +449,28 @@ loadCredentials fp = do
|
||||||
die "keyring not set"
|
die "keyring not set"
|
||||||
|
|
||||||
for_ krOpt $ \fn -> do
|
for_ krOpt $ \fn -> do
|
||||||
krData <- liftIO $ B8.readFile fn
|
(puk, cred) <- loadKeyring fn
|
||||||
cred <- pure (parseCredentials @Schema (AsCredFile krData)) `orDie` "bad keyring file"
|
|
||||||
let puk = view peerSignPk cred
|
|
||||||
trace $ "got creds for" <+> pretty (AsBase58 puk)
|
trace $ "got creds for" <+> pretty (AsBase58 puk)
|
||||||
setCredentials (RefLogKey puk) cred
|
setCredentials (RefLogKey puk) cred
|
||||||
pure ()
|
pure ()
|
||||||
|
|
||||||
|
loadCredentials' ::
|
||||||
|
( MonadIO m
|
||||||
|
, HasRefCredentials m
|
||||||
|
)
|
||||||
|
=> FilePath -> m Sign.PublicKey
|
||||||
|
loadCredentials' fn = do
|
||||||
|
(puk, cred) <- loadKeyring fn
|
||||||
|
trace $ "got creds for" <+> pretty (AsBase58 puk)
|
||||||
|
setCredentials (RefLogKey puk) cred
|
||||||
|
pure puk
|
||||||
|
|
||||||
|
loadKeyring :: (MonadIO m) => FilePath -> m (Sign.PublicKey, PeerCredentials Schema)
|
||||||
|
loadKeyring fn = do
|
||||||
|
krData <- liftIO $ B8.readFile fn
|
||||||
|
cred <- pure (parseCredentials @Schema (AsCredFile krData)) `orDie` "bad keyring file"
|
||||||
|
let puk = view peerSignPk cred
|
||||||
|
pure (puk, cred)
|
||||||
|
|
||||||
green = annotate (color Green)
|
green = annotate (color Green)
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ module HBS2Git.Export
|
||||||
( exportRefDeleted
|
( exportRefDeleted
|
||||||
, exportRefOnly
|
, exportRefOnly
|
||||||
, runExport
|
, runExport
|
||||||
|
, runExport'
|
||||||
, ExportRepoOps
|
, ExportRepoOps
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ import HBS2.System.Logger.Simple
|
||||||
import HBS2.Net.Proto.Definition()
|
import HBS2.Net.Proto.Definition()
|
||||||
import HBS2.Clock
|
import HBS2.Clock
|
||||||
import HBS2.Base58
|
import HBS2.Base58
|
||||||
|
import HBS2.Net.Proto.RefLog
|
||||||
|
|
||||||
import HBS2.Git.Local
|
import HBS2.Git.Local
|
||||||
import HBS2.Git.Local.CLI
|
import HBS2.Git.Local.CLI
|
||||||
|
@ -349,6 +351,8 @@ exportRefOnly _ remote rfrom ref val = do
|
||||||
-- что бы оставить совместимость
|
-- что бы оставить совместимость
|
||||||
pure $ lastMay logz
|
pure $ lastMay logz
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
runExport :: forall m . ( MonadIO m
|
runExport :: forall m . ( MonadIO m
|
||||||
, MonadUnliftIO m
|
, MonadUnliftIO m
|
||||||
, MonadCatch m
|
, MonadCatch m
|
||||||
|
@ -357,8 +361,37 @@ runExport :: forall m . ( MonadIO m
|
||||||
)
|
)
|
||||||
|
|
||||||
=> Maybe FilePath -> RepoRef -> App m ()
|
=> Maybe FilePath -> RepoRef -> App m ()
|
||||||
runExport fp repo = do
|
runExport mfp repo = do
|
||||||
|
loadCredentials (maybeToList mfp)
|
||||||
|
let krf = fromMaybe "keyring-file" mfp & takeFileName
|
||||||
|
runExport'' krf repo
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
runExport' :: forall m . ( MonadIO m
|
||||||
|
, MonadUnliftIO m
|
||||||
|
, MonadCatch m
|
||||||
|
, HasProgress (App m)
|
||||||
|
, MonadMask (App m)
|
||||||
|
)
|
||||||
|
|
||||||
|
=> FilePath -> App m ()
|
||||||
|
|
||||||
|
runExport' fp = do
|
||||||
|
repo <- loadCredentials' fp
|
||||||
|
runExport'' (takeFileName fp) (RefLogKey repo)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
runExport'' :: forall m . ( MonadIO m
|
||||||
|
, MonadUnliftIO m
|
||||||
|
, MonadCatch m
|
||||||
|
, HasProgress (App m)
|
||||||
|
, MonadMask (App m)
|
||||||
|
)
|
||||||
|
|
||||||
|
=> FilePath -> RepoRef -> App m ()
|
||||||
|
runExport'' krf repo = do
|
||||||
|
|
||||||
liftIO $ putDoc $
|
liftIO $ putDoc $
|
||||||
line
|
line
|
||||||
|
@ -371,8 +404,6 @@ runExport fp repo = do
|
||||||
|
|
||||||
trace $ "git directory is" <+> pretty git
|
trace $ "git directory is" <+> pretty git
|
||||||
|
|
||||||
loadCredentials (maybeToList fp)
|
|
||||||
|
|
||||||
-- FIXME: wtf-runExport
|
-- FIXME: wtf-runExport
|
||||||
branchesGr <- cfgValue @ConfBranch <&> Set.map normalizeRef
|
branchesGr <- cfgValue @ConfBranch <&> Set.map normalizeRef
|
||||||
|
|
||||||
|
@ -404,7 +435,6 @@ runExport fp repo = do
|
||||||
|
|
||||||
cwd <- liftIO getCurrentDirectory
|
cwd <- liftIO getCurrentDirectory
|
||||||
cfgPath <- configPath cwd
|
cfgPath <- configPath cwd
|
||||||
let krf = fromMaybe "keyring-file" fp & takeFileName
|
|
||||||
|
|
||||||
liftIO $ putStrLn ""
|
liftIO $ putStrLn ""
|
||||||
liftIO $ putDoc $
|
liftIO $ putDoc $
|
||||||
|
|
Loading…
Reference in New Issue