Skip to content

Commit

Permalink
feat: fga store import displays the generated store and model details (
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Apr 17, 2024
2 parents f62751c + afc6c91 commit 053d925
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 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
if storeID == "" {
var response *CreateStoreAndModelResponse //nolint:wsl
if storeID == "" { //nolint:wsl
createStoreAndModelResponse, err := CreateStoreWithModel(clientConfig, storeData.Name, storeData.Model, format)
if err != nil {
return err
response = createStoreAndModelResponse
if err != nil { //nolint:wsl
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,13 @@ 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)
if err != nil {
return err
}

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

Expand Down

0 comments on commit 053d925

Please sign in to comment.