Skip to content

Commit

Permalink
chore!: rename TypeDefinitions interface to `WriteAuthorizationMode…
Browse files Browse the repository at this point in the history
…lRequest`

- Add support for metadata in authorization models
- Upgrade dependencies

Note: The breaking change is only on the SDKs, not the API

[BREAKING CHANGE] To call WriteAuthorizationModel with this new change, check: https://github.com/openfga/go-sdk#write-authorization-model
  • Loading branch information
rhamzeh committed Sep 29, 2022
1 parent ee8869f commit be2d193
Show file tree
Hide file tree
Showing 21 changed files with 1,007 additions and 234 deletions.
10 changes: 8 additions & 2 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ docs/Leaf.md
docs/ListObjectsRequest.md
docs/ListObjectsResponse.md
docs/ListStoresResponse.md
docs/Metadata.md
docs/Node.md
docs/Nodes.md
docs/NotFoundErrorCode.md
Expand All @@ -49,6 +50,8 @@ docs/ReadAuthorizationModelsResponse.md
docs/ReadChangesResponse.md
docs/ReadRequest.md
docs/ReadResponse.md
docs/RelationMetadata.md
docs/RelationReference.md
docs/Status.md
docs/Store.md
docs/Tuple.md
Expand All @@ -58,7 +61,6 @@ docs/TupleKeys.md
docs/TupleOperation.md
docs/TupleToUserset.md
docs/TypeDefinition.md
docs/TypeDefinitions.md
docs/Users.md
docs/Userset.md
docs/UsersetTree.md
Expand All @@ -67,6 +69,7 @@ docs/UsersetTreeTupleToUserset.md
docs/Usersets.md
docs/ValidationErrorMessageResponse.md
docs/WriteAssertionsRequest.md
docs/WriteAuthorizationModelRequest.md
docs/WriteAuthorizationModelResponse.md
docs/WriteRequest.md
fga_test.go
Expand All @@ -93,6 +96,7 @@ model_leaf.go
model_list_objects_request.go
model_list_objects_response.go
model_list_stores_response.go
model_metadata.go
model_node.go
model_nodes.go
model_not_found_error_code.go
Expand All @@ -104,6 +108,8 @@ model_read_authorization_models_response.go
model_read_changes_response.go
model_read_request.go
model_read_response.go
model_relation_metadata.go
model_relation_reference.go
model_status.go
model_store.go
model_tuple.go
Expand All @@ -113,7 +119,6 @@ model_tuple_keys.go
model_tuple_operation.go
model_tuple_to_userset.go
model_type_definition.go
model_type_definitions.go
model_users.go
model_userset.go
model_userset_tree.go
Expand All @@ -122,6 +127,7 @@ model_userset_tree_tuple_to_userset.go
model_usersets.go
model_validation_error_message_response.go
model_write_assertions_request.go
model_write_authorization_model_request.go
model_write_authorization_model_response.go
model_write_request.go
oauth2/LICENSE
Expand Down
32 changes: 15 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ This is an autogenerated Go SDK for OpenFGA. It provides a wrapper around the [O

OpenFGA is designed to make it easy for application builders to model their permission layer, and to add and integrate fine-grained authorization into their applications. OpenFGA’s design is optimized for reliability and low latency at a high scale.

It allows in-memory data storage for quick development, as well as pluggable database modules - with initial support for PostgreSQL.

It offers an [HTTP API](https://openfga.dev/api/service) and has SDKs for programming languages including [Node.js/JavaScript](https://github.com/openfga/js-sdk), [GoLang](https://github.com/openfga/go-sdk) and [.NET](https://github.com/openfga/dotnet-sdk).

More SDKs and integrations such as Rego are planned for the future.

## Resources

Expand Down Expand Up @@ -237,10 +232,10 @@ if err != nil {
> Learn more about [the OpenFGA configuration language](https://openfga.dev/docs/configuration-language).
```golang
body := openfga.TypeDefinitions{TypeDefinitions: &[]openfga.TypeDefinition{
body := openfga.WriteAuthorizationModelRequest{TypeDefinitions: &[]openfga.TypeDefinition{
{
Type: "repo",
Relations: map[string]openfga.Userset{
Relations: &map[string]openfga.Userset{
"writer": {This: &map[string]interface{}{}},
"reader": {Union: &openfga.Usersets{
Child: &[]openfga.Userset{
Expand Down Expand Up @@ -293,7 +288,7 @@ fmt.Printf("%s", (*data.AuthorizationModelIds)[0]) // 1uHxCSuTP0VKPYSnkq1pbb1jeZ
```golang
body := openfga.CheckRequest{
TupleKey: &openfga.TupleKey{
User: openfga.PtrString("81684243-9356-4421-8fbf-a4f8d36aa31b"),
User: openfga.PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: openfga.PtrString("admin"),
Object: openfga.PtrString("workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6"),
},
Expand All @@ -315,7 +310,7 @@ body := openfga.WriteRequest{
Writes: &openfga.TupleKeys{
TupleKeys: []openfga.TupleKey{
{
User: openfga.PtrString("81684243-9356-4421-8fbf-a4f8d36aa31b"),
User: openfga.PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: openfga.PtrString("admin"),
Object: openfga.PtrString("workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6"),
},
Expand All @@ -335,7 +330,7 @@ body := openfga.WriteRequest{
Deletes: &openfga.TupleKeys{
TupleKeys: []openfga.TupleKey{
{
User: openfga.PtrString("81684243-9356-4421-8fbf-a4f8d36aa31b"),
User: openfga.PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: openfga.PtrString("admin"),
Object: openfga.PtrString("workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6"),
},
Expand All @@ -359,7 +354,7 @@ body := openfga.ExpandRequest{
}
data, response, err := apiClient.OpenFgaApi.Expand(context.Background()).Body(body).Execute()

// data = {"tree":{"root":{"name":"workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6#admin","leaf":{"users":{"users":["anne","beth"]}}}}} // JSON
// data = {"tree":{"root":{"name":"workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6#admin","leaf":{"users":{"users":["user:81684243-9356-4421-8fbf-a4f8d36aa31b","user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"]}}}}} // JSON
```

#### Read Changes
Expand All @@ -370,7 +365,7 @@ data, response, err := apiClient.OpenFgaApi.Expand(context.Background()).Body(bo
// Find if a relationship tuple stating that a certain user is an admin on a certain workspace
body := openfga.ReadRequest{
TupleKey: &openfga.TupleKey{
User: openfga.PtrString("81684243-9356-4421-8fbf-a4f8d36aa31b"),
User: openfga.PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: openfga.PtrString("admin"),
Object: openfga.PtrString("workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6"),
},
Expand All @@ -379,15 +374,15 @@ body := openfga.ReadRequest{
// Find all relationship tuples where a certain user has a relationship as any relation to a certain workspace
body := openfga.ReadRequest{
TupleKey: &openfga.TupleKey{
User: openfga.PtrString("81684243-9356-4421-8fbf-a4f8d36aa31b"),
User: openfga.PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Object: openfga.PtrString("workspace:675bcac4-ad38-4fb1-a19a-94a5648c91d6"),
},
}

// Find all relationship tuples where a certain user is an admin on any workspace
body := openfga.ReadRequest{
TupleKey: &openfga.TupleKey{
User: openfga.PtrString("81684243-9356-4421-8fbf-a4f8d36aa31b"),
User: openfga.PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: openfga.PtrString("admin"),
Object: openfga.PtrString("workspace:"),
},
Expand Down Expand Up @@ -433,12 +428,12 @@ data, response, err := apiClient.OpenFgaApi.ReadChanges(context.Background()).
```golang
body := openfga.ListObjectsRequest{
AuthorizationModelId: PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"),
User: PtrString("anne"),
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("can_read"),
Type: PtrString("document"),
ContextualTuples: &ContextualTupleKeys{
TupleKeys: []TupleKey{{
User: PtrString("anne"),
User: PtrString("user:81684243-9356-4421-8fbf-a4f8d36aa31b"),
Relation: PtrString("editor"),
Object: PtrString("folder:product"),
}, {
Expand Down Expand Up @@ -498,6 +493,7 @@ Class | Method | HTTP request | Description
- [ListObjectsRequest](docs/ListObjectsRequest.md)
- [ListObjectsResponse](docs/ListObjectsResponse.md)
- [ListStoresResponse](docs/ListStoresResponse.md)
- [Metadata](docs/Metadata.md)
- [Node](docs/Node.md)
- [Nodes](docs/Nodes.md)
- [NotFoundErrorCode](docs/NotFoundErrorCode.md)
Expand All @@ -509,6 +505,8 @@ Class | Method | HTTP request | Description
- [ReadChangesResponse](docs/ReadChangesResponse.md)
- [ReadRequest](docs/ReadRequest.md)
- [ReadResponse](docs/ReadResponse.md)
- [RelationMetadata](docs/RelationMetadata.md)
- [RelationReference](docs/RelationReference.md)
- [Status](docs/Status.md)
- [Store](docs/Store.md)
- [Tuple](docs/Tuple.md)
Expand All @@ -518,7 +516,6 @@ Class | Method | HTTP request | Description
- [TupleOperation](docs/TupleOperation.md)
- [TupleToUserset](docs/TupleToUserset.md)
- [TypeDefinition](docs/TypeDefinition.md)
- [TypeDefinitions](docs/TypeDefinitions.md)
- [Users](docs/Users.md)
- [Userset](docs/Userset.md)
- [UsersetTree](docs/UsersetTree.md)
Expand All @@ -527,6 +524,7 @@ Class | Method | HTTP request | Description
- [Usersets](docs/Usersets.md)
- [ValidationErrorMessageResponse](docs/ValidationErrorMessageResponse.md)
- [WriteAssertionsRequest](docs/WriteAssertionsRequest.md)
- [WriteAuthorizationModelRequest](docs/WriteAuthorizationModelRequest.md)
- [WriteAuthorizationModelResponse](docs/WriteAuthorizationModelResponse.md)
- [WriteRequest](docs/WriteRequest.md)

Expand Down
12 changes: 6 additions & 6 deletions api_open_fga.go
Original file line number Diff line number Diff line change
Expand Up @@ -4578,11 +4578,11 @@ type ApiWriteAuthorizationModelRequest struct {
ctx _context.Context
ApiService OpenFgaApi

typeDefinitions *TypeDefinitions
body *WriteAuthorizationModelRequest
}

func (r ApiWriteAuthorizationModelRequest) TypeDefinitions(typeDefinitions TypeDefinitions) ApiWriteAuthorizationModelRequest {
r.typeDefinitions = &typeDefinitions
func (r ApiWriteAuthorizationModelRequest) Body(body WriteAuthorizationModelRequest) ApiWriteAuthorizationModelRequest {
r.body = &body
return r
}

Expand Down Expand Up @@ -4680,8 +4680,8 @@ func (a *OpenFgaApiService) WriteAuthorizationModelExecute(r ApiWriteAuthorizati
localVarHeaderParams := make(map[string]string)
localVarQueryParams := _neturl.Values{}
localVarFormParams := _neturl.Values{}
if r.typeDefinitions == nil {
return localVarReturnValue, nil, reportError("typeDefinitions is required and must be specified")
if r.body == nil {
return localVarReturnValue, nil, reportError("body is required and must be specified")
}

// to determine the Content-Type header
Expand All @@ -4702,7 +4702,7 @@ func (a *OpenFgaApiService) WriteAuthorizationModelExecute(r ApiWriteAuthorizati
localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept
}
// body params
localVarPostBody = r.typeDefinitions
localVarPostBody = r.body
req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)
if err != nil {
return localVarReturnValue, nil, err
Expand Down
26 changes: 26 additions & 0 deletions docs/AuthorizationModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Id** | Pointer to **string** | | [optional]
**SchemaVersion** | Pointer to **string** | | [optional]
**TypeDefinitions** | Pointer to [**[]TypeDefinition**](TypeDefinition.md) | | [optional]

## Methods
Expand Down Expand Up @@ -51,6 +52,31 @@ SetId sets Id field to given value.

HasId returns a boolean if a field has been set.

### GetSchemaVersion

`func (o *AuthorizationModel) GetSchemaVersion() string`

GetSchemaVersion returns the SchemaVersion field if non-nil, zero value otherwise.

### GetSchemaVersionOk

`func (o *AuthorizationModel) GetSchemaVersionOk() (*string, bool)`

GetSchemaVersionOk returns a tuple with the SchemaVersion field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetSchemaVersion

`func (o *AuthorizationModel) SetSchemaVersion(v string)`

SetSchemaVersion sets SchemaVersion field to given value.

### HasSchemaVersion

`func (o *AuthorizationModel) HasSchemaVersion() bool`

HasSchemaVersion returns a boolean if a field has been set.

### GetTypeDefinitions

`func (o *AuthorizationModel) GetTypeDefinitions() []TypeDefinition`
Expand Down
4 changes: 4 additions & 0 deletions docs/ErrorCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@

* `DUPLICATE_CONTEXTUAL_TUPLE` (value: `"duplicate_contextual_tuple"`)

* `INVALID_AUTHORIZATION_MODEL` (value: `"invalid_authorization_model"`)

* `UNSUPPORTED_SCHEMA_VERSION` (value: `"unsupported_schema_version"`)


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
56 changes: 56 additions & 0 deletions docs/Metadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Metadata

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Relations** | Pointer to [**map[string]RelationMetadata**](RelationMetadata.md) | | [optional]

## Methods

### NewMetadata

`func NewMetadata() *Metadata`

NewMetadata instantiates a new Metadata object
This constructor will assign default values to properties that have it defined,
and makes sure properties required by API are set, but the set of arguments
will change when the set of required properties is changed

### NewMetadataWithDefaults

`func NewMetadataWithDefaults() *Metadata`

NewMetadataWithDefaults instantiates a new Metadata object
This constructor will only assign default values to properties that have it defined,
but it doesn't guarantee that properties required by API are set

### GetRelations

`func (o *Metadata) GetRelations() map[string]RelationMetadata`

GetRelations returns the Relations field if non-nil, zero value otherwise.

### GetRelationsOk

`func (o *Metadata) GetRelationsOk() (*map[string]RelationMetadata, bool)`

GetRelationsOk returns a tuple with the Relations field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetRelations

`func (o *Metadata) SetRelations(v map[string]RelationMetadata)`

SetRelations sets Relations field to given value.

### HasRelations

`func (o *Metadata) HasRelations() bool`

HasRelations returns a boolean if a field has been set.


[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)


8 changes: 4 additions & 4 deletions docs/OpenFgaApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ No authorization required

## WriteAuthorizationModel

> WriteAuthorizationModelResponse WriteAuthorizationModel(ctx).TypeDefinitions(typeDefinitions).Execute()
> WriteAuthorizationModelResponse WriteAuthorizationModel(ctx).Body(body).Execute()
Create a new authorization model

Expand All @@ -1352,7 +1352,7 @@ import (

func main() {

typeDefinitions := *openapiclient.NewTypeDefinitions() // TypeDefinitions |
body := *openapiclient.NewWriteAuthorizationModelRequest() // WriteAuthorizationModelRequest |

configuration, err := openfga.NewConfiguration(openfga.Configuration{
ApiScheme: os.Getenv("OPENFGA_API_SCHEME"), // optional, defaults to "https"
Expand All @@ -1366,7 +1366,7 @@ func main() {

apiClient := openfga.NewAPIClient(configuration)

resp, r, err := apiClient.OpenFgaApi.WriteAuthorizationModel(context.Background()).TypeDefinitions(typeDefinitions).Execute()
resp, r, err := apiClient.OpenFgaApi.WriteAuthorizationModel(context.Background()).Body(body).Execute()
if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `OpenFgaApi.WriteAuthorizationModel``: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
Expand Down Expand Up @@ -1404,7 +1404,7 @@ Other parameters are passed through a pointer to a apiWriteAuthorizationModelReq

Name | Type | Description | Notes
------------- | ------------- | ------------- | -------------
**typeDefinitions** | [**TypeDefinitions**](TypeDefinitions.md) | |
**body** | [**WriteAuthorizationModelRequest**](WriteAuthorizationModelRequest.md) | |

### Return type

Expand Down
Loading

0 comments on commit be2d193

Please sign in to comment.