Skip to content

Commit

Permalink
Adding cli opts
Browse files Browse the repository at this point in the history
  • Loading branch information
paulosuzart committed Feb 26, 2024
1 parent 567bfcc commit e276d95
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Contributions welcome!

It takes only two env variables at the moment `API_URL` and `STORE_ID`. The database will be stored in the current directory.
```shell
API_URL=https://myopenfga:8080 STORE_ID=03HME1444HSEY9022AENH1YYKFJ go run .
go run . -a https://myopenfga:8080 -s 03HME1444HSEY9022AENH1YYKFJ
```


Expand All @@ -27,3 +27,5 @@ So far I've made a risk decision to se FGA's [canges endpoint](https://openfga.d

It keeps the last state only, meaning all changes are applied locally but not kept, reducing the data that will be needed in general. This is not tested against billions of rows, which might be challenging, but for ordinary setups with millions of rows, this should be stable enough.

## High tuple volume
`fgamanger` was used with more than 1.3Mi tuples with no hiccups. This is possible employing [tview's virtual tables](https://github.com/rivo/tview/wiki/VirtualTable).
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/paulosuzart/fgamanager
go 1.21.6

require (
github.com/akamensky/argparse v1.4.0
github.com/gdamore/tcell/v2 v2.7.0
github.com/ggwhite/go-masker v1.1.0
github.com/jmoiron/sqlx v1.3.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/akamensky/argparse v1.4.0 h1:YGzvsTqCvbEZhL8zZu2AiA5nq805NZh75JNj4ajn1xc=
github.com/akamensky/argparse v1.4.0/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA=
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.7.0 h1:I5LiGTQuwrysAt1KS9wg1yFfOI3arI3ucFrxtd/xqaA=
Expand Down
28 changes: 17 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ package main

import (
"context"
"fmt"
"github.com/akamensky/argparse"
openfga "github.com/openfga/go-sdk"
"github.com/paulosuzart/fgamanager/db"
"github.com/rivo/tview"
"log"
"net/url"
"os"
)

var apiUrl = "http://localhost:8087"
var storeId = ""
var (
parser = argparse.NewParser("fgamanager", "fgamanager")
apiUrl = parser.String("a", "apiUrl", &argparse.Options{Default: "http://localhost:8087"})
storeId = parser.String("s", "storeId", &argparse.Options{Required: true})
)

func init() {
if _apiUrl := os.Getenv("API_URL"); _apiUrl != "" {
apiUrl = _apiUrl
err := parser.Parse(os.Args)
if err != nil {
fmt.Printf("Error: %v", err)
os.Exit(1)
}

if _storeId := os.Getenv("STORE_ID"); _storeId != "" {
storeId = _storeId
} else {
panic("Store id must be provided via STORE_ID env")
if _, err := url.Parse(*apiUrl); err != nil {
panic("Api URL is malformed")
os.Exit(1)
}
}

Expand Down Expand Up @@ -59,8 +65,8 @@ func main() {
defer db.Close()

configuration, err := openfga.NewConfiguration(openfga.Configuration{
ApiUrl: apiUrl,
StoreId: storeId,
ApiUrl: *apiUrl,
StoreId: *storeId,
})
fgaClient = openfga.NewAPIClient(configuration)

Expand Down
4 changes: 2 additions & 2 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,12 @@ func AddComponents(context context.Context, app *tview.Application) *tview.Grid

infoTable.SetCell(1, 0, tview.NewTableCell("Server:").
SetTextColor(tcell.ColorDarkOrange).SetMaxWidth(60))
infoTable.SetCell(1, 1, tview.NewTableCell(apiUrl))
infoTable.SetCell(1, 1, tview.NewTableCell(*apiUrl))

infoTable.SetCell(1, 2, tview.NewTableCell("StoreId:").
SetTextColor(tcell.ColorDarkOrange))

infoTable.SetCell(1, 3, tview.NewTableCell(masker.ID(storeId)))
infoTable.SetCell(1, 3, tview.NewTableCell(masker.ID(*storeId)))

infoTable.SetCell(1, 4, tview.NewTableCell("Continuation Token:").
SetTextColor(tcell.ColorDarkOrange))
Expand Down

0 comments on commit e276d95

Please sign in to comment.