Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,21 +445,18 @@ type SdkClient interface {
*/
SetAuthorizationModelId(authorizationModelId string) error


/*
* GetAuthorizationModelId retrieves the Authorization Model ID for an OpenFGAClient.
* @return string
*/
GetAuthorizationModelId() (string, error)


/*
* SetStoreId allows setting the Store ID for an OpenFGAClient.
* @param string storeId - The Store ID to set.
*/
SetStoreId(storeId string) error


/*
* GetStoreId retrieves the Store ID set in the OpenFGAClient.
* @return string
Expand Down Expand Up @@ -1605,6 +1602,7 @@ func (client *OpenFgaClient) WriteExecute(request SdkClientWriteRequestInterface
},
options: &ClientWriteOptions{
AuthorizationModelId: authorizationModelId,
StoreId: request.GetStoreIdOverride(),
},
})

Expand Down Expand Up @@ -1648,6 +1646,7 @@ func (client *OpenFgaClient) WriteExecute(request SdkClientWriteRequestInterface
},
options: &ClientWriteOptions{
AuthorizationModelId: authorizationModelId,
StoreId: request.GetStoreIdOverride(),
},
})

Expand Down
32 changes: 32 additions & 0 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,38 @@ func TestOpenFgaClient(t *testing.T) {
t.Fatalf("%v", err)
}
}

// store can be overridden
storeOverrideOptions := ClientWriteOptions{
AuthorizationModelId: openfga.PtrString(authModelId),
Transaction: &TransactionOptions{
Disable: true,
MaxParallelRequests: 5,
MaxPerChunk: 1,
},
StoreId: openfga.PtrString("7777HCE4YVKPQEKZQHT2R89MQV"),
}
httpmock.Reset()
httpmock.RegisterResponder(test.Method, fmt.Sprintf("%s/stores/%s/%s", fgaClient.GetConfig().ApiUrl, *storeOverrideOptions.StoreId, test.RequestPath),
func(req *http.Request) (*http.Response, error) {
resp, err := httpmock.NewJsonResponse(test.ResponseStatus, expectedResponse)
if err != nil {
return httpmock.NewStringResponse(http.StatusInternalServerError, ""), nil
}
return resp, nil
},
)
data, err = fgaClient.Write(context.Background()).Body(requestBody).Options(storeOverrideOptions).Execute()
if err != nil {
t.Fatalf("%v", data)
}

for index := 0; index < len(data.Writes); index++ {
response := data.Writes[index]
if response.Error != nil {
t.Fatalf("OpenFgaClient.%v()|%d/ %v", test.Name, index, response.Error)
}
}
})

t.Run("Write with invalid auth", func(t *testing.T) {
Expand Down