From eacf64eb1c64f3d3d79b2bc496c7f2564972c7d7 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 20 Jan 2020 10:08:55 +0100 Subject: [PATCH 1/3] options support for tlsconfig and secure --- service/http/option.go | 17 +++++++++++++++++ service/http/service.go | 2 ++ 2 files changed, 19 insertions(+) diff --git a/service/http/option.go b/service/http/option.go index 73ea43428b..21eb677222 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,8 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { Logger log.Logger + Secure bool + TLSConfig *tls.Config Namespace string Name string Version string @@ -82,3 +85,17 @@ func Flags(flags ...cli.Flag) Option { o.Flags = append(o.Flags, flags...) } } + +// Secure provides a function to set the secure option. +func Secure(secure bool) Option { + return func(o *Options) { + o.Secure = secure + } +} + +// 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..d3ca3b39dc 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -36,6 +36,8 @@ func NewService(opts ...Option) Service { web.RegisterTTL(time.Second * 30), web.RegisterInterval(time.Second * 10), web.Context(sopts.Context), + web.Secure(sopts.Secure), + web.TLSConfig(sopts.TLSConfig), web.Flags(sopts.Flags...), } From 5dc789f3e1668cf96d26f72a89d9b48678728642 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 20 Jan 2020 12:11:01 +0100 Subject: [PATCH 2/3] added transport method to logger --- service/http/service.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/service/http/service.go b/service/http/service.go index d3ca3b39dc..09ab849d69 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -15,9 +15,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.Secure)). Str("addr", sopts.Address). Msg("Starting server") @@ -47,3 +46,11 @@ func NewService(opts ...Option) Service { ), } } + +func transport(secure bool) string { + if secure { + return "https" + } + + return "http" +} From 1a7ad9f61b990b44388624cc890e9702bb9eee85 Mon Sep 17 00:00:00 2001 From: "A.Unger" Date: Mon, 20 Jan 2020 12:55:58 +0100 Subject: [PATCH 3/3] remove secure flag --- service/http/option.go | 8 -------- service/http/service.go | 8 ++++---- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/service/http/option.go b/service/http/option.go index 21eb677222..39ddd47776 100644 --- a/service/http/option.go +++ b/service/http/option.go @@ -14,7 +14,6 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { Logger log.Logger - Secure bool TLSConfig *tls.Config Namespace string Name string @@ -86,13 +85,6 @@ func Flags(flags ...cli.Flag) Option { } } -// Secure provides a function to set the secure option. -func Secure(secure bool) Option { - return func(o *Options) { - o.Secure = secure - } -} - // TLSConfig provides a function to set the TLSConfig option. func TLSConfig(config *tls.Config) Option { return func(o *Options) { diff --git a/service/http/service.go b/service/http/service.go index 09ab849d69..76173707a4 100644 --- a/service/http/service.go +++ b/service/http/service.go @@ -1,6 +1,7 @@ package http import ( + "crypto/tls" "strings" "time" @@ -16,7 +17,7 @@ type Service struct { func NewService(opts ...Option) Service { sopts := newOptions(opts...) sopts.Logger.Info(). - Str("transport", transport(sopts.Secure)). + Str("transport", transport(sopts.TLSConfig)). Str("addr", sopts.Address). Msg("Starting server") @@ -35,7 +36,6 @@ func NewService(opts ...Option) Service { web.RegisterTTL(time.Second * 30), web.RegisterInterval(time.Second * 10), web.Context(sopts.Context), - web.Secure(sopts.Secure), web.TLSConfig(sopts.TLSConfig), web.Flags(sopts.Flags...), } @@ -47,8 +47,8 @@ func NewService(opts ...Option) Service { } } -func transport(secure bool) string { - if secure { +func transport(secure *tls.Config) string { + if secure != nil { return "https" }