mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2025-12-30 09:38:26 -05:00
* primitive implementation to demonstrate how it could work, still to be considered WIP at best * add new dependency: MicahParks/jwkset and MicahParks/keyfunc to retrieve the JWK set from KeyCloak to verify the signature of the JWTs sent as part of Bearer authentication in the /auth API * (minor) opencloud/.../service.go: clean up a logging statement that was introduced earlier to hunt down why the auth-api service was not being started
62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package http
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/go-chi/chi/v5/middleware"
|
|
opencloudmiddleware "github.com/opencloud-eu/opencloud/pkg/middleware"
|
|
"github.com/opencloud-eu/opencloud/pkg/service/http"
|
|
"github.com/opencloud-eu/opencloud/pkg/version"
|
|
svc "github.com/opencloud-eu/opencloud/services/auth-api/pkg/service/http/v0"
|
|
"go-micro.dev/v4"
|
|
)
|
|
|
|
// Server initializes the http service and server.
|
|
func Server(opts ...Option) (http.Service, error) {
|
|
options := newOptions(opts...)
|
|
|
|
service, err := http.NewService(
|
|
http.TLSConfig(options.Config.HTTP.TLS),
|
|
http.Logger(options.Logger),
|
|
http.Name(options.Config.Service.Name),
|
|
http.Version(version.GetString()),
|
|
http.Namespace(options.Config.HTTP.Namespace),
|
|
http.Address(options.Config.HTTP.Addr),
|
|
http.Context(options.Context),
|
|
http.TraceProvider(options.TraceProvider),
|
|
)
|
|
if err != nil {
|
|
options.Logger.Error().
|
|
Err(err).
|
|
Msg("Error initializing http service")
|
|
return http.Service{}, fmt.Errorf("could not initialize http service: %w", err)
|
|
}
|
|
|
|
handle := svc.NewService(
|
|
svc.Logger(options.Logger),
|
|
svc.Config(options.Config),
|
|
svc.Metrics(options.Metrics),
|
|
svc.TraceProvider(options.TraceProvider),
|
|
svc.Middleware(
|
|
middleware.RealIP,
|
|
middleware.RequestID,
|
|
opencloudmiddleware.Version(
|
|
options.Config.Service.Name,
|
|
version.GetString(),
|
|
),
|
|
opencloudmiddleware.Logger(options.Logger),
|
|
),
|
|
)
|
|
|
|
{
|
|
handle = svc.NewInstrument(handle, options.Metrics)
|
|
handle = svc.NewLogging(handle, options.Logger)
|
|
}
|
|
|
|
if err := micro.RegisterHandler(service.Server(), handle); err != nil {
|
|
return http.Service{}, err
|
|
}
|
|
|
|
return service, nil
|
|
}
|