From b112147100ecbd3d99d37ab3ca529c1f3741a4a6 Mon Sep 17 00:00:00 2001 From: lowzj Date: Thu, 21 Feb 2019 16:15:11 +0800 Subject: [PATCH] feature: dfdaemon supports proxing https registries Signed-off-by: lowzj --- dfdaemon/config/config.go | 74 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 dfdaemon/config/config.go diff --git a/dfdaemon/config/config.go b/dfdaemon/config/config.go new file mode 100644 index 000000000..d7f0c1682 --- /dev/null +++ b/dfdaemon/config/config.go @@ -0,0 +1,74 @@ +/* + * Copyright The Dragonfly Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package config + +import ( + "fmt" + "io/ioutil" + + "gopkg.in/yaml.v2" +) + +// ----------------------------------------------------------------------------- +// Properties + +// Properties holds all configurable properties of dfdaemon. +// The default path is '/etc/dragonfly/dfdaemon.yml' +type Properties struct { + Registries []Registry `yaml:"registries"` +} + +// Load loads properties from config file. +func (p *Properties) Load(path string) error { + return p.loadFromYaml(path) +} + +func (p *Properties) loadFromYaml(path string) error { + yamlFile, err := ioutil.ReadFile(path) + if err != nil { + return fmt.Errorf("read yaml config from %s error: %v", path, err) + } + err = yaml.Unmarshal(yamlFile, p) + if err != nil { + return fmt.Errorf("unmarshal yaml error:%v", err) + } + return nil +} + +// ----------------------------------------------------------------------------- +// Registry + +// Registry is the proxied registry base information. +type Registry struct { + // Match is a regular expression, dfdaemon use this registry to process the + // requests whose host is matched. + Match string `yaml:"match"` + + // Schema can be 'http', 'https' or empty. It will use dfdaemon's schema if + // it's empty. + Schema string `yaml:"schema"` + + // Host is the host of proxied registry, including ip and port. + Host string `yaml:"host"` + + // Cert is the path of server-side certification. It should be provided when + // the 'Schema' is 'https' and the dfdaemon is worked on proxy pattern and + // the proxied registry is self-certificated. + // The server-side certification could be get by using this command: + // openssl x509 -in <(openssl s_client -showcerts -servername xxx -connect xxx:443 -prexit 2>/dev/null) + Cert string `yaml:"cert"` +}