Skip to content

Commit

Permalink
➖ Isolate CLI with a go.mod and remove dependency on Rig internals (r…
Browse files Browse the repository at this point in the history
  • Loading branch information
andersjohnsen committed Sep 2, 2023
1 parent f29fd68 commit 82300b6
Show file tree
Hide file tree
Showing 6 changed files with 899 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ DEVENVS = RIG_MANAGEMENT_TELEMETRY_ENABLED=false

.PHONY: build-rig
build-rig: ## 🔨 Build rig binary
$(GOBUILD) -o bin/rig ./cmd/rig
(cd cmd/rig/ && $(GOBUILD) -o ../../bin/rig ./)

.PHONY: build-rig-server
build-rig-server: ## 🔨 Build rig-server binary
Expand Down
17 changes: 14 additions & 3 deletions cmd/rig/cmd/base/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ import (
"github.com/golang-jwt/jwt"
"github.com/rigdev/rig-go-api/api/v1/project"
"github.com/rigdev/rig-go-sdk"
"github.com/rigdev/rig/pkg/service"
"github.com/rigdev/rig/pkg/uuid"
"go.uber.org/fx"
)

const (
_rigProjectTokenHeader = "X-Rig-Project-Token"
)

var _omitProjectToken = map[string]struct{}{
"/api.v1.project.Service/Use": {},
"/api.v1.project.Service/Create": {},
"/api.v1.project.Service/List": {},

"/grpc.reflection.v1alpha.ServerReflection/ServerReflectionInfo": {},
}

var clientModule = fx.Module("client",
fx.Supply(&http.Client{}),
fx.Provide(func(s *Service, cfg *Config) rig.Client {
Expand Down Expand Up @@ -87,7 +98,7 @@ type authInterceptor struct {
}

func (i *authInterceptor) handleAuth(ctx context.Context, h http.Header, method string) {
if _, ok := service.OmitProjectToken[method]; !ok {
if _, ok := _omitProjectToken[method]; !ok {
i.setProjectToken(ctx, h)
}
}
Expand Down Expand Up @@ -126,7 +137,7 @@ func (i *authInterceptor) setProjectToken(ctx context.Context, h http.Header) {
}
}

h.Set(service.RigProjectTokenHeader, fmt.Sprint(i.cfg.Context().Project.ProjectToken))
h.Set(_rigProjectTokenHeader, fmt.Sprint(i.cfg.Context().Project.ProjectToken))
}

func (i *authInterceptor) WrapUnary(next connect.UnaryFunc) connect.UnaryFunc {
Expand Down
17 changes: 15 additions & 2 deletions cmd/rig/cmd/storage/list_providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rigdev/rig-go-api/model"
"github.com/rigdev/rig-go-sdk"
"github.com/rigdev/rig/cmd/rig/cmd/utils"
storage_service "github.com/rigdev/rig/internal/service/storage"
"github.com/rigdev/rig/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,7 +39,7 @@ func StorageListProviders(ctx context.Context, cmd *cobra.Command, nc rig.Client
t := table.NewWriter()
t.AppendHeader(table.Row{fmt.Sprintf("Providers (%d)", resp.Msg.GetTotal()), "Name", "ID", "Backend", "#Buckets"})
for i, u := range resp.Msg.GetProviders() {
typ, err := storage_service.GetProviderType(u.GetConfig())
typ, err := getProviderType(u.GetConfig())
if err != nil {
return err
}
Expand All @@ -48,3 +48,16 @@ func StorageListProviders(ctx context.Context, cmd *cobra.Command, nc rig.Client
cmd.Println(t.Render())
return nil
}

func getProviderType(p *storage.Config) (string, error) {
switch p.GetConfig().(type) {
case *storage.Config_S3:
return "s3", nil
case *storage.Config_Gcs:
return "gcs", nil
case *storage.Config_Minio:
return "minio", nil
default:
return "", errors.InvalidArgumentErrorf("unknown provider type")
}
}
124 changes: 124 additions & 0 deletions cmd/rig/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
module github.com/rigdev/rig/cmd/rig

go 1.20

replace github.com/rigdev/rig => ../..

require (
firebase.google.com/go v3.13.0+incompatible
github.com/bufbuild/connect-go v1.10.0
github.com/distribution/distribution/v3 v3.0.0-20230601133803-97b1d649c493
github.com/docker/distribution v2.8.2+incompatible
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/jedib0t/go-pretty/v6 v6.4.6
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/mapstructure v1.5.0
github.com/nyaruka/phonenumbers v1.1.7
github.com/rigdev/rig v0.1.0
github.com/rigdev/rig-go-api v0.0.0-20230901110907-d3cdf0db09f7
github.com/rigdev/rig-go-sdk v0.0.0-20230901111022-ea6af2ed0b83
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
go.uber.org/dig v1.17.0
go.uber.org/fx v1.19.3
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/sync v0.3.0
google.golang.org/api v0.122.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v3 v3.0.1
)

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go/compute v1.19.3 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/firestore v1.9.0 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/longrunning v0.4.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.26 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.28 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.26 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.29 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.28 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.3 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.36.0 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
github.com/bufbuild/connect-grpcreflect-go v1.0.0 // indirect
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/coreos/go-oidc/v3 v3.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-chi/chi/v5 v5.0.10 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/s2a-go v0.1.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.8.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.16.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailjet/mailjet-apiv3-go v0.0.0-20201009050126-c24bc15a9394 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.52 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/segmentio/analytics-go/v3 v3.2.1 // indirect
github.com/segmentio/backo-go v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.2 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.2 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/uptrace/bun v1.1.13 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
go.mongodb.org/mongo-driver v1.11.6 // indirect
go.opencensus.io v0.24.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.13.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/grpc v1.55.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Loading

0 comments on commit 82300b6

Please sign in to comment.