mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-03-14 13:18:58 -04:00
Support for TLS on http services (#18)
Support for TLS on http services
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user