Skip to content

Commit

Permalink
fga store import displays store and model details
Browse files Browse the repository at this point in the history
Signed-off-by: Neeraj Nagure <[email protected]>
  • Loading branch information
NeerajNagure committed Apr 16, 2024
1 parent f62751c commit 2a957b1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions cmd/store/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ func importStore(
storeID string,
maxTuplesPerWrite int,
maxParallelRequests int,
) error {
) (*CreateStoreAndModelResponse, error) {
var err error
var response *CreateStoreAndModelResponse

Check failure on line 46 in cmd/store/import.go

View workflow job for this annotation

GitHub Actions / Lints

declarations should never be cuddled (wsl)
if storeID == "" {

Check failure on line 47 in cmd/store/import.go

View workflow job for this annotation

GitHub Actions / Lints

only one cuddle assignment allowed before if statement (wsl)
createStoreAndModelResponse, err := CreateStoreWithModel(clientConfig, storeData.Name, storeData.Model, format)
response = createStoreAndModelResponse
if err != nil {

Check failure on line 50 in cmd/store/import.go

View workflow job for this annotation

GitHub Actions / Lints

only one cuddle assignment allowed before if statement (wsl)
return err
return nil, err
}
clientConfig.StoreID = createStoreAndModelResponse.Store.Id //nolint:wsl
} else {
Expand All @@ -55,18 +57,18 @@ func importStore(

err = authModel.ReadModelFromString(storeData.Model, format)
if err != nil {
return err //nolint:wrapcheck
return nil, err //nolint:wrapcheck
}

_, err := model.Write(fgaClient, authModel)
if err != nil {
return fmt.Errorf("failed to write model due to %w", err)
return nil, fmt.Errorf("failed to write model due to %w", err)
}
}

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

writeRequest := client.ClientWriteRequest{
Expand All @@ -75,10 +77,10 @@ func importStore(

_, err = tuple.ImportTuples(fgaClient, writeRequest, maxTuplesPerWrite, maxParallelRequests)
if err != nil {
return err //nolint:wrapcheck
return nil, err //nolint:wrapcheck
}

return nil
return response, nil
}

// importCmd represents the get command.
Expand All @@ -88,6 +90,7 @@ var importCmd = &cobra.Command{
Long: `Import a store: updating the name, model and appending the global tuples`,
Example: "fga store import --file=model.fga.yaml",
RunE: func(cmd *cobra.Command, _ []string) error {
var createStoreAndModelResponse *CreateStoreAndModelResponse
clientConfig := cmdutils.GetClientConfig(cmd)

storeID, err := cmd.Flags().GetString("store-id")
Expand Down Expand Up @@ -120,12 +123,12 @@ var importCmd = &cobra.Command{
return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

err = importStore(clientConfig, fgaClient, storeData, format, storeID, maxTuplesPerWrite, maxParallelRequests)
createStoreAndModelResponse, err = importStore(clientConfig, fgaClient, storeData, format, storeID, maxTuplesPerWrite, maxParallelRequests)

Check failure on line 126 in cmd/store/import.go

View workflow job for this annotation

GitHub Actions / Lints

line is 141 characters (lll)
if err != nil {
return err
}

return output.Display(output.EmptyStruct{})
return output.Display(createStoreAndModelResponse)
},
}

Expand Down

0 comments on commit 2a957b1

Please sign in to comment.