inherit other fields
I think this is all that need to be inherited.
This commit is contained in:
parent
c3975ff3b4
commit
df5b0ffab3
4 changed files with 40 additions and 13 deletions
|
@ -39,10 +39,34 @@ autoEnableField = "autoenable"
|
|||
encryptionField :: RemoteConfigField
|
||||
encryptionField = "encryption"
|
||||
|
||||
macField :: RemoteConfigField
|
||||
macField = "mac"
|
||||
|
||||
cipherField :: RemoteConfigField
|
||||
cipherField = "cipher"
|
||||
|
||||
cipherkeysField :: RemoteConfigField
|
||||
cipherkeysField = "cipher"
|
||||
|
||||
pubkeysField :: RemoteConfigField
|
||||
pubkeysField = "pubkeys"
|
||||
|
||||
chunksizeField :: RemoteConfigField
|
||||
chunksizeField = "chunksize"
|
||||
|
||||
{- A remote with sameas-uuid set will inherit these values from the config
|
||||
- of that uuid. These values cannot be overridden. -}
|
||||
sameasInherits :: S.Set RemoteConfigField
|
||||
sameasInherits = S.fromList
|
||||
-- encryption configuration is necessarily the same for two
|
||||
-- remotes that access the same data store
|
||||
[ encryptionField
|
||||
-- TODO more encryption related fields
|
||||
, macField
|
||||
, cipherField
|
||||
, cipherkeysField
|
||||
, pubkeysField
|
||||
-- legacy chunking was either enabled or not, so has to be the same
|
||||
-- across configs for remotes that access the same data
|
||||
-- (new-style chunking does not have that limitation)
|
||||
, chunksizeField
|
||||
]
|
||||
|
|
|
@ -238,8 +238,8 @@ instance LensGpgEncParams (RemoteConfig, RemoteGitConfig) where
|
|||
{- When the remote is configured to use public-key encryption,
|
||||
- look up the recipient keys and add them to the option list. -}
|
||||
case M.lookup encryptionField c of
|
||||
Just "pubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup "cipherkeys" c
|
||||
Just "sharedpubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup "pubkeys" c
|
||||
Just "pubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup cipherkeysField c
|
||||
Just "sharedpubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup pubkeysField c
|
||||
_ -> []
|
||||
getGpgDecParams (_c,gc) = map Param (remoteAnnexGnupgDecryptOptions gc)
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import Logs.Chunk
|
|||
import Utility.Metered
|
||||
import Crypto (EncKey)
|
||||
import Backend (isStableKey)
|
||||
import Annex.SpecialRemote.Config
|
||||
|
||||
import qualified Data.ByteString.Lazy as L
|
||||
import qualified Data.Map as M
|
||||
|
@ -49,11 +50,11 @@ noChunks _ = False
|
|||
|
||||
getChunkConfig :: RemoteConfig -> ChunkConfig
|
||||
getChunkConfig m =
|
||||
case M.lookup "chunksize" m of
|
||||
case M.lookup chunksizeField m of
|
||||
Nothing -> case M.lookup "chunk" m of
|
||||
Nothing -> NoChunks
|
||||
Just v -> readsz UnpaddedChunks v "chunk"
|
||||
Just v -> readsz LegacyChunks v "chunksize"
|
||||
Just v -> readsz LegacyChunks v chunksizeField
|
||||
where
|
||||
readsz c v f = case readSize dataUnits v of
|
||||
Just size
|
||||
|
|
|
@ -131,29 +131,29 @@ remoteCipher' c gc = go $ extractCipher c
|
|||
embedCreds :: RemoteConfig -> Bool
|
||||
embedCreds c = case yesNo =<< M.lookup "embedcreds" c of
|
||||
Just v -> v
|
||||
Nothing -> isJust (M.lookup "cipherkeys" c) && isJust (M.lookup "cipher" c)
|
||||
Nothing -> isJust (M.lookup cipherkeysField c) && isJust (M.lookup cipherField c)
|
||||
|
||||
{- Gets encryption Cipher, and key encryptor. -}
|
||||
cipherKey :: RemoteConfig -> RemoteGitConfig -> Annex (Maybe (Cipher, EncKey))
|
||||
cipherKey c gc = fmap make <$> remoteCipher c gc
|
||||
where
|
||||
make ciphertext = (ciphertext, encryptKey mac ciphertext)
|
||||
mac = fromMaybe defaultMac $ M.lookup "mac" c >>= readMac
|
||||
mac = fromMaybe defaultMac $ M.lookup macField c >>= readMac
|
||||
|
||||
{- Stores an StorableCipher in a remote's configuration. -}
|
||||
storeCipher :: StorableCipher -> RemoteConfig -> RemoteConfig
|
||||
storeCipher cip = case cip of
|
||||
(SharedCipher t) -> addcipher t
|
||||
(EncryptedCipher t _ ks) -> addcipher t . storekeys ks "cipherkeys"
|
||||
(SharedPubKeyCipher t ks) -> addcipher t . storekeys ks "pubkeys"
|
||||
(EncryptedCipher t _ ks) -> addcipher t . storekeys ks cipherkeysField
|
||||
(SharedPubKeyCipher t ks) -> addcipher t . storekeys ks pubkeysField
|
||||
where
|
||||
addcipher t = M.insert "cipher" (toB64bs t)
|
||||
addcipher t = M.insert cipherField (toB64bs t)
|
||||
storekeys (KeyIds l) n = M.insert n (intercalate "," l)
|
||||
|
||||
{- Extracts an StorableCipher from a remote's configuration. -}
|
||||
extractCipher :: RemoteConfig -> Maybe StorableCipher
|
||||
extractCipher c = case (M.lookup "cipher" c,
|
||||
M.lookup "cipherkeys" c <|> M.lookup "pubkeys" c,
|
||||
extractCipher c = case (M.lookup cipherField c,
|
||||
M.lookup cipherkeysField c <|> M.lookup pubkeysField c,
|
||||
M.lookup encryptionField c) of
|
||||
(Just t, Just ks, encryption) | maybe True (== "hybrid") encryption ->
|
||||
Just $ EncryptedCipher (fromB64bs t) Hybrid (readkeys ks)
|
||||
|
@ -174,7 +174,9 @@ isEncrypted c = case M.lookup encryptionField c of
|
|||
Nothing -> hasEncryptionConfig c
|
||||
|
||||
hasEncryptionConfig :: RemoteConfig -> Bool
|
||||
hasEncryptionConfig c = M.member "cipher" c || M.member "cipherkeys" c || M.member "pubkeys" c
|
||||
hasEncryptionConfig c = M.member cipherField c
|
||||
|| M.member cipherkeysField c
|
||||
|| M.member pubkeysField c
|
||||
|
||||
describeEncryption :: RemoteConfig -> String
|
||||
describeEncryption c = case extractCipher c of
|
||||
|
|
Loading…
Reference in a new issue