chore: code cleanup service/webfinger

This commit is contained in:
Thomas Müller
2024-04-26 11:11:10 +02:00
parent f7fb0bc591
commit ac951eaaae
7 changed files with 15 additions and 40 deletions

View File

@@ -44,17 +44,17 @@ func Server(cfg *config.Config) *cli.Command {
}
return context.WithCancel(cfg.Context)
}()
metrics = metrics.New(metrics.Logger(logger))
m = metrics.New(metrics.Logger(logger))
)
defer cancel()
metrics.BuildInfo.WithLabelValues(version.GetString()).Set(1)
m.BuildInfo.WithLabelValues(version.GetString()).Set(1)
{
relationProviders, err := getRelationProviders(cfg)
if err != nil {
logger.Error().Err(err).Msg("relation providier init")
logger.Error().Err(err).Msg("relation provider init")
return err
}
@@ -67,7 +67,7 @@ func Server(cfg *config.Config) *cli.Command {
logger.Error().Err(err).Msg("handler init")
return err
}
svc = service.NewInstrument(svc, metrics)
svc = service.NewInstrument(svc, m)
svc = service.NewLogging(svc, logger) // this logs service specific data
svc = service.NewTracing(svc, traceProvider)

View File

@@ -32,6 +32,6 @@ func ParseConfig(cfg *config.Config) error {
return Validate(cfg)
}
func Validate(cfg *config.Config) error {
func Validate(_ *config.Config) error {
return nil
}

View File

@@ -22,7 +22,7 @@ func OpenIDDiscovery(href string) service.RelationProvider {
}
}
func (l *openIDDiscovery) Add(ctx context.Context, jrd *webfinger.JSONResourceDescriptor) {
func (l *openIDDiscovery) Add(_ context.Context, jrd *webfinger.JSONResourceDescriptor) {
if jrd == nil {
jrd = &webfinger.JSONResourceDescriptor{}
}

View File

@@ -31,7 +31,7 @@ func Server(opts ...Option) (*http.Server, error) {
}
// health implements the health check.
func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
func health(_ *config.Config) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
@@ -47,7 +47,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
}
// ready implements the ready check.
func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
func ready(_ *config.Config) func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)

View File

@@ -2,6 +2,7 @@ package http
import (
"context"
"go.opentelemetry.io/otel/trace/noop"
"github.com/owncloud/ocis/v2/ocis-pkg/log"
"github.com/owncloud/ocis/v2/services/webfinger/pkg/config"
@@ -36,13 +37,6 @@ func newOptions(opts ...Option) Options {
return opt
}
// Name provides a name for the service.
func Name(val string) Option {
return func(o *Options) {
o.Name = val
}
}
// Logger provides a function to set the logger option.
func Logger(val log.Logger) Option {
return func(o *Options) {
@@ -64,20 +58,6 @@ func Config(val *config.Config) Option {
}
}
// Flags provides a function to set the flags option.
func Flags(val []cli.Flag) Option {
return func(o *Options) {
o.Flags = append(o.Flags, val...)
}
}
// Namespace provides a function to set the namespace option.
func Namespace(val string) Option {
return func(o *Options) {
o.Namespace = val
}
}
// Service provides a function to set the service option.
func Service(val svc.Service) Option {
return func(o *Options) {
@@ -91,7 +71,7 @@ func TraceProvider(traceProvider trace.TracerProvider) Option {
if traceProvider != nil {
o.TraceProvider = traceProvider
} else {
o.TraceProvider = trace.NewNoopTracerProvider()
o.TraceProvider = noop.NewTracerProvider()
}
}
}

View File

@@ -26,7 +26,7 @@ func Server(opts ...Option) (ohttp.Service, error) {
options := newOptions(opts...)
service := options.Service
svc, err := ohttp.NewService(
newService, err := ohttp.NewService(
ohttp.TLSConfig(options.Config.HTTP.TLS),
ohttp.Logger(options.Logger),
ohttp.Namespace(options.Config.HTTP.Namespace),
@@ -98,13 +98,13 @@ func Server(opts ...Option) (ohttp.Service, error) {
r.Get("/.well-known/webfinger", WebfingerHandler(service))
})
err = micro.RegisterHandler(svc.Server(), mux)
err = micro.RegisterHandler(newService.Server(), mux)
if err != nil {
options.Logger.Fatal().Err(err).Msg("failed to register the handler")
}
svc.Init()
return svc, nil
newService.Init()
return newService, nil
}
func WebfingerHandler(service svc.Service) func(w http.ResponseWriter, r *http.Request) {

View File

@@ -9,11 +9,6 @@ import (
"github.com/owncloud/ocis/v2/services/webfinger/pkg/webfinger"
)
const (
OwnCloudInstanceRel = "http://webfinger.owncloud/rel/server-instance"
OpenIDConnectRel = "http://openid.net/specs/connect/1.0/issuer"
)
// Service defines the extension handlers.
type Service interface {
// Webfinger is the endpoint for retrieving various href relations.
@@ -78,7 +73,7 @@ type svc struct {
}
// TODO implement different implementations:
// static one returning the href or a configureable domain
// static one returning the href or a configurable domain
// regex one returning different instances based on the regex that matches
// claim one that reads a claim and then fetches the instance?
// that is actually two interfaces / steps: