Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9.3.0
with:
version: v2.12.2
version: v2.13.2
args: -v -c .golangci.yaml

audit:
Expand Down
72 changes: 37 additions & 35 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@ run:
modules-download-mode: readonly
allow-parallel-runners: true
linters:
default: all
disable:
- dupl
- exhaustruct
- forbidigo
- gochecknoglobals
- gochecknoinits
- goconst
- mnd
- testpackage
- usetesting
- noinlineerr
- wsl
default: none
enable:
- bodyclose
- copyloopvar
- errcheck
- errname
- gocritic
- govet
- ineffassign
- revive
- staticcheck
- unused
- unconvert
- unparam
- wastedassign
- whitespace
- godot
- importas
Comment thread
curfew-marathon marked this conversation as resolved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
- depguard
settings:
govet: { enable-all: true, disable: [shadow, fieldalignment] }
staticcheck: { checks: [all] }
gocritic: { disabled-checks: [ifElseChain] }
revive:
rules:
- { name: package-comments, disabled: true }
importas:
no-unaliased: true
alias:
- { pkg: github.com/openfga/api/proto/openfga/v1, alias: openfgav1 }
depguard:
rules:
main:
Expand Down Expand Up @@ -66,18 +82,6 @@ linters:
- github.com/spf13/cobra
- github.com/spf13/viper
- google.golang.org/protobuf/proto
funlen:
lines: 120
statements: 80
tagliatelle:
case:
rules:
json: snake
use-field-name: true
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
exclusions:
generated: lax
presets:
Expand All @@ -86,18 +90,15 @@ linters:
- legacy
- std-error-handling
rules:
- linters:
- lll
path: cmd/tuple/write(.*).go
- linters:
- err113
- funlen
- lll
path: _test.go
- linters:
- revive
- { linters: [errcheck, bodyclose], path: (.+)_test.go }
- { linters: [errcheck], source: ^\s*defer\s+ }
- linters: [revive]
text: "avoid package names that conflict with Go standard library package names"
path: internal/slices
# gofumpt v0.11.0 (bundled in golangci-lint v2.13.2) mis-indents the
# multi-return composite literal here; remove when golangci-lint bundles
# gofumpt >= v0.12.0. See openfga/cli#750.
- { linters: [gofumpt], path: internal/storetest/conversion.go }
paths:
- third_party$
- builtin$
Expand All @@ -108,6 +109,7 @@ formatters:
- gofumpt
- goimports
settings:
gofmt: { simplify: true }
goimports:
local-prefixes:
- github.com/openfga/cli
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MOCK_SRC_DIR ?= mocks
#-----------------------------------------------------------------------------------------------------------------------
$(GO_BIN)/golangci-lint:
@echo "==> Installing golangci-lint within "${GO_BIN}""
@go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.12.2
@go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2
Comment thread
curfew-marathon marked this conversation as resolved.

$(GO_BIN)/govulncheck:
@echo "==> Installing govulncheck within "${GO_BIN}""
Expand Down
4 changes: 2 additions & 2 deletions cmd/model/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"time"

"github.com/oklog/ulid/v2"
pb "github.com/openfga/api/proto/openfga/v1"
openfgav1 "github.com/openfga/api/proto/openfga/v1"
openfga "github.com/openfga/go-sdk"
"github.com/openfga/openfga/pkg/typesystem"
"github.com/spf13/cobra"
Expand All @@ -41,7 +41,7 @@ type validationResult struct {
}

func validate(inputModel authorizationmodel.AuthzModel) validationResult {
model := &pb.AuthorizationModel{}
model := &openfgav1.AuthorizationModel{}
output := validationResult{
IsValid: true,
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/query/expand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestExpandWithNoError(t *testing.T) {
t.Error(err)
}

if !(reflect.DeepEqual(*output, expectedResponse)) {
if !reflect.DeepEqual(*output, expectedResponse) {
t.Errorf("Expect output response %v actual response %v", expandResponseTxt, *output)
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestExpandWithConsistency(t *testing.T) {
t.Error(err)
}

if !(reflect.DeepEqual(*output, expectedResponse)) {
if !reflect.DeepEqual(*output, expectedResponse) {
t.Errorf("Expect output response %v actual response %v", expandResponseTxt, *output)
}
}
2 changes: 1 addition & 1 deletion cmd/query/list-relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func getRelationsForType(
}

typeDefs := authorizationModel.TypeDefinitions
objectType := strings.Split(object, ":")[0]
objectType, _, _ := strings.Cut(object, ":")
relations := []string{}

for index := range typeDefs {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/openfga/cli

go 1.26.0
go 1.26.0 // floor: support one version back; run with the latest (toolchain below)

toolchain go1.26.6
toolchain go1.27.1

require (
github.com/charmbracelet/huh v1.0.0
Expand Down
10 changes: 5 additions & 5 deletions internal/authorizationmodel/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"time"

"github.com/oklog/ulid/v2"
pb "github.com/openfga/api/proto/openfga/v1"
openfgav1 "github.com/openfga/api/proto/openfga/v1"
openfga "github.com/openfga/go-sdk"
language "github.com/openfga/language/pkg/go/transformer"
"google.golang.org/protobuf/encoding/protojson"
Expand Down Expand Up @@ -120,12 +120,12 @@ func (model *AuthzModel) GetConditions() *map[string]openfga.Condition {
return &conditions
}

func (model *AuthzModel) GetProtoModel() *pb.AuthorizationModel {
func (model *AuthzModel) GetProtoModel() *openfgav1.AuthorizationModel {
if model == nil {
return nil
}

var pbModel pb.AuthorizationModel
var pbModel openfgav1.AuthorizationModel

jsonModel, err := model.GetAsJSONString()
if err != nil {
Expand All @@ -145,7 +145,7 @@ func (model *AuthzModel) GetSizeInKB() float64 {

// ProtoModelSizeInKB returns the protobuf-serialized size of the model in KB,
// rounded to two decimal places. Returns 0 for a nil model.
func ProtoModelSizeInKB(pbModel *pb.AuthorizationModel) float64 {
func ProtoModelSizeInKB(pbModel *openfgav1.AuthorizationModel) float64 {
if pbModel == nil {
return 0
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func (model *AuthzModel) DisplayAsJSON(fields []string) AuthzModel {
}

func (model *AuthzModel) DisplayAsDSL(fields []string) (*string, error) {
modelPb := pb.AuthorizationModel{}
modelPb := openfgav1.AuthorizationModel{}

if len(fields) < 1 {
fields = append(fields, "model")
Expand Down
2 changes: 1 addition & 1 deletion internal/fga/fga.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var (
)

type ClientConfig struct {
ApiUrl string `json:"api_url,omitempty"` //nolint:revive,stylecheck
ApiUrl string `json:"api_url,omitempty"` //nolint:revive,staticcheck
StoreID string `json:"store_id,omitempty"`
AuthorizationModelID string `json:"authorization_model_id,omitempty"`
APIToken string `json:"api_token,omitempty"`
Expand Down
32 changes: 16 additions & 16 deletions internal/storetest/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import (
"fmt"
"strings"

pb "github.com/openfga/api/proto/openfga/v1"
openfgav1 "github.com/openfga/api/proto/openfga/v1"
openfga "github.com/openfga/go-sdk"
"github.com/openfga/go-sdk/client"
"google.golang.org/protobuf/types/known/structpb"
)

func convertClientTupleKeysToProtoTupleKeys(
tuples []client.ClientContextualTupleKey,
) ([]*pb.TupleKey, error) {
pbTuples := []*pb.TupleKey{}
) ([]*openfgav1.TupleKey, error) {
pbTuples := []*openfgav1.TupleKey{}

for _, tuple := range tuples {
tpl := pb.TupleKey{
tpl := openfgav1.TupleKey{
User: tuple.User,
Relation: tuple.Relation,
Object: tuple.Object,
Expand All @@ -28,7 +28,7 @@ func convertClientTupleKeysToProtoTupleKeys(
return nil, fmt.Errorf("failed to construct a proto struct: %w", err)
}

tpl.Condition = &pb.RelationshipCondition{
tpl.Condition = &openfgav1.RelationshipCondition{
Name: tuple.Condition.Name,
Context: conditionContext,
}
Expand All @@ -40,31 +40,31 @@ func convertClientTupleKeysToProtoTupleKeys(
return pbTuples, nil
}

func convertStoreObjectToObject(object string) (openfga.FgaObject, *pb.Object) {
func convertStoreObjectToObject(object string) (openfga.FgaObject, *openfgav1.Object) {
splitObject := strings.Split(object, ":")

return openfga.FgaObject{
Type: splitObject[0],
Id: splitObject[1],
}, &pb.Object{
Type: splitObject[0],
Id: splitObject[1],
}
Type: splitObject[0],
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Id: splitObject[1],
Comment thread
curfew-marathon marked this conversation as resolved.
}, &openfgav1.Object{
Type: splitObject[0],
Id: splitObject[1],
}
}

func convertPbUsersToStrings(users []*pb.User) []string {
func convertPbUsersToStrings(users []*openfgav1.User) []string {
simpleUsers := []string{}

for _, user := range users {
switch typedUser := user.GetUser().(type) {
case *pb.User_Object:
case *openfgav1.User_Object:
simpleUsers = append(simpleUsers, typedUser.Object.GetType()+":"+typedUser.Object.GetId())
case *pb.User_Userset:
case *openfgav1.User_Userset:
simpleUsers = append(
simpleUsers,
typedUser.Userset.GetType()+":"+typedUser.Userset.GetId()+"#"+typedUser.Userset.GetRelation(),
)
case *pb.User_Wildcard:
case *openfgav1.User_Wildcard:
simpleUsers = append(simpleUsers, typedUser.Wildcard.GetType()+":*")
}
}
Expand Down
20 changes: 10 additions & 10 deletions internal/storetest/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package storetest
import (
"testing"

pb "github.com/openfga/api/proto/openfga/v1"
openfgav1 "github.com/openfga/api/proto/openfga/v1"
openfga "github.com/openfga/go-sdk"
"github.com/openfga/go-sdk/client"
"github.com/stretchr/testify/assert"
Expand All @@ -14,19 +14,19 @@ func TestConvertPbUsersToStrings(t *testing.T) {
t.Parallel()

tests := map[string]struct {
input *pb.User
input *openfgav1.User
expected string
}{
"User_Object": {
input: &pb.User{User: &pb.User_Object{Object: &pb.Object{Type: "user", Id: "anne"}}},
input: &openfgav1.User{User: &openfgav1.User_Object{Object: &openfgav1.Object{Type: "user", Id: "anne"}}},
expected: "user:anne",
},
"User_Userset": {
input: &pb.User{User: &pb.User_Userset{Userset: &pb.UsersetUser{Type: "group", Id: "fga", Relation: "member"}}},
input: &openfgav1.User{User: &openfgav1.User_Userset{Userset: &openfgav1.UsersetUser{Type: "group", Id: "fga", Relation: "member"}}},
expected: "group:fga#member",
},
"User_Wildcard": {
input: &pb.User{User: &pb.User_Wildcard{Wildcard: &pb.TypedWildcard{Type: "user"}}},
input: &openfgav1.User{User: &openfgav1.User_Wildcard{Wildcard: &openfgav1.TypedWildcard{Type: "user"}}},
expected: "user:*",
},
}
Expand All @@ -35,7 +35,7 @@ func TestConvertPbUsersToStrings(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := convertPbUsersToStrings([]*pb.User{testcase.input})
got := convertPbUsersToStrings([]*openfgav1.User{testcase.input})

assert.Equal(t, []string{testcase.expected}, got)
})
Expand Down Expand Up @@ -80,12 +80,12 @@ func TestConvertStoreObjectToObject(t *testing.T) {
tests := map[string]struct {
input string
expectedFGAObject openfga.FgaObject
expectedPBObject *pb.Object
expectedPBObject *openfgav1.Object
}{
"Converts object": {
input: "document:roadmap",
expectedFGAObject: openfga.FgaObject{Type: "document", Id: "roadmap"},
expectedPBObject: &pb.Object{Type: "document", Id: "roadmap"},
expectedPBObject: &openfgav1.Object{Type: "document", Id: "roadmap"},
},
}

Expand All @@ -106,13 +106,13 @@ func TestConvertClientTupleKeysToProtoTupleKeys(t *testing.T) {

tests := map[string]struct {
input []client.ClientContextualTupleKey
expected []*pb.TupleKey
expected []*openfgav1.TupleKey
}{
"User_Object": {
input: []client.ClientContextualTupleKey{
{User: "user:anne", Relation: "owner", Object: "folder:product"},
},
expected: []*pb.TupleKey{
expected: []*openfgav1.TupleKey{
{User: "user:anne", Relation: "owner", Object: "folder:product"},
},
},
Expand Down
Loading
Loading