Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IAM 968 #382

Merged
merged 3 commits into from
Aug 27, 2024
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
4 changes: 2 additions & 2 deletions internal/openfga/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import (
)

type Client struct {
c OpenFGAClientInterface
c OpenFGACoreClientInterface

tracer tracing.TracingInterface
monitor monitoring.MonitorInterface
logger logging.LoggerInterface
}

func (c *Client) APIClient() OpenFGAClientInterface {
func (c *Client) APIClient() OpenFGACoreClientInterface {
return c.c
}

Expand Down
24 changes: 12 additions & 12 deletions internal/openfga/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestNewClientAPIClientImplementsInterface(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)

specs := new(EnvSpec)

Expand All @@ -63,9 +63,9 @@ func TestNewClientAPIClientImplementsInterface(t *testing.T) {
c.c = mockOpenFGAClient

if !reflect.TypeOf(c.APIClient()).Implements(
reflect.TypeOf((*OpenFGAClientInterface)(nil)).Elem(),
reflect.TypeOf((*OpenFGACoreClientInterface)(nil)).Elem(),
) {
t.Fatal("APIClient doesn't implement interface OpenFGAClientInterface")
t.Fatal("APIClient doesn't implement interface OpenFGACoreClientInterface")
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ func TestClientListObjectsSuccess(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientListObjectsRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -149,7 +149,7 @@ func TestClientListObjectsFails(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientListObjectsRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -230,7 +230,7 @@ func TestClientReadTuplesSuccess(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientReadRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestClientReadTuplesFails(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientReadRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -343,7 +343,7 @@ func TestClientWriteTuplesSuccess(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientWriteRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -384,7 +384,7 @@ func TestClientWriteTuplesFails(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientWriteRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -440,7 +440,7 @@ func TestClientDeleteTuplesSuccess(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientWriteRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -481,7 +481,7 @@ func TestClientDeleteTuplesFails(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientWriteRequestInterface(ctrl)

c := Client{
Expand Down Expand Up @@ -565,7 +565,7 @@ func TestClientWriteBatchCheckSuccess(t *testing.T) {
mockLogger := NewMockLoggerInterface(ctrl)
mockTracer := NewMockTracer(ctrl)
mockMonitor := monitoring.NewMockMonitorInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGAClientInterface(ctrl)
mockOpenFGAClient := NewMockOpenFGACoreClientInterface(ctrl)
mockRequest := NewMockSdkClientBatchCheckRequestInterface(ctrl)

c := Client{
Expand Down
11 changes: 10 additions & 1 deletion internal/openfga/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/openfga/go-sdk/client"
)

type OpenFGAClientInterface interface {
type OpenFGACoreClientInterface interface {
GetAuthorizationModelId() (string, error)
CreateStore(context.Context) client.SdkClientCreateStoreRequestInterface
CreateStoreExecute(client.SdkClientCreateStoreRequestInterface) (*client.ClientCreateStoreResponse, error)
Expand All @@ -30,3 +30,12 @@ type OpenFGAClientInterface interface {
ListObjects(context.Context) client.SdkClientListObjectsRequestInterface
ListObjectsExecute(client.SdkClientListObjectsRequestInterface) (*client.ClientListObjectsResponse, error)
}

// OpenFGAClientInterface is the interface used to decouple the OpenFGA store implementation
type OpenFGAClientInterface interface {
ListObjects(context.Context, string, string, string) ([]string, error)
ReadTuples(context.Context, string, string, string, string) (*client.ClientReadResponse, error)
WriteTuples(context.Context, ...Tuple) error
DeleteTuples(context.Context, ...Tuple) error
Check(context.Context, string, string, string, ...Tuple) (bool, error)
BarcoMasile marked this conversation as resolved.
Show resolved Hide resolved
}
Loading
Loading