From 2a957b198cffc9c87642a659d52fd0e2296936aa Mon Sep 17 00:00:00 2001 From: Neeraj Nagure Date: Tue, 16 Apr 2024 21:44:46 +0530 Subject: [PATCH] fga store import displays store and model details Signed-off-by: Neeraj Nagure --- cmd/store/import.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/cmd/store/import.go b/cmd/store/import.go index 2b0fbe8..ed9fe5a 100644 --- a/cmd/store/import.go +++ b/cmd/store/import.go @@ -41,12 +41,14 @@ func importStore( storeID string, maxTuplesPerWrite int, maxParallelRequests int, -) error { +) (*CreateStoreAndModelResponse, error) { var err error + var response *CreateStoreAndModelResponse if storeID == "" { createStoreAndModelResponse, err := CreateStoreWithModel(clientConfig, storeData.Name, storeData.Model, format) + response = createStoreAndModelResponse if err != nil { - return err + return nil, err } clientConfig.StoreID = createStoreAndModelResponse.Store.Id //nolint:wsl } else { @@ -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{ @@ -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. @@ -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") @@ -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) if err != nil { return err } - return output.Display(output.EmptyStruct{}) + return output.Display(createStoreAndModelResponse) }, }