Skip to content

Commit

Permalink
Add oauth to LB API client (#104)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Auerbeck <[email protected]>
Co-authored-by: Tyler Auerbeck <[email protected]>
  • Loading branch information
tylerauerbeck and tylerauerbeck authored Jun 13, 2023
1 parent 8856ec1 commit 103c949
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
13 changes: 12 additions & 1 deletion cmd/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/spf13/viper"

"go.infratographer.com/loadbalancer-manager-haproxy/pkg/lbapi"
"go.infratographer.com/loadbalancer-manager-haproxy/x/oauth2x"
"go.infratographer.com/x/echox"
"go.infratographer.com/x/versionx"
"go.infratographer.com/x/viperx"
Expand Down Expand Up @@ -94,7 +95,7 @@ func process(ctx context.Context, logger *zap.SugaredLogger) error {
}

server := &srv.Server{
APIClient: lbapi.NewClient(viper.GetString("api-endpoint")),
// APIClient: lbapi.NewClient(viper.GetString("api-endpoint")),
Echo: eSrv,
Chart: chart,
Context: cx,
Expand All @@ -107,6 +108,16 @@ func process(ctx context.Context, logger *zap.SugaredLogger) error {
Locations: viper.GetStringSlice("event-locations"),
}

// init lbapi client
if config.AppConfig.OIDC.ClientID != "" {
oauthHTTPClient := oauth2x.NewClient(ctx, oauth2x.NewClientCredentialsTokenSrc(ctx, config.AppConfig.OIDC))
server.APIClient = lbapi.NewClient(viper.GetString("api-endpoint"),
lbapi.WithHTTPClient(oauthHTTPClient),
)
} else {
server.APIClient = lbapi.NewClient(viper.GetString("api-endpoint"))
}

if err := server.Run(cx); err != nil {
logger.Fatalw("failed starting server", "error", err)
cancel()
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/viper"
"go.uber.org/zap"

"go.infratographer.com/loadbalancer-manager-haproxy/x/oauth2x"
"go.infratographer.com/loadbalanceroperator/internal/config"

"go.infratographer.com/x/events"
Expand Down Expand Up @@ -50,6 +51,7 @@ func init() {
viperx.MustBindFlag(viper.GetViper(), "healthcheck-port", rootCmd.PersistentFlags().Lookup("healthcheck-port"))

events.MustViperFlagsForSubscriber(viper.GetViper(), processCmd.Flags())
oauth2x.MustViperFlags(viper.GetViper(), rootCmd.Flags())

// Cobra also supports local flags, which will only run
// when this action is called directly.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230524022050-2d83ce4fef64
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230612145135-7bf6c8074a9e
go.opentelemetry.io/contrib/instrumentation/github.com/labstack/echo/otelecho v0.42.0 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,8 @@ go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230524022050-2d83ce4fef64 h1:GoY2TzlKH/ZXmkqX7cLx9St+cuqg09pggcOvDXEFwME=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230524022050-2d83ce4fef64/go.mod h1:4Di7Vzg55I2/RH9P4B4Y63Muuxl0CNTsiCrwIu3UzCs=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230612145135-7bf6c8074a9e h1:1tpVzkkoP+HKC6AjLKWvm6Z25rYqeIN/Lh2dorQNWx0=
go.infratographer.com/loadbalancer-manager-haproxy v0.0.0-20230612145135-7bf6c8074a9e/go.mod h1:mrwcbc0ljw0up+sX+umoa1FydiqSeMiynlR6QIO9dqU=
go.infratographer.com/x v0.3.1-0.20230605180922-67c1a1e705ac h1:5PFHsIXYJqF6ALLA39JicYzkSeLOgeF1zg3Vr68GZm8=
go.infratographer.com/x v0.3.1-0.20230605180922-67c1a1e705ac/go.mod h1:GvOhGwi/1Dp5qAQSudHUdLfFmiXzzc27KBfkH0nxnEQ=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package config

import (
"go.infratographer.com/loadbalancer-manager-haproxy/x/oauth2x"

"go.infratographer.com/x/echox"
"go.infratographer.com/x/events"
"go.infratographer.com/x/loggingx"
Expand All @@ -14,6 +16,7 @@ var AppConfig struct {
Events EventsConfig
Server echox.Config
Tracing otelx.Config
OIDC oauth2x.Config
}

// EventsConfig stores the configuration for a load-balancer-api events config
Expand Down

0 comments on commit 103c949

Please sign in to comment.