Skip to content

Commit

Permalink
feat: abac (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh authored Dec 5, 2023
2 parents 5101122 + a95417a commit d171737
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 250 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ indent_style = tab
indent_style = space
indent_size = 4

[*.js]
[*.{js,ts}]
indent_style = space
indent_size = 2

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Main config
OPENFGA_DOCKER_TAG = latest
OPEN_API_URL = https://raw.githubusercontent.com/openfga/api/main/docs/openapiv2/apidocs.swagger.json
OPEN_API_URL = https://raw.githubusercontent.com/openfga/api/feat/abac/docs/openapiv2/apidocs.swagger.json
OPENAPI_GENERATOR_CLI_DOCKER_TAG = v6.4.0
NODE_DOCKER_TAG = 18-alpine
GO_DOCKER_TAG = 1
Expand Down
6 changes: 6 additions & 0 deletions config/clients/go/CHANGELOG.md.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.3.0

### [0.3.0](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/compare/v0.2.3...v0.3.0) (2023-11-02)

- feat!: initial support for conditions

## v0.2.3

### [0.2.3](https://{{gitHost}}/{{gitUserId}}/{{gitRepoId}}/compare/v0.2.2...v0.2.3) (2023-10-13)
Expand Down
2 changes: 1 addition & 1 deletion config/clients/go/config.overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"sdkId": "go",
"gitRepoId": "go-sdk",
"packageName": "openfga",
"packageVersion": "0.2.3",
"packageVersion": "0.3.0-beta.1",
"packageDescription": "Go SDK for OpenFGA",
"packageDetailedDescription": "This is an autogenerated Go SDK for OpenFGA. It provides a wrapper around the [OpenFGA API definition](https://openfga.dev/api).",
"fossaComplianceNoticeId": "41c01c64-f74a-414a-9e39-7aeca87bc47b",
Expand Down
4 changes: 2 additions & 2 deletions config/clients/go/template/README_calling_api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ body := ClientWriteRequest{
Relation: "viewer",
Object: "document:budget",
} },
Deletes: &[]ClientTupleKey{ {
Deletes: &[]ClientTupleKeyWithoutCondition{ {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "writer",
Object: "document:roadmap",
Expand Down Expand Up @@ -298,7 +298,7 @@ body := ClientWriteRequest{
Relation: "viewer",
Object: "document:budget",
} },
Deletes: &[]ClientTupleKey{ {
Deletes: &[]ClientTupleKeyWithoutCondition{ {
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "writer",
Object: "document:roadmap",
Expand Down
126 changes: 63 additions & 63 deletions config/clients/go/template/api_test.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ func Test{{appShortName}}ApiConfiguration(t *testing.T) {
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", fmt.Sprintf("%s://%s/stores/%s/authorization-models", configuration.ApiScheme, configuration.ApiHost, configuration.StoreId),
func(req *http.Request) (*http.Response, error) {
resp, err := httpmock.NewJsonResponse(200, ReadAuthorizationModelsResponse{AuthorizationModels: &[]AuthorizationModel{
resp, err := httpmock.NewJsonResponse(200, ReadAuthorizationModelsResponse{AuthorizationModels: []AuthorizationModel{
{
Id: PtrString("01GXSA8YR785C4FYS3C0RTG7B1"),
TypeDefinitions: &[]TypeDefinition{},
TypeDefinitions: []TypeDefinition{},
},
{
Id: PtrString("01GXSBM5PVYHCJNRNKXMB4QZTW"),
TypeDefinitions: &[]TypeDefinition{},
TypeDefinitions: []TypeDefinition{},
},
}})
if err != nil {
Expand Down Expand Up @@ -238,14 +238,14 @@ func Test{{appShortName}}ApiConfiguration(t *testing.T) {
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", fmt.Sprintf("%s://%s/stores/%s/authorization-models", configuration.ApiScheme, configuration.ApiHost, configuration.StoreId),
func(req *http.Request) (*http.Response, error) {
resp, err := httpmock.NewJsonResponse(200, ReadAuthorizationModelsResponse{AuthorizationModels: &[]AuthorizationModel{
resp, err := httpmock.NewJsonResponse(200, ReadAuthorizationModelsResponse{AuthorizationModels: []AuthorizationModel{
{
Id: PtrString("01GXSA8YR785C4FYS3C0RTG7B1"),
TypeDefinitions: &[]TypeDefinition{},
TypeDefinitions: []TypeDefinition{},
},
{
Id: PtrString("01GXSBM5PVYHCJNRNKXMB4QZTW"),
TypeDefinitions: &[]TypeDefinition{},
TypeDefinitions: []TypeDefinition{},
},
}})
if err != nil {
Expand Down Expand Up @@ -302,14 +302,14 @@ func Test{{appShortName}}ApiConfiguration(t *testing.T) {
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder("GET", fmt.Sprintf("%s://%s/stores/%s/authorization-models", configuration.ApiScheme, configuration.ApiHost, configuration.StoreId),
func(req *http.Request) (*http.Response, error) {
resp, err := httpmock.NewJsonResponse(200, ReadAuthorizationModelsResponse{AuthorizationModels: &[]AuthorizationModel{
resp, err := httpmock.NewJsonResponse(200, ReadAuthorizationModelsResponse{AuthorizationModels: []AuthorizationModel{
{
Id: PtrString("01GXSA8YR785C4FYS3C0RTG7B1"),
TypeDefinitions: &[]TypeDefinition{},
TypeDefinitions: []TypeDefinition{},
},
{
Id: PtrString("01GXSBM5PVYHCJNRNKXMB4QZTW"),
TypeDefinitions: &[]TypeDefinition{},
TypeDefinitions: []TypeDefinition{},
},
}})
if err != nil {
Expand Down Expand Up @@ -436,12 +436,12 @@ func Test{{appShortName}}Api(t *testing.T) {
t.Fatalf("{{appShortName}}%v().Execute() = %v, want %v", test.Name, response.StatusCode, test.ResponseStatus)
}

if len(*got.AuthorizationModels) != 1 {
if len(got.AuthorizationModels) != 1 {
t.Fatalf("%v", err)
}

if *((*got.AuthorizationModels)[0].Id) != *((*expectedResponse.AuthorizationModels)[0].Id) {
t.Fatalf("{{appShortName}}%v().Execute() = %v, want %v", test.Name, *((*got.AuthorizationModels)[0].Id), *((*expectedResponse.AuthorizationModels)[0].Id))
if *(got.AuthorizationModels[0].Id) != *(expectedResponse.AuthorizationModels[0].Id) {
t.Fatalf("{{appShortName}}%v().Execute() = %v, want %v", test.Name, *(got.AuthorizationModels[0].Id), *(expectedResponse.AuthorizationModels[0].Id))
}
})

Expand All @@ -462,7 +462,7 @@ func Test{{appShortName}}Api(t *testing.T) {
This: &map[string]interface{}{},
},
"viewer": {Union: &Usersets{
Child: &[]Userset{
Child: []Userset{
{This: &map[string]interface{}{}},
{ComputedUserset: &ObjectRelation{
Object: PtrString(""),
Expand Down Expand Up @@ -560,10 +560,10 @@ func Test{{appShortName}}Api(t *testing.T) {
RequestPath: "check",
}
requestBody := CheckRequest{
TupleKey: TupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: CheckRequestTupleKey{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
},
AuthorizationModelId: PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"),
}
Expand Down Expand Up @@ -613,11 +613,11 @@ func Test{{appShortName}}Api(t *testing.T) {
}
{{=<% %>=}}
requestBody := WriteRequest{
Writes: &TupleKeys{
Writes: &WriteRequestWrites{
TupleKeys: []TupleKey{{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
}},
},
AuthorizationModelId: PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"),
Expand Down Expand Up @@ -661,11 +661,11 @@ func Test{{appShortName}}Api(t *testing.T) {

{{=<% %>=}}
requestBody := WriteRequest{
Deletes: &TupleKeys{
TupleKeys: []TupleKey{{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
Deletes: &WriteRequestDeletes{
TupleKeys: []TupleKeyWithoutCondition{{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
}},
},
AuthorizationModelId: PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"),
Expand Down Expand Up @@ -708,9 +708,9 @@ func Test{{appShortName}}Api(t *testing.T) {
}

requestBody := ExpandRequest{
TupleKey: TupleKey{
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: ExpandRequestTupleKey{
Relation: "viewer",
Object: "document:roadmap",
},
AuthorizationModelId: PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"),
}
Expand Down Expand Up @@ -756,7 +756,7 @@ func Test{{appShortName}}Api(t *testing.T) {
}

requestBody := ReadRequest{
TupleKey: &TupleKey{
TupleKey: &ReadRequestTupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
Expand Down Expand Up @@ -793,7 +793,7 @@ func Test{{appShortName}}Api(t *testing.T) {
t.Fatalf("%v", err)
}

if len(*got.Tuples) != len(*expectedResponse.Tuples) {
if len(got.Tuples) != len(expectedResponse.Tuples) {
t.Fatalf("{{appShortName}}%v().Execute() = %v, want %v", test.Name, string(responseJson), test.JsonResponse)
}
})
Expand Down Expand Up @@ -841,7 +841,7 @@ func Test{{appShortName}}Api(t *testing.T) {
t.Fatalf("%v", err)
}

if len(*got.Changes) != len(*expectedResponse.Changes) {
if len(got.Changes) != len(expectedResponse.Changes) {
t.Fatalf("{{appShortName}}%v().Execute() = %v, want %v", test.Name, string(responseJson), test.JsonResponse)
}
})
Expand All @@ -863,13 +863,13 @@ func Test{{appShortName}}Api(t *testing.T) {
ContextualTuples: &ContextualTupleKeys{
{{=<% %>=}}
TupleKeys: []TupleKey{{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("editor"),
Object: PtrString("folder:product"),
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "editor",
Object: "folder:product",
}, {
User: PtrString("folder:product"),
Relation: PtrString("parent"),
Object: PtrString("document:roadmap"),
User: "folder:product",
Relation: "parent",
Object: "document:roadmap",
}},
<%={{ }}=%>
},
Expand Down Expand Up @@ -907,7 +907,7 @@ func Test{{appShortName}}Api(t *testing.T) {
t.Fatalf("%v", err)
}

if len(*got.Objects) != len(*expectedResponse.Objects) || (*got.Objects)[0] != (*expectedResponse.Objects)[0] {
if len(got.Objects) != len(expectedResponse.Objects) || (got.Objects)[0] != (expectedResponse.Objects)[0] {
t.Fatalf("{{appShortName}}%v().Execute() = %v, want %v", test.Name, string(responseJson), test.JsonResponse)
}
})
Expand All @@ -921,10 +921,10 @@ func Test{{appShortName}}Api(t *testing.T) {
RequestPath: "check",
}
requestBody := CheckRequest{
TupleKey: TupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: CheckRequestTupleKey{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
},
}

Expand Down Expand Up @@ -984,10 +984,10 @@ func Test{{appShortName}}Api(t *testing.T) {
RequestPath: "check",
}
requestBody := CheckRequest{
TupleKey: TupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: CheckRequestTupleKey{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
},
}

Expand Down Expand Up @@ -1040,10 +1040,10 @@ func Test{{appShortName}}Api(t *testing.T) {
RequestPath: "check",
}
requestBody := CheckRequest{
TupleKey: TupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: CheckRequestTupleKey{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
},
}

Expand Down Expand Up @@ -1103,10 +1103,10 @@ func Test{{appShortName}}Api(t *testing.T) {
RequestPath: "check",
}
requestBody := CheckRequest{
TupleKey: TupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: CheckRequestTupleKey{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
},
}

Expand Down Expand Up @@ -1174,10 +1174,10 @@ func Test{{appShortName}}Api(t *testing.T) {
RequestPath: "check",
}
requestBody := CheckRequest{
TupleKey: TupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: CheckRequestTupleKey{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
},
}

Expand Down Expand Up @@ -1236,10 +1236,10 @@ func Test{{appShortName}}Api(t *testing.T) {
RequestPath: "check",
}
requestBody := CheckRequest{
TupleKey: TupleKey{
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("viewer"),
Object: PtrString("document:roadmap"),
TupleKey: CheckRequestTupleKey{
User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
Relation: "viewer",
Object: "document:roadmap",
},
}

Expand Down
Loading

0 comments on commit d171737

Please sign in to comment.