Skip to content

Commit

Permalink
Upgrade packages (#220)
Browse files Browse the repository at this point in the history
* upgrade go v1.23

Signed-off-by: Mike Mason <mimason@equinix.com>

* upgrade otel

Signed-off-by: Mike Mason <mimason@equinix.com>

* upgraded nats

Signed-off-by: Mike Mason <mimason@equinix.com>

* upgrade spf13/cobra,viper,pflag

Signed-off-by: Mike Mason <mimason@equinix.com>

* upgrade gin-contrib packages cors,zap

Signed-off-by: Mike Mason <mimason@equinix.com>

* upgrade governor-api to v0.2.4

Signed-off-by: Mike Mason <mimason@equinix.com>

* upgrade prometheus client

Signed-off-by: Mike Mason <mimason@equinix.com>

---------

Signed-off-by: Mike Mason <mimason@equinix.com>
  • Loading branch information
mikemrm authored Dec 17, 2024
1 parent 4d1a3a5 commit 146c8c0
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 270 deletions.
6 changes: 3 additions & 3 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ steps:
key: "lint"
plugins:
- docker#v5.9.0:
image: "registry.hub.docker.com/golangci/golangci-lint:v1.51-alpine"
image: "registry.hub.docker.com/golangci/golangci-lint:v1.62-alpine"
command: ["golangci-lint", "run", "-v"]

- label: ":test_tube: test"
key: "test"
plugins:
- docker#v5.9.0:
image: "golang:1.20"
image: "golang:1.23"
command: ["go", "test", "-cover" ,"-race", "./..."]

- label: ":golang: build"
key: "gobuild"
artifact_paths: "bin/${APP_NAME}"
plugins:
- docker#v5.9.0:
image: "golang:1.20"
image: "golang:1.23"
environment:
- CGO_ENABLED=0
- GOOS=linux
Expand Down
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ linters:
- bodyclose
- gocritic
- gocyclo
- goerr113
- err113
- gofmt
- gofumpt
- goimports
- gomnd
- mnd
- govet
- misspell
- noctx
Expand Down
29 changes: 12 additions & 17 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package cmd

import (
"context"
"fmt"
"errors"
"net/url"
"os"
"os/signal"
"strings"
"time"

"github.com/metal-toolbox/addonx/natslock"
Expand All @@ -32,7 +31,7 @@ const (
var serveCmd = &cobra.Command{
Use: "serve",
Short: "starts the gov-okta-addon service",
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
return serve(cmd.Context(), viper.GetViper())
},
}
Expand Down Expand Up @@ -278,43 +277,39 @@ func newNATSLocker(nc *nats.Conn) (*natslock.Locker, error) {

// validateMandatoryFlags collects the mandatory flag validation
func validateMandatoryFlags() error {
errs := []string{}
errs := []error{}

if viper.GetString("nats.url") == "" {
errs = append(errs, ErrNATSURLRequired.Error())
errs = append(errs, ErrNATSURLRequired)
}

if viper.GetString("okta.url") == "" {
errs = append(errs, ErrOktaURLRequired.Error())
errs = append(errs, ErrOktaURLRequired)
}

if viper.GetString("okta.token") == "" {
errs = append(errs, ErrOktaTokenRequired.Error())
errs = append(errs, ErrOktaTokenRequired)
}

if viper.GetString("governor.url") == "" {
errs = append(errs, ErrGovernorURLRequired.Error())
errs = append(errs, ErrGovernorURLRequired)
}

if viper.GetString("governor.client-id") == "" {
errs = append(errs, ErrGovernorClientIDRequired.Error())
errs = append(errs, ErrGovernorClientIDRequired)
}

if viper.GetString("governor.client-secret") == "" {
errs = append(errs, ErrGovernorClientSecretRequired.Error())
errs = append(errs, ErrGovernorClientSecretRequired)
}

if viper.GetString("governor.token-url") == "" {
errs = append(errs, ErrGovernorClientTokenURLRequired.Error())
errs = append(errs, ErrGovernorClientTokenURLRequired)
}

if viper.GetString("governor.audience") == "" {
errs = append(errs, ErrGovernorClientAudienceRequired.Error())
errs = append(errs, ErrGovernorClientAudienceRequired)
}

if len(errs) == 0 {
return nil
}

return fmt.Errorf(strings.Join(errs, "\n")) //nolint:goerr113
return errors.Join(errs...)
}
2 changes: 1 addition & 1 deletion cmd/sync_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var syncGroupsCmd = &cobra.Command{
Groups that exist in Okta but not in Governor, will be created. Groups that exist in Governor but not in Okta, will be deleted.
This command is intended for doing an initial load of groups. It is strongly recommended that you use the dry-run flag first
to see what groups would be created/deleted in Governor.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
return syncGroupsToGovernor(cmd.Context())
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sync_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ group members that do not exist in the Okta group will be removed from the group
must exist in Governor. It is strongly recommended that you use the dry-run flag first to see what
group memberships would be created/deleted in Governor.
`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
return syncGroupMembersToGovernor(cmd.Context())
},
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/sync_users.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var syncUsersCmd = &cobra.Command{
Users that exist in Okta but not in Governor, will be created. Users that exist in Governor but not in Okta, will be deleted.
This command is intended for doing an initial load of users. It is strongly recommended that you use the dry-run flag first
to see what users would be created/deleted in Governor.`,
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
return syncUsersToGovernor(cmd.Context())
},
}
Expand Down
38 changes: 31 additions & 7 deletions cmd/tracing.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,53 @@
package cmd

import (
"context"
"net/url"
"time"

"github.com/spf13/viper"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
)

const timeout = 10 * time.Second

func initTracing() {
if viper.GetBool("tracing.enabled") {
initTracer(viper.GetString("tracing.endpoint"))
initTracer(
viper.GetString("tracing.endpoint"),
viper.GetBool("tracing.insecure"),
)
}
}

// initTracer returns an OpenTelemetry TracerProvider configured to use
// the Jaeger exporter that will send spans to the provided url. The returned
// the OTLP GRPC exporter that will send spans to the provided endpoint. The returned
// TracerProvider will also use a Resource configured with all the information
// about the application.
func initTracer(url string) *tracesdk.TracerProvider {
// Create the Jaeger exporter
exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url)))
func initTracer(endpoint string, insecure bool) *tracesdk.TracerProvider {
_, err := url.Parse(endpoint)
if err != nil {
logger.Fatalw("invalid tracing endpoint", "error", err)
}

exporterOpts := []otlptracegrpc.Option{
otlptracegrpc.WithEndpoint(endpoint),
otlptracegrpc.WithTimeout(timeout),
}

if insecure {
exporterOpts = append(exporterOpts, otlptracegrpc.WithInsecure())
}

exp, err := otlptracegrpc.New(context.Background(), exporterOpts...)
if err != nil {
logger.Fatalw("failed to initialize tracing exporter", "error", err)
logger.Fatalf("failed to initialize tracing", "error", err)
}

tp := tracesdk.NewTracerProvider(
Expand All @@ -39,6 +62,7 @@ func initTracer(url string) *tracesdk.TracerProvider {
)

otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))

return tp
}
Loading

0 comments on commit 146c8c0

Please sign in to comment.