include creds location in info
This is intended to let the user easily tell if a remote's creds are coming from info embedded in the repository, or instead from the environment, or perhaps are locally stored in a creds file. This commit was sponsored by Frédéric Schütz.
This commit is contained in:
parent
a0297915c1
commit
9280fe4cbe
3 changed files with 30 additions and 5 deletions
29
Creds.hs
29
Creds.hs
|
@ -15,6 +15,7 @@ module Creds (
|
||||||
writeCacheCreds,
|
writeCacheCreds,
|
||||||
readCacheCreds,
|
readCacheCreds,
|
||||||
removeCreds,
|
removeCreds,
|
||||||
|
includeCredsInfo,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
|
@ -144,10 +145,16 @@ readCacheCredPair storage = maybe Nothing decodeCredPair
|
||||||
<$> readCacheCreds (credPairFile storage)
|
<$> readCacheCreds (credPairFile storage)
|
||||||
|
|
||||||
readCacheCreds :: FilePath -> Annex (Maybe Creds)
|
readCacheCreds :: FilePath -> Annex (Maybe Creds)
|
||||||
readCacheCreds file = do
|
readCacheCreds f = liftIO . catchMaybeIO . readFile =<< cacheCredsFile f
|
||||||
|
|
||||||
|
cacheCredsFile :: FilePath -> Annex FilePath
|
||||||
|
cacheCredsFile basefile = do
|
||||||
d <- fromRepo gitAnnexCredsDir
|
d <- fromRepo gitAnnexCredsDir
|
||||||
let f = d </> file
|
return $ d </> basefile
|
||||||
liftIO $ catchMaybeIO $ readFile f
|
|
||||||
|
existsCacheCredPair :: CredPairStorage -> Annex Bool
|
||||||
|
existsCacheCredPair storage =
|
||||||
|
liftIO . doesFileExist =<< cacheCredsFile (credPairFile storage)
|
||||||
|
|
||||||
encodeCredPair :: CredPair -> Creds
|
encodeCredPair :: CredPair -> Creds
|
||||||
encodeCredPair (l, p) = unlines [l, p]
|
encodeCredPair (l, p) = unlines [l, p]
|
||||||
|
@ -162,3 +169,19 @@ removeCreds file = do
|
||||||
d <- fromRepo gitAnnexCredsDir
|
d <- fromRepo gitAnnexCredsDir
|
||||||
let f = d </> file
|
let f = d </> file
|
||||||
liftIO $ nukeFile f
|
liftIO $ nukeFile f
|
||||||
|
|
||||||
|
includeCredsInfo :: RemoteConfig -> CredPairStorage -> [(String, String)] -> Annex [(String, String)]
|
||||||
|
includeCredsInfo c storage info = do
|
||||||
|
v <- liftIO $ getEnvCredPair storage
|
||||||
|
case v of
|
||||||
|
Just _ -> do
|
||||||
|
let (uenv, penv) = credPairEnvironment storage
|
||||||
|
ret $ "from environment variables (" ++ unwords [uenv, penv] ++ ")"
|
||||||
|
Nothing -> case (\ck -> M.lookup ck c) =<< credPairRemoteKey storage of
|
||||||
|
Nothing -> ifM (existsCacheCredPair storage)
|
||||||
|
( ret "stored locally"
|
||||||
|
, ret "not available"
|
||||||
|
)
|
||||||
|
Just _ -> ret "embedded in git repository"
|
||||||
|
where
|
||||||
|
ret s = return $ ("creds", s) : info
|
||||||
|
|
|
@ -72,7 +72,8 @@ gen r u c gc = new <$> remoteCost gc expensiveRemoteCost
|
||||||
availability = GloballyAvailable,
|
availability = GloballyAvailable,
|
||||||
remotetype = remote,
|
remotetype = remote,
|
||||||
mkUnavailable = gen r u (M.insert "host" "!dne!" c) gc,
|
mkUnavailable = gen r u (M.insert "host" "!dne!" c) gc,
|
||||||
getInfo = return [("bucket", fromMaybe "unknown" (getBucket c))]
|
getInfo = includeCredsInfo c (AWS.creds u)
|
||||||
|
[ ("bucket", fromMaybe "unknown" (getBucket c)) ]
|
||||||
}
|
}
|
||||||
|
|
||||||
s3Setup :: Maybe UUID -> Maybe CredPair -> RemoteConfig -> Annex (RemoteConfig, UUID)
|
s3Setup :: Maybe UUID -> Maybe CredPair -> RemoteConfig -> Annex (RemoteConfig, UUID)
|
||||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -14,7 +14,8 @@ git-annex (5.20141014) UNRELEASED; urgency=medium
|
||||||
* info: When run on a single annexed file, displays some info about the
|
* info: When run on a single annexed file, displays some info about the
|
||||||
file, including its key and size.
|
file, including its key and size.
|
||||||
* info: When passed the name or uuid of a remote, displays info about that
|
* info: When passed the name or uuid of a remote, displays info about that
|
||||||
remote.
|
remote. Remotes that support encryption, chunking, or embedded
|
||||||
|
creds will include that in their info.
|
||||||
|
|
||||||
-- Joey Hess <joeyh@debian.org> Tue, 14 Oct 2014 14:09:24 -0400
|
-- Joey Hess <joeyh@debian.org> Tue, 14 Oct 2014 14:09:24 -0400
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue