From 3e0c758d7f453efc011fbae02527741d5fc223f0 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 30 Apr 2017 17:55:11 +0200 Subject: [PATCH] config: PushACLs, sinks are also just ClientMappings & LOCAL_TRANSPORT_IDENTITY --- cmd/config.go | 60 +++++++++++++++++++++++++--------------- cmd/sampleconf/zrepl.yml | 22 ++++++++------- 2 files changed, 50 insertions(+), 32 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index 163cf1f..a38c769 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -45,16 +45,17 @@ type Pull struct { From *Pool Mapping zfs.DatasetMapping } -type Sink struct { +type ClientMapping struct { From string Mapping zfs.DatasetMapping } type Config struct { - Pools []Pool - Pushs []Push - Pulls []Pull - Sinks []Sink + Pools []Pool + Pushs []Push + Pulls []Pull + Sinks []ClientMapping + PullACLs []ClientMapping } func ParseConfig(path string) (config Config, err error) { @@ -94,7 +95,10 @@ func parseMain(root map[string]interface{}) (c Config, err error) { if c.Pulls, err = parsePulls(root["pulls"], poolLookup); err != nil { return } - if c.Sinks, err = parseSinks(root["sinks"]); err != nil { + if c.Sinks, err = parseClientMappings(root["sinks"]); err != nil { + return + } + if c.PullACLs, err = parseClientMappings(root["pull_acls"]); err != nil { return } return @@ -112,6 +116,12 @@ func parsePools(v interface{}) (pools []Pool, err error) { pools = make([]Pool, len(asList)) for i, p := range asList { + + if p.Name == LOCAL_TRANSPORT_IDENTITY { + err = errors.New(fmt.Sprintf("pool name '%s' reserved for local pulls", LOCAL_TRANSPORT_IDENTITY)) + return + } + var transport Transport if transport, err = parseTransport(p.Transport); err != nil { return @@ -227,28 +237,34 @@ func parsePulls(v interface{}, pl poolLookup) (p []Pull, err error) { return } -func parseSinks(v interface{}) (sinks []Sink, err error) { - - var asList []interface{} +func expectList(v interface{}) (asList []interface{}, err error) { var ok bool if asList, ok = v.([]interface{}); !ok { - return nil, errors.New("expected list") + err = errors.New("expected list") } - - sinks = make([]Sink, len(asList)) - - for i, s := range asList { - var sink Sink - if sink, err = parseSink(s); err != nil { - return - } - sinks[i] = sink - } - return } -func parseSink(v interface{}) (s Sink, err error) { +func parseClientMappings(v interface{}) (cm []ClientMapping, err error) { + + var asList []interface{} + if asList, err = expectList(v); err != nil { + return + } + + cm = make([]ClientMapping, len(asList)) + + for i, e := range asList { + var m ClientMapping + if m, err = parseClientMapping(e); err != nil { + return + } + cm[i] = m + } + return +} + +func parseClientMapping(v interface{}) (s ClientMapping, err error) { t := struct { From string Mapping map[string]string diff --git a/cmd/sampleconf/zrepl.yml b/cmd/sampleconf/zrepl.yml index 07814cf..25ea7a0 100644 --- a/cmd/sampleconf/zrepl.yml +++ b/cmd/sampleconf/zrepl.yml @@ -2,17 +2,10 @@ pools: - name: offsite_backups transport: ssh: - zrepl_identity: db2 - host: backups1.example.com + host: 192.168.122.6 user: root port: 22 - command: ssh - args: [] - - - name: local_mirror - transport: - local: - pool: mirrorpool + identity_file: /etc/zrepl/identities/offsite_backups pushs: - to: offsite_backups @@ -26,7 +19,9 @@ pulls: # like in sinks } - - from: local_mirror + # local replication, only allowed in pull mode + # the from name 'local' is reserved for this purpose + - from: local mapping: { "tank/usr/home":"mirrorpool/foo/bar" } @@ -79,3 +74,10 @@ sinks: "*": backups/special_snowflake/remainingbackup # NOTE: ^ alignment, should be possible, looks nicer } + +pull_acls: + # same synatx as in sinks, but the returned mapping does not matter + - from: office_backup + mapping: { + "tank/usr/home":"notnull" + }