This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: dfdaemon supports proxing https registries
Signed-off-by: lowzj <[email protected]>
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"` | ||
} |