diff --git a/service/http/option.go b/service/http/option.go index 73ea43428b..39ddd47776 100644 --- a/service/http/option.go +++ b/service/http/option.go @@ -2,6 +2,7 @@ package http import ( "context" + "crypto/tls" "github.com/micro/cli" "github.com/owncloud/ocis-pkg/log" @@ -13,6 +14,7 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { Logger log.Logger + TLSConfig *tls.Config Namespace string Name string Version string @@ -82,3 +84,10 @@ func Flags(flags ...cli.Flag) Option { o.Flags = append(o.Flags, flags...) } } + +// TLSConfig provides a function to set the TLSConfig option. +func TLSConfig(config *tls.Config) Option { + return func(o *Options) { + o.TLSConfig = config + } +} diff --git a/service/http/service.go b/service/http/service.go index c77dcaae2f..76173707a4 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -1,6 +1,7 @@ package http import ( + "crypto/tls" "strings" "time" @@ -15,9 +16,8 @@ type Service struct { // NewService initializes a new http service. func NewService(opts ...Option) Service { sopts := newOptions(opts...) - sopts.Logger.Info(). - Str("transport", "http"). + Str("transport", transport(sopts.TLSConfig)). Str("addr", sopts.Address). Msg("Starting server") @@ -36,6 +36,7 @@ func NewService(opts ...Option) Service { web.RegisterTTL(time.Second * 30), web.RegisterInterval(time.Second * 10), web.Context(sopts.Context), + web.TLSConfig(sopts.TLSConfig), web.Flags(sopts.Flags...), } @@ -45,3 +46,11 @@ func NewService(opts ...Option) Service { ), } } + +func transport(secure *tls.Config) string { + if secure != nil { + return "https" + } + + return "http" +}