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 :: RemoteConfigField
|
||||||
encryptionField = "encryption"
|
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
|
{- A remote with sameas-uuid set will inherit these values from the config
|
||||||
- of that uuid. These values cannot be overridden. -}
|
- of that uuid. These values cannot be overridden. -}
|
||||||
sameasInherits :: S.Set RemoteConfigField
|
sameasInherits :: S.Set RemoteConfigField
|
||||||
sameasInherits = S.fromList
|
sameasInherits = S.fromList
|
||||||
|
-- encryption configuration is necessarily the same for two
|
||||||
|
-- remotes that access the same data store
|
||||||
[ encryptionField
|
[ 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,
|
{- When the remote is configured to use public-key encryption,
|
||||||
- look up the recipient keys and add them to the option list. -}
|
- look up the recipient keys and add them to the option list. -}
|
||||||
case M.lookup encryptionField c of
|
case M.lookup encryptionField c of
|
||||||
Just "pubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup "cipherkeys" c
|
Just "pubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup cipherkeysField c
|
||||||
Just "sharedpubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup "pubkeys" c
|
Just "sharedpubkey" -> Gpg.pkEncTo $ maybe [] (splitc ',') $ M.lookup pubkeysField c
|
||||||
_ -> []
|
_ -> []
|
||||||
getGpgDecParams (_c,gc) = map Param (remoteAnnexGnupgDecryptOptions gc)
|
getGpgDecParams (_c,gc) = map Param (remoteAnnexGnupgDecryptOptions gc)
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ import Logs.Chunk
|
||||||
import Utility.Metered
|
import Utility.Metered
|
||||||
import Crypto (EncKey)
|
import Crypto (EncKey)
|
||||||
import Backend (isStableKey)
|
import Backend (isStableKey)
|
||||||
|
import Annex.SpecialRemote.Config
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
|
@ -49,11 +50,11 @@ noChunks _ = False
|
||||||
|
|
||||||
getChunkConfig :: RemoteConfig -> ChunkConfig
|
getChunkConfig :: RemoteConfig -> ChunkConfig
|
||||||
getChunkConfig m =
|
getChunkConfig m =
|
||||||
case M.lookup "chunksize" m of
|
case M.lookup chunksizeField m of
|
||||||
Nothing -> case M.lookup "chunk" m of
|
Nothing -> case M.lookup "chunk" m of
|
||||||
Nothing -> NoChunks
|
Nothing -> NoChunks
|
||||||
Just v -> readsz UnpaddedChunks v "chunk"
|
Just v -> readsz UnpaddedChunks v "chunk"
|
||||||
Just v -> readsz LegacyChunks v "chunksize"
|
Just v -> readsz LegacyChunks v chunksizeField
|
||||||
where
|
where
|
||||||
readsz c v f = case readSize dataUnits v of
|
readsz c v f = case readSize dataUnits v of
|
||||||
Just size
|
Just size
|
||||||
|
|
|
@ -131,29 +131,29 @@ remoteCipher' c gc = go $ extractCipher c
|
||||||
embedCreds :: RemoteConfig -> Bool
|
embedCreds :: RemoteConfig -> Bool
|
||||||
embedCreds c = case yesNo =<< M.lookup "embedcreds" c of
|
embedCreds c = case yesNo =<< M.lookup "embedcreds" c of
|
||||||
Just v -> v
|
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. -}
|
{- Gets encryption Cipher, and key encryptor. -}
|
||||||
cipherKey :: RemoteConfig -> RemoteGitConfig -> Annex (Maybe (Cipher, EncKey))
|
cipherKey :: RemoteConfig -> RemoteGitConfig -> Annex (Maybe (Cipher, EncKey))
|
||||||
cipherKey c gc = fmap make <$> remoteCipher c gc
|
cipherKey c gc = fmap make <$> remoteCipher c gc
|
||||||
where
|
where
|
||||||
make ciphertext = (ciphertext, encryptKey mac ciphertext)
|
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. -}
|
{- Stores an StorableCipher in a remote's configuration. -}
|
||||||
storeCipher :: StorableCipher -> RemoteConfig -> RemoteConfig
|
storeCipher :: StorableCipher -> RemoteConfig -> RemoteConfig
|
||||||
storeCipher cip = case cip of
|
storeCipher cip = case cip of
|
||||||
(SharedCipher t) -> addcipher t
|
(SharedCipher t) -> addcipher t
|
||||||
(EncryptedCipher t _ ks) -> addcipher t . storekeys ks "cipherkeys"
|
(EncryptedCipher t _ ks) -> addcipher t . storekeys ks cipherkeysField
|
||||||
(SharedPubKeyCipher t ks) -> addcipher t . storekeys ks "pubkeys"
|
(SharedPubKeyCipher t ks) -> addcipher t . storekeys ks pubkeysField
|
||||||
where
|
where
|
||||||
addcipher t = M.insert "cipher" (toB64bs t)
|
addcipher t = M.insert cipherField (toB64bs t)
|
||||||
storekeys (KeyIds l) n = M.insert n (intercalate "," l)
|
storekeys (KeyIds l) n = M.insert n (intercalate "," l)
|
||||||
|
|
||||||
{- Extracts an StorableCipher from a remote's configuration. -}
|
{- Extracts an StorableCipher from a remote's configuration. -}
|
||||||
extractCipher :: RemoteConfig -> Maybe StorableCipher
|
extractCipher :: RemoteConfig -> Maybe StorableCipher
|
||||||
extractCipher c = case (M.lookup "cipher" c,
|
extractCipher c = case (M.lookup cipherField c,
|
||||||
M.lookup "cipherkeys" c <|> M.lookup "pubkeys" c,
|
M.lookup cipherkeysField c <|> M.lookup pubkeysField c,
|
||||||
M.lookup encryptionField c) of
|
M.lookup encryptionField c) of
|
||||||
(Just t, Just ks, encryption) | maybe True (== "hybrid") encryption ->
|
(Just t, Just ks, encryption) | maybe True (== "hybrid") encryption ->
|
||||||
Just $ EncryptedCipher (fromB64bs t) Hybrid (readkeys ks)
|
Just $ EncryptedCipher (fromB64bs t) Hybrid (readkeys ks)
|
||||||
|
@ -174,7 +174,9 @@ isEncrypted c = case M.lookup encryptionField c of
|
||||||
Nothing -> hasEncryptionConfig c
|
Nothing -> hasEncryptionConfig c
|
||||||
|
|
||||||
hasEncryptionConfig :: RemoteConfig -> Bool
|
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 :: RemoteConfig -> String
|
||||||
describeEncryption c = case extractCipher c of
|
describeEncryption c = case extractCipher c of
|
||||||
|
|
Loading…
Add table
Reference in a new issue