To enable an existing special remote, the new enableremote command must be used. The initremote command now is used only to create new special remotes.
This commit is contained in:
parent
9a24728d95
commit
85d83e7756
14 changed files with 141 additions and 52 deletions
|
@ -69,17 +69,22 @@ makeRsyncRemote name location = makeRemote name location $
|
|||
, ("type", "rsync")
|
||||
]
|
||||
|
||||
{- Inits a special remote. Currently, only 'weak' ciphers can be
|
||||
- generated from the assistant, because otherwise GnuPG may block once
|
||||
- the entropy pool is drained, and as of now there's no way to tell the
|
||||
- user to perform IO actions to refill the pool. -}
|
||||
{- Inits a new special remote, or enables an existing one.
|
||||
-
|
||||
- Currently, only 'weak' ciphers can be generated from the assistant,
|
||||
- because otherwise GnuPG may block once the entropy pool is drained,
|
||||
- and as of now there's no way to tell the user to perform IO actions
|
||||
- to refill the pool. -}
|
||||
makeSpecialRemote :: String -> RemoteType -> R.RemoteConfig -> Annex ()
|
||||
makeSpecialRemote name remotetype config = do
|
||||
(u, c) <- Command.InitRemote.findByName name
|
||||
c' <- R.setup remotetype u $
|
||||
M.insert "highRandomQuality" "false" $ M.union config c
|
||||
describeUUID u name
|
||||
configSet u c'
|
||||
makeSpecialRemote name remotetype config =
|
||||
go =<< Command.InitRemote.findExisting name
|
||||
where
|
||||
go Nothing = go =<< Just <$> Command.InitRemote.generateNew name
|
||||
go (Just (u, c)) = do
|
||||
c' <- R.setup remotetype u $
|
||||
M.insert "highRandomQuality" "false" $ M.union config c
|
||||
describeUUID u name
|
||||
configSet u c'
|
||||
|
||||
{- Returns the name of the git remote it created. If there's already a
|
||||
- remote at the location, returns its name. -}
|
||||
|
|
56
Command/EnableRemote.hs
Normal file
56
Command/EnableRemote.hs
Normal file
|
@ -0,0 +1,56 @@
|
|||
{- git-annex command
|
||||
-
|
||||
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
module Command.EnableRemote where
|
||||
|
||||
import Common.Annex
|
||||
import Command
|
||||
import qualified Logs.Remote
|
||||
import qualified Types.Remote as R
|
||||
import qualified Command.InitRemote as InitRemote
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
def :: [Command]
|
||||
def = [command "enableremote"
|
||||
(paramPair paramName $ paramOptional $ paramRepeating paramKeyValue)
|
||||
seek SectionSetup "enables use of an existing special remote"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withWords start]
|
||||
|
||||
start :: [String] -> CommandStart
|
||||
start [] = unknownNameError "Specify the name of the special remote to enable."
|
||||
start (name:ws) = go =<< InitRemote.findExisting name
|
||||
where
|
||||
config = Logs.Remote.keyValToConfig ws
|
||||
|
||||
go Nothing = unknownNameError "Unknown special remote name."
|
||||
go (Just (u, c)) = do
|
||||
let fullconfig = config `M.union` c
|
||||
t <- InitRemote.findType fullconfig
|
||||
|
||||
showStart "enableremote" name
|
||||
next $ perform t u fullconfig
|
||||
|
||||
unknownNameError :: String -> Annex a
|
||||
unknownNameError prefix = do
|
||||
names <- InitRemote.remoteNames
|
||||
error $ prefix ++
|
||||
if null names
|
||||
then ""
|
||||
else " Known special remotes: " ++ intercalate " " names
|
||||
|
||||
perform :: RemoteType -> UUID -> R.RemoteConfig -> CommandPerform
|
||||
perform t u c = do
|
||||
c' <- R.setup t u c
|
||||
next $ cleanup u c'
|
||||
|
||||
cleanup :: UUID -> R.RemoteConfig -> CommandCleanup
|
||||
cleanup u c = do
|
||||
Logs.Remote.configSet u c
|
||||
return True
|
|
@ -1,6 +1,6 @@
|
|||
{- git-annex command
|
||||
-
|
||||
- Copyright 2011 Joey Hess <joey@kitenet.net>
|
||||
- Copyright 2011,2013 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
@ -23,26 +23,23 @@ import Data.Ord
|
|||
def :: [Command]
|
||||
def = [command "initremote"
|
||||
(paramPair paramName $ paramOptional $ paramRepeating paramKeyValue)
|
||||
seek SectionSetup "sets up a special (non-git) remote"]
|
||||
seek SectionSetup "creates a special (non-git) remote"]
|
||||
|
||||
seek :: [CommandSeek]
|
||||
seek = [withWords start]
|
||||
|
||||
start :: [String] -> CommandStart
|
||||
start [] = do
|
||||
names <- remoteNames
|
||||
error $ "Specify a name for the remote. " ++
|
||||
if null names
|
||||
then ""
|
||||
else "Either a new name, or one of these existing special remotes: " ++ intercalate " " names
|
||||
start (name:ws) = do
|
||||
(u, c) <- findByName name
|
||||
let fullconfig = config `M.union` c
|
||||
t <- findType fullconfig
|
||||
|
||||
showStart "initremote" name
|
||||
next $ perform t u name $ M.union config c
|
||||
start [] = error "Specify a name for the remote."
|
||||
start (name:ws) = ifM (isJust <$> findExisting name)
|
||||
( error $ "There is already a special remote named \"" ++ name ++
|
||||
"\". (Use enableremote to enable an existing special remote.)"
|
||||
, do
|
||||
(u, c) <- generateNew name
|
||||
t <- findType config
|
||||
|
||||
showStart "initremote" name
|
||||
next $ perform t u name $ M.union config c
|
||||
)
|
||||
where
|
||||
config = Logs.Remote.keyValToConfig ws
|
||||
|
||||
|
@ -57,21 +54,22 @@ cleanup u name c = do
|
|||
Logs.Remote.configSet u c
|
||||
return True
|
||||
|
||||
{- Look up existing remote's UUID and config by name, or generate a new one -}
|
||||
findByName :: String -> Annex (UUID, R.RemoteConfig)
|
||||
findByName name = do
|
||||
{- See if there's an existing special remote with this name. -}
|
||||
findExisting :: String -> Annex (Maybe (UUID, R.RemoteConfig))
|
||||
findExisting name = do
|
||||
t <- trustMap
|
||||
matches <- sortBy (comparing $ \(u, _c) -> M.lookup u t )
|
||||
. findByName' name
|
||||
. findByName name
|
||||
<$> Logs.Remote.readRemoteLog
|
||||
maybe generate return $ headMaybe matches
|
||||
where
|
||||
generate = do
|
||||
uuid <- liftIO genUUID
|
||||
return (uuid, M.insert nameKey name M.empty)
|
||||
return $ headMaybe matches
|
||||
|
||||
findByName' :: String -> M.Map UUID R.RemoteConfig -> [(UUID, R.RemoteConfig)]
|
||||
findByName' n = filter (matching . snd) . M.toList
|
||||
generateNew :: String -> Annex (UUID, R.RemoteConfig)
|
||||
generateNew name = do
|
||||
uuid <- liftIO genUUID
|
||||
return (uuid, M.singleton nameKey name)
|
||||
|
||||
findByName :: String -> M.Map UUID R.RemoteConfig -> [(UUID, R.RemoteConfig)]
|
||||
findByName n = filter (matching . snd) . M.toList
|
||||
where
|
||||
matching c = case M.lookup nameKey c of
|
||||
Nothing -> False
|
||||
|
|
|
@ -30,6 +30,7 @@ import qualified Command.Fix
|
|||
import qualified Command.Init
|
||||
import qualified Command.Describe
|
||||
import qualified Command.InitRemote
|
||||
import qualified Command.EnableRemote
|
||||
import qualified Command.Fsck
|
||||
import qualified Command.Unused
|
||||
import qualified Command.DropUnused
|
||||
|
@ -91,6 +92,7 @@ cmds = concat
|
|||
, Command.Init.def
|
||||
, Command.Describe.def
|
||||
, Command.InitRemote.def
|
||||
, Command.EnableRemote.def
|
||||
, Command.Reinject.def
|
||||
, Command.Unannex.def
|
||||
, Command.Uninit.def
|
||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -40,6 +40,9 @@ git-annex (4.20130418) UNRELEASED; urgency=low
|
|||
its edit page.
|
||||
* Automatically register public urls for files uploaded to the
|
||||
Internet Archive.
|
||||
* To enable an existing special remote, the new enableremote command
|
||||
must be used. The initremote command now is used only to create
|
||||
new special remotes.
|
||||
|
||||
-- Joey Hess <joeyh@debian.org> Thu, 18 Apr 2013 16:22:48 -0400
|
||||
|
||||
|
|
|
@ -31,10 +31,10 @@ non-empty remote.
|
|||
The [[encryption_design|design/encryption]] allows additional encryption keys
|
||||
to be added on to a special remote later. Once a key is added, it is able
|
||||
to access content that has already been stored in the special remote.
|
||||
To add a new key, just run `git annex initremote` again, specifying the
|
||||
To add a new key, just run `git annex enableremote` specifying the
|
||||
new encryption key:
|
||||
|
||||
git annex initremote myremote encryption=788A3F4C
|
||||
git annex enableremote myremote encryption=788A3F4C
|
||||
|
||||
Note that once a key has been given access to a remote, it's not
|
||||
possible to revoke that access, short of deleting the remote. See
|
||||
|
|
|
@ -236,15 +236,40 @@ subdirectories).
|
|||
|
||||
* initremote name [param=value ...]
|
||||
|
||||
Sets up a special remote. The remote's
|
||||
configuration is specified by the parameters. If a remote
|
||||
with the specified name has already been configured, its configuration
|
||||
is modified by any values specified. In either case, the remote will be
|
||||
added to `.git/config`.
|
||||
Creates a new special remote, and adds it to `.git/config`.
|
||||
|
||||
The remote's configuration is specified by the parameters. Different
|
||||
types of special remotes need different configuration values. The
|
||||
command will prompt for parameters as needed.
|
||||
|
||||
All special remotes support encryption. You must either specify
|
||||
encryption=none to disable encryption, or use encryption=keyid
|
||||
(or encryption=emailaddress) to specify a gpg key that can access
|
||||
the encrypted special remote.
|
||||
|
||||
Example Amazon S3 remote:
|
||||
|
||||
initremote mys3 type=S3 encryption=none datacenter=EU
|
||||
git annex initremote mys3 type=S3 encryption=me@example.com datacenter=EU
|
||||
|
||||
* enableremote name [param=value ...]
|
||||
|
||||
Enables use of an existing special remote in the current repository,
|
||||
which may be a different repository than the one in which it was
|
||||
originally created with the initremote command.
|
||||
|
||||
The name of the remote is the same name used when origianlly
|
||||
creating that remote with "initremote". Run "git annex enableremote"
|
||||
with no parameters to get a list of special remote names.
|
||||
|
||||
Some special remotes may need parameters to be specified every time.
|
||||
For example, the directory special remote requires a directory= parameter.
|
||||
|
||||
This command can also be used to modify the configuration of an existing
|
||||
special remote, by specifying new values for parameters that were originally
|
||||
set when using initremote. For example, to add a new gpg key to the keys
|
||||
that can access an encrypted remote:
|
||||
|
||||
git annex initremote mys3 encryption=friend@example.com
|
||||
|
||||
* trust [repository ...]
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ the S3 remote.
|
|||
every clone of the repository to access the encrypted data (use with caution).
|
||||
|
||||
Note that additional gpg keys can be given access to a remote by
|
||||
rerunning initremote with the new key id. See [[encryption]].
|
||||
running enableremote with the new key id. See [[encryption]].
|
||||
|
||||
* `embedcreds` - Optional. Set to "yes" embed the login credentials inside
|
||||
the git repository, which allows other clones to also access them. This is
|
||||
|
|
|
@ -26,7 +26,7 @@ These parameters can be passed to `git annex initremote` to configure bup:
|
|||
every clone of the repository to access the encrypted data (use with caution).
|
||||
|
||||
Note that additional gpg keys can be given access to a remote by
|
||||
rerunning initremote with the new key id. See [[encryption]].
|
||||
running enableremote with the new key id. See [[encryption]].
|
||||
|
||||
* `buprepo` - Required. This is passed to `bup` as the `--remote`
|
||||
to use to store data. To create the repository,`bup init` will be run.
|
||||
|
|
|
@ -16,7 +16,7 @@ remote:
|
|||
every clone of the repository to decrypt the encrypted data.
|
||||
|
||||
Note that additional gpg keys can be given access to a remote by
|
||||
rerunning initremote with the new key id. See [[encryption]].
|
||||
running enableremote with the new key id. See [[encryption]].
|
||||
|
||||
* `chunksize` - Avoid storing files larger than the specified size in the
|
||||
directory. For use on directories on mount points that have file size
|
||||
|
|
|
@ -27,7 +27,7 @@ the Glacier remote.
|
|||
every clone of the repository to access the encrypted data (use with caution).
|
||||
|
||||
Note that additional gpg keys can be given access to a remote by
|
||||
rerunning initremote with the new key id. See [[encryption]].
|
||||
running enableremote with the new key id. See [[encryption]].
|
||||
|
||||
* `embedcreds` - Optional. Set to "yes" embed the login credentials inside
|
||||
the git repository, which allows other clones to also access them. This is
|
||||
|
|
|
@ -31,7 +31,7 @@ These parameters can be passed to `git annex initremote`:
|
|||
every clone of the repository to access the encrypted data.
|
||||
|
||||
Note that additional gpg keys can be given access to a remote by
|
||||
rerunning initremote with the new key id. See [[encryption]].
|
||||
running enableremote with the new key id. See [[encryption]].
|
||||
|
||||
* `hooktype` - Required. This specifies a collection of hooks to use for
|
||||
this remote.
|
||||
|
|
|
@ -21,7 +21,7 @@ These parameters can be passed to `git annex initremote` to configure rsync:
|
|||
every clone of the repository to decrypt the encrypted data.
|
||||
|
||||
Note that additional gpg keys can be given access to a remote by
|
||||
rerunning initremote with the new key id. See [[encryption]].
|
||||
running enableremote with the new key id. See [[encryption]].
|
||||
|
||||
* `rsyncurl` - Required. This is the url or `hostname:/directory` to
|
||||
pass to rsync to tell it where to store content.
|
||||
|
@ -31,7 +31,7 @@ These parameters can be passed to `git annex initremote` to configure rsync:
|
|||
setups, but not with some hosting providers that do not expose rsynced
|
||||
filenames to the shell. You'll know you need this option if `git annex get`
|
||||
from the special remote fails with an error message containing a single
|
||||
quote (`'`) character. If that happens, you can re-run initremote
|
||||
quote (`'`) character. If that happens, you can run enableremote
|
||||
setting shellescape=no.
|
||||
|
||||
The `annex-rsync-options` git configuration setting can be used to pass
|
||||
|
|
|
@ -16,7 +16,7 @@ the webdav remote.
|
|||
every clone of the repository to access the encrypted data (use with caution).
|
||||
|
||||
Note that additional gpg keys can be given access to a remote by
|
||||
rerunning initremote with the new key id. See [[encryption]].
|
||||
running enableremote with the new key id. See [[encryption]].
|
||||
|
||||
* `embedcreds` - Optional. Set to "yes" embed the login credentials inside
|
||||
the git repository, which allows other clones to also access them. This is
|
||||
|
|
Loading…
Reference in a new issue