2019-10-10 16:48:26 +00:00
|
|
|
{- git-annex special remote configuration
|
|
|
|
-
|
|
|
|
- Copyright 2019 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
module Annex.SpecialRemote.Config where
|
|
|
|
|
|
|
|
import Common
|
2019-10-10 19:31:10 +00:00
|
|
|
import Types.Remote (RemoteConfigField, RemoteConfig)
|
2019-10-11 16:45:30 +00:00
|
|
|
import Types.UUID
|
2019-10-10 16:48:26 +00:00
|
|
|
|
|
|
|
import qualified Data.Map as M
|
2019-10-10 19:46:12 +00:00
|
|
|
import qualified Data.Set as S
|
2019-10-10 16:48:26 +00:00
|
|
|
|
|
|
|
{- The name of a configured remote is stored in its config using this key. -}
|
2019-10-10 19:31:10 +00:00
|
|
|
nameField :: RemoteConfigField
|
|
|
|
nameField = "name"
|
2019-10-10 16:48:26 +00:00
|
|
|
|
|
|
|
{- The name of a sameas remote is stored using this key instead.
|
|
|
|
- This prevents old versions of git-annex getting confused. -}
|
2019-10-10 19:31:10 +00:00
|
|
|
sameasNameField :: RemoteConfigField
|
|
|
|
sameasNameField = "sameas-name"
|
2019-10-10 16:48:26 +00:00
|
|
|
|
|
|
|
lookupName :: RemoteConfig -> Maybe String
|
2019-10-10 19:31:10 +00:00
|
|
|
lookupName c = M.lookup nameField c <|> M.lookup sameasNameField c
|
2019-10-10 16:48:26 +00:00
|
|
|
|
|
|
|
{- The uuid that a sameas remote is the same as is stored in this key. -}
|
2019-10-10 19:31:10 +00:00
|
|
|
sameasUUIDField :: RemoteConfigField
|
|
|
|
sameasUUIDField = "sameas-uuid"
|
2019-10-10 16:48:26 +00:00
|
|
|
|
|
|
|
{- The type of a remote is stored in its config using this key. -}
|
2019-10-10 19:31:10 +00:00
|
|
|
typeField :: RemoteConfigField
|
|
|
|
typeField = "type"
|
2019-10-10 16:48:26 +00:00
|
|
|
|
2019-10-10 19:31:10 +00:00
|
|
|
autoEnableField :: RemoteConfigField
|
|
|
|
autoEnableField = "autoenable"
|
2019-10-10 16:48:26 +00:00
|
|
|
|
2019-10-10 19:46:12 +00:00
|
|
|
encryptionField :: RemoteConfigField
|
|
|
|
encryptionField = "encryption"
|
|
|
|
|
2019-10-10 20:10:12 +00:00
|
|
|
macField :: RemoteConfigField
|
|
|
|
macField = "mac"
|
|
|
|
|
|
|
|
cipherField :: RemoteConfigField
|
|
|
|
cipherField = "cipher"
|
|
|
|
|
|
|
|
cipherkeysField :: RemoteConfigField
|
2019-10-11 17:05:25 +00:00
|
|
|
cipherkeysField = "cipherkeys"
|
2019-10-10 20:10:12 +00:00
|
|
|
|
|
|
|
pubkeysField :: RemoteConfigField
|
|
|
|
pubkeysField = "pubkeys"
|
|
|
|
|
|
|
|
chunksizeField :: RemoteConfigField
|
|
|
|
chunksizeField = "chunksize"
|
|
|
|
|
2019-10-10 19:46:12 +00:00
|
|
|
{- A remote with sameas-uuid set will inherit these values from the config
|
2019-10-10 20:12:17 +00:00
|
|
|
- of that uuid. These values cannot be overridden in the remote's config. -}
|
2019-10-10 19:46:12 +00:00
|
|
|
sameasInherits :: S.Set RemoteConfigField
|
|
|
|
sameasInherits = S.fromList
|
2019-10-10 20:10:12 +00:00
|
|
|
-- encryption configuration is necessarily the same for two
|
|
|
|
-- remotes that access the same data store
|
2019-10-10 19:46:12 +00:00
|
|
|
[ encryptionField
|
2019-10-10 20:10:12 +00:00
|
|
|
, 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
|
2019-10-10 19:46:12 +00:00
|
|
|
]
|
2019-10-11 16:45:30 +00:00
|
|
|
|
|
|
|
{- Each RemoteConfig that has a sameas-uuid inherits some fields
|
|
|
|
- from it. Such fields can only be set by inheritance; the RemoteConfig
|
|
|
|
- cannot provide values from them. -}
|
|
|
|
addSameasInherited :: M.Map UUID RemoteConfig -> RemoteConfig -> RemoteConfig
|
|
|
|
addSameasInherited m c = case toUUID <$> M.lookup sameasUUIDField c of
|
|
|
|
Nothing -> c
|
|
|
|
Just sameasuuid -> case M.lookup sameasuuid m of
|
|
|
|
Nothing -> c
|
|
|
|
Just parentc ->
|
|
|
|
M.withoutKeys c sameasInherits
|
|
|
|
`M.union`
|
|
|
|
M.restrictKeys parentc sameasInherits
|
|
|
|
|
|
|
|
{- Remove any fields inherited from a sameas-uuid. When storing a
|
|
|
|
- RemoteConfig, those fields don't get stored, since they were already
|
|
|
|
- inherited. -}
|
|
|
|
removeSameasInherited :: RemoteConfig -> RemoteConfig
|
|
|
|
removeSameasInherited c = case M.lookup sameasUUIDField c of
|
|
|
|
Nothing -> c
|
|
|
|
Just _ -> M.restrictKeys c sameasInherits
|