Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TLS configuration for server #190

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ var (
SecretExpiry int64 `flag:"secret-expiry" default:"0" description:"Maximum expiry of the stored secrets in seconds"`
StorageType string `flag:"storage-type" default:"mem" description:"Storage to use for putting secrets to" validate:"nonzero"`
VersionAndExit bool `flag:"version" default:"false" description:"Print version information and exit"`
EnableTLS bool `flag:"enable-tls" default:"false" description:"Enable HTTPS/TLS"`
CertFile string `flag:"cert-file" default:"" description:"Path to the TLS certificate file"`
KeyFile string `flag:"key-file" default:"" description:"Path to the TLS private key file"`
}

assets file_helpers.FSStack
Expand Down Expand Up @@ -158,8 +161,19 @@ func main() {
"version": version,
}).Info("ots started")

if err = server.ListenAndServe(); err != nil {
logrus.WithError(err).Fatal("HTTP server quit unexpectedly")
if cfg.EnableTLS {
if cfg.CertFile == "" || cfg.KeyFile == "" {
logrus.Fatal("TLS is enabled but cert-file or key-file is not provided")
}
logrus.Infof("Starting HTTPS server on %s", cfg.Listen)
if err := server.ListenAndServeTLS(cfg.CertFile, cfg.KeyFile); err != nil {
logrus.WithError(err).Fatal("HTTPS server quit unexpectedly")
}
} else {
logrus.Infof("Starting HTTP server on %s", cfg.Listen)
if err := server.ListenAndServe(); err != nil {
logrus.WithError(err).Fatal("HTTP server quit unexpectedly")
}
}
}

Expand Down
Loading