Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support importing assertions along with the store #224

Open
poovamraj opened this issue Jan 12, 2024 · 12 comments
Open

Support importing assertions along with the store #224

poovamraj opened this issue Jan 12, 2024 · 12 comments
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest

Comments

@poovamraj
Copy link
Contributor

Currently we support importing a store file using

fga import store --file=store.fga.yaml

But this doesn't import the assertions present along with the store.

Importing the assertions can be helpful to be accessed from the playground and do the checks.

@poovamraj poovamraj added enhancement New feature or request good first issue Good for newcomers labels Jan 12, 2024
@rhamzeh rhamzeh added the on-hold On Hold - Not ready yet label Jan 12, 2024
@m3talsmith m3talsmith self-assigned this Feb 7, 2024
@rhamzeh rhamzeh moved this to Backlog in SDKs and Tooling Feb 9, 2024
@rhamzeh
Copy link
Member

rhamzeh commented Feb 9, 2024

@KamalAman
Copy link

I would also love a fga model test --upload command to upload the assertions into the playground

@rhamzeh rhamzeh added hacktoberfest and removed on-hold On Hold - Not ready yet labels Sep 25, 2024
@sujitha-av
Copy link

Hey all, when we are talking about importing assertions, it is only the check assertions right? since that is the only type that can be created/accessed from the playground.

@aaguiarz
Copy link
Member

Yes, you'd convert check tests to assertions.

@sujitha-av
Copy link

Yes, you'd convert check tests to assertions.

Yes, but then there are other assertion types too like the listObjects and listUsers assertions. Do we import them too

  1. They are not supported in the playground
  2. The WriteAssertions API only supports check assertions. Should we do this first and support the other types of assertions too?

@aaguiarz
Copy link
Member

No, they should be ignored for now. We should only import assertions for Check

@sujitha-av
Copy link

Hello, I need some help with this:
Was trying to test the import function. Realised that we create another fgaClient midway here in CreateStoreWithModel -

cli/cmd/store/create.go

Lines 50 to 59 in 6c3b7aa

func CreateStoreWithModel(
clientConfig fga.ClientConfig,
storeName string,
inputModel string,
inputFormat authorizationmodel.ModelFormat,
) (*CreateStoreAndModelResponse, error) {
fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
return nil, fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

I tried to refactor it here - sujitha-av@df157a1
But CreateStoreWithModel requires a *client.OpenFgaClient due to this line
err = fgaClient.SetStoreId(response.Store.Id)

The problem is there is a mock for client of type client.SdkClient but not for OpenFgaClient which implements it and has extra methods like SetStoreId. Any help on how to proceed is appreciated, thanks!

@ewanharris
Copy link
Member

@sujitha-av I just opened a PR in the go-sdk to add the getter/setter for Store ID to the SdkClient interface so that the generated mock will then include that method. I'll ask the team to review this to make sure it's correct.

We need to maintain the SetStoreId method usage because when we create a store we need to ensure that the OpenFGAClient is updated to use the ID from the store created in CreateStoreWithModel in subsequent API calls.

@sujitha-av
Copy link

Sure, thank you!

@ewanharris
Copy link
Member

@sujitha-av FYI we just merged #436 to main that updates the go-sdk to include that change to the interface and generate the mocks. If you pull and update your branch that mock should now the SetStoreId method.

@ewanharris
Copy link
Member

Hey @sujitha-av, I just wanted to check in and see if there's any assistance we can provide. If the work is complete and you're just needing to add tests, feel free to open a PR as the testing in this project isn't necessarily the most straight forward due to mocking etc.

@sujitha-av
Copy link

Thanks @ewanharris. Yep, got carried away in testing other parts of import. I have opened a PR for just this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers hacktoberfest
Projects
Status: Backlog
Development

No branches or pull requests

8 participants