diff --git a/README.md b/README.md index b38ff51..26e2a65 100644 --- a/README.md +++ b/README.md @@ -655,7 +655,7 @@ type document | [Write Relationship Tuples](#write-relationship-tuples) | `write` | `--store-id`, `--model-id` | `fga tuple write user:anne can_view document:roadmap --store-id=01H0H015178Y2V4CX10C2KGHF4` | | [Delete Relationship Tuples](#delete-relationship-tuples) | `delete` | `--store-id`, `--model-id` | `fga tuple delete user:anne can_view document:roadmap --store-id=01H0H015178Y2V4CX10C2KGHF4` | | [Read Relationship Tuples](#read-relationship-tuples) | `read` | `--store-id`, `--model-id` | `fga tuple read --store-id=01H0H015178Y2V4CX10C2KGHF4 --model-id=01GXSA8YR785C4FYS3C0RTG7B1` | -| [Read Relationship Tuple Changes (Watch)](#read-relationship-tuple-changes-watch) | `changes` | `--store-id`, `--type`, `--continuation-token`, | `fga tuple changes --store-id=01H0H015178Y2V4CX10C2KGHF4 --type=document --continuation-token=M3w=` | +| [Read Relationship Tuple Changes (Watch)](#read-relationship-tuple-changes-watch) | `changes` | `--store-id`, `--type`, `--start-time`, `--continuation-token`, | `fga tuple changes --store-id=01H0H015178Y2V4CX10C2KGHF4 --type=document --start-time=2022-01-01T00:00:00Z --continuation-token=M3w=` | | [Import Relationship Tuples](#import-relationship-tuples) | `import` | `--store-id`, `--model-id`, `--file` | `fga tuple import --store-id=01H0H015178Y2V4CX10C2KGHF4 --model-id=01GXSA8YR785C4FYS3C0RTG7B1 --file tuples.json` | ##### Write Relationship Tuples @@ -896,6 +896,7 @@ fga tuple **changes** --type --store-id= ###### Parameters * `--store-id`: Specifies the store id * `--type`: Restrict to a specific type (optional) +* `--start-time`: Return changes since a specified time * `--max-pages`: Max number of pages to retrieve (default: 20) * `--continuation-token`: Continuation token to start changes from diff --git a/cmd/tuple/changes.go b/cmd/tuple/changes.go index 1a3fab0..c2eab9c 100644 --- a/cmd/tuple/changes.go +++ b/cmd/tuple/changes.go @@ -32,14 +32,15 @@ import ( var MaxReadChangesPagesLength = 20 func readChanges( - fgaClient client.SdkClient, maxPages int, selectedType string, continuationToken string, + fgaClient client.SdkClient, maxPages int, selectedType string, startTime string, continuationToken string, ) (*openfga.ReadChangesResponse, error) { changes := []openfga.TupleChange{} pageIndex := 0 for { body := &client.ClientReadChangesRequest{ - Type: selectedType, + Type: selectedType, + StartTime: startTime, } options := &client.ClientReadChangesOptions{ ContinuationToken: &continuationToken, @@ -70,7 +71,7 @@ var changesCmd = &cobra.Command{ Use: "changes", Short: "Read Relationship Tuple Changes (Watch)", Long: "Get a list of relationship tuple changes (Writes and Deletes) across time.", - Example: "fga tuple changes --store-id=01H0H015178Y2V4CX10C2KGHF4 --type document --continuation-token=MXw=", + Example: "fga tuple changes --store-id=01H0H015178Y2V4CX10C2KGHF4 --type document --start-time 2022-01-01T00:00:00Z --continuation-token=MXw=", RunE: func(cmd *cobra.Command, _ []string) error { clientConfig := cmdutils.GetClientConfig(cmd) @@ -89,12 +90,17 @@ var changesCmd = &cobra.Command{ return fmt.Errorf("failed to get tuple changes due to %w", err) } + startTime, err := cmd.Flags().GetString("start-time") + if err != nil { + return fmt.Errorf("failed to get tuple changes due to %w", err) + } + continuationToken, err := cmd.Flags().GetString("continuation-token") if err != nil { return fmt.Errorf("failed to get tuple changes due to %w", err) } - response, err := readChanges(fgaClient, maxPages, selectedType, continuationToken) + response, err := readChanges(fgaClient, maxPages, selectedType, startTime, continuationToken) if err != nil { return err } @@ -105,6 +111,7 @@ var changesCmd = &cobra.Command{ func init() { changesCmd.Flags().String("type", "", "Type to restrict the changes by.") + changesCmd.Flags().String("start-time", "", "Time to return changes since.") changesCmd.Flags().Int("max-pages", MaxReadChangesPagesLength, "Max number of pages to get.") changesCmd.Flags().String("continuation-token", "", "Continuation token to start changes from.") }