Skip to content

Commit

Permalink
Merge pull request #382 from canonical/IAM-968
Browse files Browse the repository at this point in the history
IAM 968
  • Loading branch information
shipperizer committed Aug 28, 2024
2 parents 99e00d4 + d2c388c commit 6570281
Show file tree
Hide file tree
Showing 9 changed files with 3,629 additions and 30 deletions.
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)
}
Loading

0 comments on commit 6570281

Please sign in to comment.