5 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
6 "git.curoverse.com/arvados.git/sdk/go/keepclient"
13 // keep-rsync arguments
15 srcConfig arvadosclient.APIConfig
16 dstConfig arvadosclient.APIConfig
17 srcKeepServicesJSON string
18 dstKeepServicesJSON string
24 var srcConfigFile string
25 var dstConfigFile string
31 "Source configuration filename with full path that contains "+
32 "an ARVADOS_API_TOKEN which is a valid datamanager token recognized by the source keep servers, "+
33 "ARVADOS_API_HOST, ARVADOS_API_HOST_INSECURE, and ARVADOS_BLOB_SIGNING_KEY.")
39 "Destination configuration filename with full path that contains "+
40 "an ARVADOS_API_TOKEN which is a valid datamanager token recognized by the destination keep servers, "+
41 "ARVADOS_API_HOST, ARVADOS_API_HOST_INSECURE, and ARVADOS_BLOB_SIGNING_KEY.")
45 "src-keep-services-json",
47 "An optional list of available source keepservices. "+
48 "If not provided, this list is obtained from api server configured in src-config-file.")
52 "dst-keep-services-json",
54 "An optional list of available destination keepservices. "+
55 "If not provided, this list is obtained from api server configured in dst-config-file.")
61 "Number of replications to write to the destination.")
74 if srcConfigFile == "" {
75 log.Fatal("-src-config-file must be specified.")
77 srcConfig, err = readConfigFromFile(srcConfigFile)
79 log.Fatal("Error reading source configuration: %s", err.Error())
82 if dstConfigFile == "" {
83 log.Fatal("-dst-config-file must be specified.")
85 dstConfig, err = readConfigFromFile(dstConfigFile)
87 log.Fatal("Error reading destination configuration: %s", err.Error())
90 // Initialize keep-rsync
91 err = initializeKeepRsync()
93 log.Fatal("Error configurating keep-rsync: %s", err.Error())
97 var matchTrue = regexp.MustCompile("^(?i:1|yes|true)$")
99 // Reads config from file
100 func readConfigFromFile(filename string) (arvadosclient.APIConfig, error) {
101 var config arvadosclient.APIConfig
103 content, err := ioutil.ReadFile(filename)
108 lines := strings.Split(string(content), "\n")
109 for _, line := range lines {
113 kv := strings.Split(line, "=")
116 case "ARVADOS_API_TOKEN":
117 config.APIToken = kv[1]
118 case "ARVADOS_API_HOST":
119 config.APIHost = kv[1]
120 case "ARVADOS_API_HOST_INSECURE":
121 config.APIHostInsecure = matchTrue.MatchString(kv[1])
122 case "ARVADOS_EXTERNAL_CLIENT":
123 config.ExternalClient = matchTrue.MatchString(kv[1])
129 // keep-rsync source and destination clients
131 arvSrc arvadosclient.ArvadosClient
132 arvDst arvadosclient.ArvadosClient
133 kcSrc *keepclient.KeepClient
134 kcDst *keepclient.KeepClient
137 // Initializes keep-rsync using the config provided
138 func initializeKeepRsync() (err error) {
139 // arvSrc from srcConfig
140 arvSrc, err = arvadosclient.New(srcConfig)
145 // arvDst from dstConfig
146 arvDst, err = arvadosclient.New(dstConfig)
151 // if srcKeepServicesJSON is provided, use it to load services; else, use DiscoverKeepServers
152 if srcKeepServicesJSON == "" {
153 kcSrc, err = keepclient.MakeKeepClient(&arvSrc)
158 kcSrc, err = keepclient.MakeKeepClientFromJSON(&arvSrc, srcKeepServicesJSON)
164 // if dstKeepServicesJSON is provided, use it to load services; else, use DiscoverKeepServers
165 if dstKeepServicesJSON == "" {
166 kcDst, err = keepclient.MakeKeepClient(&arvDst)
171 kcDst, err = keepclient.MakeKeepClientFromJSON(&arvDst, dstKeepServicesJSON)
176 kcDst.Want_replicas = replications