Skip to content

Commit

Permalink
[feat] add basic TLS support for HTTPS registry
Browse files Browse the repository at this point in the history
  • Loading branch information
Duske committed Jul 22, 2019
1 parent 2475e3f commit e58f5a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -32,7 +32,7 @@ lint: $(GOMETALINTER)
## build: Builds project into an executable binary.
.PHONY: build
build:
go build -o bin/ipdr cmd/ipdr/ipdr.go
go build -o bin/ipdr cmd/ipdr/main.go

## release: Release a new version. Runs `goreleaser internally.
.PHONY: release
Expand Down
6 changes: 6 additions & 0 deletions cmd/ipdr/main.go
Expand Up @@ -34,6 +34,8 @@ func main() {
var format string
var dockerRegistryHost string
var port uint
var tlsCrtPath string
var tlsKeyPath string
var silent bool

rootCmd := &cobra.Command{
Expand Down Expand Up @@ -138,6 +140,8 @@ More info: https://github.com/miguelmota/ipdr`,
srv := server.NewServer(&server.Config{
Port: port,
Debug: !silent,
TLSKeyPath: tlsKeyPath,
TLSCrtPath: tlsCrtPath,
})

return srv.Start()
Expand All @@ -146,6 +150,8 @@ More info: https://github.com/miguelmota/ipdr`,

serverCmd.Flags().BoolVarP(&silent, "silent", "s", false, "Silent flag suppresses logs")
serverCmd.Flags().UintVarP(&port, "port", "p", 5000, "The port for the Docker registry to listen on")
serverCmd.Flags().StringVarP(&tlsCrtPath, "tlsCrtPath", "", "", "The path to the .crt file for TLS")
serverCmd.Flags().StringVarP(&tlsKeyPath, "tlsKeyPath", "", "", "The path to the .key file for TLS")

convertCmd := &cobra.Command{
Use: "convert",
Expand Down
10 changes: 9 additions & 1 deletion server/server.go
Expand Up @@ -19,13 +19,17 @@ type Server struct {
listener net.Listener
host string
ipfsGateway string
tlsCrtPath string
tlsKeyPath string
}

// Config is server config
type Config struct {
Debug bool
Port uint
IPFSGateway string
TLSCrtPath string
TLSKeyPath string
}

// InfoResponse is response for manifest info response
Expand Down Expand Up @@ -59,6 +63,8 @@ func NewServer(config *Config) *Server {
host: fmt.Sprintf("0.0.0.0:%v", port),
debug: config.Debug,
ipfsGateway: ipfs.NormalizeGatewayURL(config.IPFSGateway),
tlsCrtPath: config.TLSCrtPath,
tlsKeyPath: config.TLSKeyPath,
}
}

Expand Down Expand Up @@ -171,7 +177,9 @@ func (s *Server) Start() error {
}

s.Debugf("[registry/server] listening on %s", s.listener.Addr())

if s.tlsKeyPath != "" && s.tlsCrtPath != "" {
return http.ServeTLS(s.listener, nil, s.tlsCrtPath, s.tlsKeyPath)
}
return http.Serve(s.listener, nil)
}

Expand Down

0 comments on commit e58f5a6

Please sign in to comment.