Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
feature: dfdaemon supports proxing https registries
Browse files Browse the repository at this point in the history
Signed-off-by: lowzj <[email protected]>
  • Loading branch information
lowzj committed Feb 21, 2019
1 parent 0feb820 commit d49fdfc
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions dfdaemon/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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

type Registry struct {
// Match is a regular expression, dfdaemon use this registry to process the
// matched requests.
Match string `yaml:"match"`

// Schema only can be 'http' or 'https'.
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 from the following command:
// openssl x509 -in <(openssl s_client -showcerts -servername xxx -connect xxx:443 -prexit 2>/dev/null)
Cert string `yaml:"cert"`
}

0 comments on commit d49fdfc

Please sign in to comment.