Skip to content

Commit

Permalink
Listen with TLS if configured
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Oct 12, 2021
1 parent ec7ad02 commit 5d95fcc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Add support for TLS so the registry can directly listen on HTTPS. []()

### Deprecated

### Known Issues
Expand Down
14 changes: 13 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var (
address string
httpProfAddress string

tlsCertFile string
tlsKeyFile string

dryRun bool
configPath = "config.yml"

Expand All @@ -50,6 +53,8 @@ var (

func init() {
flag.StringVar(&address, "address", "localhost:8080", "Address of the package-registry service.")
flag.StringVar(&tlsCertFile, "tls-cert", "", "Path of the TLS certificate.")
flag.StringVar(&tlsKeyFile, "tls-key", "", "Path of the TLS key.")
flag.StringVar(&httpProfAddress, "httpprof", "", "Enable HTTP profiler listening on the given address.")
// This flag is experimental and might be removed in the future or renamed
flag.BoolVar(&dryRun, "dry-run", false, "Runs a dry-run of the registry without starting the web service (experimental)")
Expand All @@ -73,7 +78,7 @@ func main() {

server := initServer()
go func() {
err := server.ListenAndServe()
err := runServer(server)
if err != nil && err != http.ErrServerClosed {
log.Fatalf("Error occurred while serving: %s", err)
}
Expand Down Expand Up @@ -129,6 +134,13 @@ func initServer() *http.Server {
return &http.Server{Addr: address, Handler: router}
}

func runServer(server *http.Server) error {
if tlsCertFile != "" && tlsKeyFile != "" {
return server.ListenAndServeTLS(tlsCertFile, tlsKeyFile)
}
return server.ListenAndServe()
}

func initAPMTracer() *apm.Tracer {
apm.DefaultTracer.Close()
if _, found := os.LookupEnv("ELASTIC_APM_SERVER_URL"); !found {
Expand Down

0 comments on commit 5d95fcc

Please sign in to comment.