Skip to content

Commit

Permalink
fix: update based on code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
adriantam committed Jun 30, 2023
1 parent 9d22f32 commit a4f82bf
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 49 deletions.
6 changes: 0 additions & 6 deletions cmd/models/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,11 @@ func getModel(clientConfig fga.ClientConfig, fgaClient client.SdkClient) (string
}

if err != nil {
fmt.Printf("Failed to get model %v due to %v", clientConfig.AuthorizationModelID, err)

return "", fmt.Errorf("failed to get model %v due to %w", clientConfig.AuthorizationModelID, err)
}

modelJSON, err := json.Marshal(model)
if err != nil {
fmt.Printf("Failed to get model due to %v", err)

return "", fmt.Errorf("failed to get model due to %w", err)
}

Expand All @@ -69,8 +65,6 @@ var getCmd = &cobra.Command{

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
fmt.Printf("Failed to initialize FGA Client due to %v", err)

return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}
output, err := getModel(clientConfig, fgaClient)
Expand Down
10 changes: 1 addition & 9 deletions cmd/models/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ func listModels(fgaClient client.SdkClient, maxPages int) (string, error) {

response, err := fgaClient.ReadAuthorizationModels(context.Background()).Options(options).Execute()
if err != nil {
fmt.Printf("XXX Failed to list models due to %v", err)

return "", fmt.Errorf("xxx failed to list models due to %w", err)
return "", fmt.Errorf("failed to list models due to %w", err)
}

models = append(models, *response.AuthorizationModels...)
Expand All @@ -62,8 +60,6 @@ func listModels(fgaClient client.SdkClient, maxPages int) (string, error) {

modelsJSON, err := json.Marshal(openfga.ReadAuthorizationModelsResponse{AuthorizationModels: &models})
if err != nil {
fmt.Printf("Failed to marshal listed models due to %v", err)

return "", fmt.Errorf("failed to marshal listed models due to %w", err)
}

Expand All @@ -78,14 +74,10 @@ var listCmd = &cobra.Command{
clientConfig := cmdutils.GetClientConfig(cmd)
fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
fmt.Printf("Failed to initialize FGA Client due to %v", err)

return fmt.Errorf("failed to intialized FGA client due to %w", err)
}
maxPages, err := cmd.Flags().GetInt("max-pages")
if err != nil {
fmt.Printf("Failed to list models due to %v", err)

return fmt.Errorf("failed to list models due to %w", err)
}
output, err := listModels(fgaClient, maxPages)
Expand Down
8 changes: 0 additions & 8 deletions cmd/models/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,16 @@ func write(fgaClient client.SdkClient, text string) (string, error) {

err := json.Unmarshal([]byte(text), &body)
if err != nil {
fmt.Printf("Failed to parse model due to %v", err)

return "", fmt.Errorf("failed to parse model due to %w", err)
}

model, err := fgaClient.WriteAuthorizationModel(context.Background()).Body(*body).Execute()
if err != nil {
fmt.Printf("Failed to write model due to %v", err)

return "", fmt.Errorf("failed to write model due to %w", err)
}

modelJSON, err := json.Marshal(model)
if err != nil {
fmt.Printf("Failed to write model due to %v", err)

return "", fmt.Errorf("failed to write model due to %w", err)
}

Expand All @@ -62,8 +56,6 @@ var writeCmd = &cobra.Command{

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
fmt.Printf("Failed to initialize FGA Client due to %v", err)

return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

Expand Down
6 changes: 0 additions & 6 deletions cmd/query/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,11 @@ func check(fgaClient client.SdkClient, user string, relation string, object stri

response, err := fgaClient.Check(context.Background()).Body(*body).Options(*options).Execute()
if err != nil {
fmt.Printf("Failed to check due to %v", err)

return "", fmt.Errorf("failed to check due to %w", err)
}

responseJSON, err := json.Marshal(response)
if err != nil {
fmt.Printf("Failed to check due to %v", err)

return "", fmt.Errorf("failed to check due to %w", err)
}

Expand All @@ -60,8 +56,6 @@ var checkCmd = &cobra.Command{
clientConfig := cmdutils.GetClientConfig(cmd)
fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
fmt.Printf("Failed to initialize FGA Client due to %v", err)

return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

Expand Down
6 changes: 0 additions & 6 deletions cmd/query/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ func expand(fgaClient client.SdkClient, relation string, object string) (string,

tuples, err := fgaClient.Expand(context.Background()).Body(*body).Execute()
if err != nil {
fmt.Printf("Failed to expand tuples due to %v", err)

return "", fmt.Errorf("failed to expand tuples due to %w", err)
}

tuplesJSON, err := json.Marshal(tuples)
if err != nil {
fmt.Printf("Failed to expand tuples due to %v", err)

return "", fmt.Errorf("failed to expand tuples due to %w", err)
}

Expand All @@ -59,8 +55,6 @@ var expandCmd = &cobra.Command{

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
fmt.Printf("Failed to initialize FGA Client due to %v", err)

return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

Expand Down
6 changes: 0 additions & 6 deletions cmd/query/list-objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ func listObjects(fgaClient client.SdkClient, user string, relation string, types

response, err := fgaClient.ListObjects(context.Background()).Body(*body).Options(*options).Execute()
if err != nil {
fmt.Printf("Failed to list objects due to %v", err)

return "", fmt.Errorf("failed to list objects due to %w", err)
}

responseJSON, err := json.Marshal(response)
if err != nil {
fmt.Printf("Failed to list objects due to %v", err)

return "", fmt.Errorf("failed to list objects due to %w", err)
}

Expand All @@ -62,8 +58,6 @@ var listObjectsCmd = &cobra.Command{

fgaClient, err := clientConfig.GetFgaClient()
if err != nil {
fmt.Printf("Failed to initialize FGA Client due to %v", err)

return fmt.Errorf("failed to initialize FGA Client due to %w", err)
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/query/list-relations.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ func listRelations(clientConfig fga.ClientConfig,
// note that the auth model id is already configured in the fgaClient.
response, err := fgaClient.ReadAuthorizationModel(context.Background()).Execute()
if err != nil {
fmt.Printf("Failed to list relations due to %v", err)

return "", fmt.Errorf("failed to list relations due to %w", err)
}

authorizationModel = *response.AuthorizationModel
} else {
response, err := fgaClient.ReadLatestAuthorizationModel(context.Background()).Execute()
if err != nil {
fmt.Printf("Failed to list relations due to %v", err)

return "", fmt.Errorf("failed to list relations due to %w", err)
}

Expand Down Expand Up @@ -81,15 +77,11 @@ func listRelations(clientConfig fga.ClientConfig,

response, err := fgaClient.ListRelations(context.Background()).Body(*body).Options(*options).Execute()
if err != nil {
fmt.Printf("Failed to list relations due to %v", err)

return "", fmt.Errorf("failed to list relations due to %w", err)
}

responseJSON, err := json.Marshal(response)
if err != nil {
fmt.Printf("Failed to list relations due to %v", err)

return "", fmt.Errorf("failed to list relations due to %w", err)
}

Expand Down

0 comments on commit a4f82bf

Please sign in to comment.