Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
cache-dependency-path: './go.sum'
check-latest: true

- uses: anchore/sbom-action/download-syft@deef08a0db64bfad603422135db61477b16cef56 # v0.22.1
- uses: anchore/sbom-action/download-syft@28d71544de8eaf1b958d335707167c5f783590ad # v0.22.2

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@e435ccd777264be153ace6237001ef4d979d3a7a # v6.4.0
Expand Down Expand Up @@ -158,7 +158,7 @@ jobs:
with:
cosign-release: "v2.6.1"

- uses: anchore/sbom-action/download-syft@deef08a0db64bfad603422135db61477b16cef56 # v0.22.1
- uses: anchore/sbom-action/download-syft@28d71544de8eaf1b958d335707167c5f783590ad # v0.22.2

- name: Run GoReleaser
id: goreleaser
Expand Down
2 changes: 2 additions & 0 deletions cmd/model/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ var listCmd = &cobra.Command{
Example: "fga model list --store-id=01H0H015178Y2V4CX10C2KGHF4",
RunE: func(cmd *cobra.Command, _ []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA client due to %w", err)
Expand All @@ -96,6 +97,7 @@ var listCmd = &cobra.Command{
}

models := authorizationmodel.AuthzModelList{}

authzModels := response.AuthorizationModels
for index := range authzModels {
authModel := authorizationmodel.AuthzModel{}
Expand Down
10 changes: 10 additions & 0 deletions cmd/model/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ var modelTestCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("invalid tests pattern %s due to %w", testsFileName, err)
}

if len(fileNames) == 0 {
// Check if the literal path exists
if _, err := os.Stat(testsFileName); err != nil {
return fmt.Errorf("test file %s does not exist: %w", testsFileName, err)
}

fileNames = []string{testsFileName}
}

multipleFiles := len(fileNames) > 1

clientConfig := cmdutils.GetClientConfig(cmd)
Expand All @@ -80,6 +83,7 @@ var modelTestCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to read test file %s: %w", file, err)
}

test, err := storetest.RunTests(
cmd.Context(),
fgaClient,
Expand All @@ -94,19 +98,24 @@ var modelTestCmd = &cobra.Command{

if !suppressSummary && multipleFiles {
fullDisplay := test.FriendlyDisplay()

// Extract just the summary part (after "# Test Summary #")
headerIndex := strings.Index(fullDisplay, "# Test Summary #")

var summaryText string

if headerIndex != -1 {
// Get the summary part and remove the "# Test Summary #" header
summaryPart := fullDisplay[headerIndex:]
lines := strings.Split(summaryPart, "\n")

if len(lines) > 1 {
summaryText = strings.Join(lines[1:], "\n") // Skip the header line
}
} else {
summaryText = fullDisplay
}

summary := fmt.Sprintf("# file: %s\n%s", file, summaryText)
summaries = append(summaries, summary)
}
Expand All @@ -120,6 +129,7 @@ var modelTestCmd = &cobra.Command{
fmt.Fprintln(os.Stderr, summary)
}
}

fmt.Fprintln(os.Stderr, aggregateResults.FriendlyDisplay())
}

Expand Down
1 change: 1 addition & 0 deletions cmd/model/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ fga model transform --file=fga.mod`,
if err != nil {
return fmt.Errorf("failed to transform model due to %w", err)
}

fmt.Printf("%v", *dslModel)

return nil
Expand Down
1 change: 1 addition & 0 deletions cmd/query/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var checkCmd = &cobra.Command{
Args: cobra.ExactArgs(3), //nolint:mnd
RunE: func(cmd *cobra.Command, args []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
Expand Down
1 change: 1 addition & 0 deletions cmd/query/list-relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ var listRelationsCmd = &cobra.Command{
Args: cobra.ExactArgs(2), //nolint:mnd,lll
RunE: func(cmd *cobra.Command, args []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
Expand Down
1 change: 1 addition & 0 deletions cmd/query/list-users.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ var listUsersCmd = &cobra.Command{
Example: `fga query list-users --store-id=01H0H015178Y2V4CX10C2KGHF4 --object document:roadmap --relation can_view --consistency "HIGHER_CONSISTENCY"`, //nolint:lll
RunE: func(cmd *cobra.Command, _ []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
Expand Down
1 change: 1 addition & 0 deletions cmd/store/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export FGA_STORE_ID=$(fga store create --model Model.fga | jq -r .store.id)
RunE: func(cmd *cobra.Command, args []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)
storeName, _ := cmd.Flags().GetString("name")

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA Client: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions cmd/store/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ var deleteCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to parse force flag due to %w", err)
}

if !force {
confirmation, err := confirmation.AskForConfirmation("Are you sure you want to delete the store:")
if err != nil {
return fmt.Errorf("prompt failed due to %w", err)
}

if !confirmation {
type returnMessage struct {
Message string
Expand All @@ -59,6 +61,7 @@ var deleteCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

_, err = fgaClient.DeleteStore(context.Background()).Execute()
if err != nil {
return fmt.Errorf("failed to delete store %v due to %w", clientConfig.StoreID, err)
Expand Down
1 change: 1 addition & 0 deletions cmd/store/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ var exportCmd = &cobra.Command{
}

maxTupleCount, _ := cmd.Flags().GetUint("max-tuples")

storeData, err := buildStoreData(cmd.Context(), clientConfig, fgaClient, maxTupleCount)
if err != nil {
return fmt.Errorf("failed to export store: %w", err)
Expand Down
1 change: 1 addition & 0 deletions cmd/store/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var getCmd = &cobra.Command{
Example: "fga store get --store-id=01H0H015178Y2V4CX10C2KGHF4",
RunE: func(cmd *cobra.Command, _ []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
Expand Down
3 changes: 2 additions & 1 deletion cmd/store/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ var listCmd = &cobra.Command{
Example: "fga store list",
RunE: func(cmd *cobra.Command, _ []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

maxPages, _ := cmd.Flags().GetInt("max-pages")
maxPages, err := cmd.Flags().GetInt("max-pages")
if err != nil {
return fmt.Errorf("failed to parse max pages due to %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions cmd/tuple/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,25 @@ var deleteCmd = &cobra.Command{
fga tuple delete --store-id=01H0H015178Y2V4CX10C2KGHF4 --file tuples.csv --on-missing ignore`,
RunE: func(cmd *cobra.Command, args []string) error {
clientConfig := cmdutils.GetClientConfig(cmd)

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

fileName, err := cmd.Flags().GetString("file")
if err != nil {
return fmt.Errorf("failed to parse file name due to %w", err)
}

if fileName != "" {
startTime := time.Now()

clientTupleKeys, err := tuplefile.ReadTupleFile(fileName)
if err != nil {
return fmt.Errorf("failed to read file %s due to %w", fileName, err)
}

clientTupleKeyWithoutCondition := tuple.TupleKeysToTupleKeysWithoutCondition(clientTupleKeys...)

maxTuplesPerWrite, err := cmd.Flags().GetInt("max-tuples-per-write")
Expand Down Expand Up @@ -107,13 +111,15 @@ var deleteCmd = &cobra.Command{

return output.Display(outputResponse)
}

body := &client.ClientDeleteTuplesBody{
client.ClientTupleKeyWithoutCondition{
User: args[0],
Relation: args[1],
Object: args[2],
},
}

options := &client.ClientWriteOptions{}
if cmd.Flags().Changed("on-missing") {
options.Conflict.OnMissingDeletes = onMissingDeleteOption.ToSdkEnum()
Expand Down
5 changes: 4 additions & 1 deletion cmd/tuple/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var readCmd = &cobra.Command{
relation, _ := cmd.Flags().GetString("relation")
object, _ := cmd.Flags().GetString("object")

maxPages, _ := cmd.Flags().GetInt("max-pages")
maxPages, err := cmd.Flags().GetInt("max-pages")
if err != nil {
return fmt.Errorf("failed to parse max pages due to %w", err)
}
Expand All @@ -166,6 +166,7 @@ var readCmd = &cobra.Command{
if pageSize < 0 {
return fmt.Errorf("%w: got %d", ErrPageSizeNegative, pageSize)
}

if pageSize > 100 {
return fmt.Errorf("%w: got %d", ErrPageSizeExceedsMax, pageSize)
}
Expand Down Expand Up @@ -207,7 +208,9 @@ var readCmd = &cobra.Command{

return nil
}

var data any

data = *response.complete

if simpleOutput || outputFormat == "simple-json" {
Expand Down
2 changes: 2 additions & 0 deletions internal/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

// Package build provides build information that is linked into the application. Other
// packages within this project can use this information in logs etc..

//nolint:revive // package name conflicts with stdlib is acceptable here
package build

var (
Expand Down
2 changes: 2 additions & 0 deletions internal/slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ limitations under the License.
*/

// Package slices contains some functionality to make working with slices easier

//nolint:revive // package name conflicts with stdlib is acceptable here
package slices
Loading