Skip to content

Commit

Permalink
chore(deps): bump up dependencies with changes to the Write API (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-whit authored Nov 28, 2023
2 parents 410ac99 + 8b80d3c commit b3a2254
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 92 deletions.
4 changes: 2 additions & 2 deletions cmd/tuple/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var deleteCmd = &cobra.Command{
return fmt.Errorf("failed to parse file name due to %w", err)
}
if fileName != "" {
var tuples []client.ClientWriteRequestTupleKey
var tuples []client.ClientTupleKeyWithoutCondition

data, err := os.ReadFile(fileName)
if err != nil {
Expand Down Expand Up @@ -79,7 +79,7 @@ var deleteCmd = &cobra.Command{
return output.Display(*response) //nolint:wrapcheck
}
body := &client.ClientDeleteTuplesBody{
client.ClientWriteRequestTupleKey{
client.ClientTupleKeyWithoutCondition{
User: args[0],
Relation: args[1],
Object: args[2],
Expand Down
47 changes: 38 additions & 9 deletions cmd/tuple/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/openfga/cli/internal/cmdutils"
"github.com/openfga/cli/internal/output"
openfga "github.com/openfga/go-sdk"
"github.com/openfga/go-sdk/client"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"
Expand All @@ -35,13 +36,13 @@ var MaxTuplesPerWrite = 1
var MaxParallelRequests = 10

type failedWriteResponse struct {
TupleKey client.ClientWriteRequestTupleKey `json:"tuple_key"`
Reason string `json:"reason"`
TupleKey client.ClientTupleKey `json:"tuple_key"`
Reason string `json:"reason"`
}

type importResponse struct {
Successful []client.ClientWriteRequestTupleKey `json:"successful"`
Failed []failedWriteResponse `json:"failed"`
Successful []client.ClientTupleKey `json:"successful"`
Failed []failedWriteResponse `json:"failed"`
}

// importTuples receives a client.ClientWriteRequest and imports the tuples to the store. It can be used to import
Expand Down Expand Up @@ -69,7 +70,7 @@ func importTuples(
}

successfulWrites, failedWrites := processWrites(response.Writes)
successfulDeletes, failedDeletes := processWrites(response.Deletes)
successfulDeletes, failedDeletes := processDeletes(response.Deletes)

result := importResponse{
Successful: append(successfulWrites, successfulDeletes...),
Expand All @@ -80,10 +81,10 @@ func importTuples(
}

func processWrites(
writes []client.ClientWriteSingleResponse,
) ([]client.ClientWriteRequestTupleKey, []failedWriteResponse) {
writes []client.ClientWriteRequestWriteResponse,
) ([]client.ClientTupleKey, []failedWriteResponse) {
var (
successfulWrites []client.ClientWriteRequestTupleKey
successfulWrites []client.ClientTupleKey
failedWrites []failedWriteResponse
)

Expand All @@ -101,6 +102,34 @@ func processWrites(
return successfulWrites, failedWrites
}

func processDeletes(
deletes []client.ClientWriteRequestDeleteResponse,
) ([]client.ClientTupleKey, []failedWriteResponse) {
var (
successfulDeletes []client.ClientTupleKey
failedDeletes []failedWriteResponse
)

for _, delete := range deletes {
deletedTupleKey := openfga.TupleKey{
Object: delete.TupleKey.Object,
Relation: delete.TupleKey.Relation,
User: delete.TupleKey.User,
}

if delete.Status == client.SUCCESS {
successfulDeletes = append(successfulDeletes, deletedTupleKey)
} else {
failedDeletes = append(failedDeletes, failedWriteResponse{
TupleKey: deletedTupleKey,
Reason: delete.Error.Error(),
})
}
}

return successfulDeletes, failedDeletes
}

// importCmd represents the import command.
var importCmd = &cobra.Command{
Use: "import",
Expand Down Expand Up @@ -131,7 +160,7 @@ var importCmd = &cobra.Command{
return fmt.Errorf("failed to parse parallel requests due to %w", err)
}

tuples := []client.ClientWriteRequestTupleKey{}
tuples := []client.ClientTupleKey{}

data, err := os.ReadFile(fileName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/tuple/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fga tuple write --store-id=01H0H015178Y2V4CX10C2KGHF4 --file tuples.yaml
return fmt.Errorf("failed to parse parallel requests due to %w", err)
}

var tuples []client.ClientWriteRequestTupleKey
var tuples []client.ClientTupleKey

data, err := os.ReadFile(fileName)
if err != nil {
Expand All @@ -83,7 +83,7 @@ fga tuple write --store-id=01H0H015178Y2V4CX10C2KGHF4 --file tuples.yaml
return output.Display(*response) //nolint:wrapcheck
}
body := &client.ClientWriteTuplesBody{
client.ClientWriteRequestTupleKey{
client.ClientTupleKey{
User: args[0],
Relation: args[1],
Object: args[2],
Expand Down
42 changes: 21 additions & 21 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/openfga/cli

go 1.21.3
go 1.21.4

require (
github.com/golang/mock v1.6.0
Expand All @@ -9,10 +9,10 @@ require (
github.com/muesli/roff v0.1.0
github.com/nwidger/jsoncolor v0.3.2
github.com/oklog/ulid/v2 v2.1.0
github.com/openfga/api/proto v0.0.0-20231013152440-fb9e0a84ee12
github.com/openfga/go-sdk v0.3.0-beta.1
github.com/openfga/language/pkg/go v0.0.0-20231103185736-f24a2a7b610b
github.com/openfga/openfga v1.4.0-rc1
github.com/openfga/api/proto v0.0.0-20231122192407-7f9be45ba22c
github.com/openfga/go-sdk v0.3.0-beta.1.0.20231127120042-25b92122948b
github.com/openfga/language/pkg/go v0.0.0-20231127150605-50a8baa6c11b
github.com/openfga/openfga v1.4.0-rc1.0.20231128174922-9d26b1a5f809
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.17.0
Expand All @@ -29,13 +29,13 @@ require (
github.com/envoyproxy/protoc-gen-validate v1.0.2 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/cel-go v0.17.3 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand All @@ -59,23 +59,23 @@ require (
github.com/spf13/cast v1.5.1 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/sdk v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect
golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 // indirect
golang.org/x/net v0.18.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 // indirect
google.golang.org/grpc v1.59.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
)
Loading

0 comments on commit b3a2254

Please sign in to comment.