diff --git a/.openapi-generator/FILES b/.openapi-generator/FILES index bff5b34..5bf70a9 100644 --- a/.openapi-generator/FILES +++ b/.openapi-generator/FILES @@ -47,11 +47,15 @@ docs/Leaf.md docs/ListObjectsRequest.md docs/ListObjectsResponse.md docs/ListStoresResponse.md +docs/ListUsersFilter.md +docs/ListUsersRequest.md +docs/ListUsersResponse.md docs/Metadata.md docs/Node.md docs/Nodes.md docs/NotFoundErrorCode.md docs/NullValue.md +docs/Object.md docs/ObjectRelation.md docs/OpenFgaApi.md docs/PathUnknownErrorMessageResponse.md @@ -75,11 +79,14 @@ docs/TupleOperation.md docs/TupleToUserset.md docs/TypeDefinition.md docs/TypeName.md +docs/TypedWildcard.md +docs/User.md docs/Users.md docs/Userset.md docs/UsersetTree.md docs/UsersetTreeDifference.md docs/UsersetTreeTupleToUserset.md +docs/UsersetUser.md docs/Usersets.md docs/ValidationErrorMessageResponse.md docs/WriteAssertionsRequest.md @@ -125,11 +132,15 @@ model_leaf.go model_list_objects_request.go model_list_objects_response.go model_list_stores_response.go +model_list_users_filter.go +model_list_users_request.go +model_list_users_response.go model_metadata.go model_node.go model_nodes.go model_not_found_error_code.go model_null_value.go +model_object.go model_object_relation.go model_path_unknown_error_message_response.go model_read_assertions_response.go @@ -152,11 +163,14 @@ model_tuple_operation.go model_tuple_to_userset.go model_type_definition.go model_type_name.go +model_typed_wildcard.go +model_user.go model_users.go model_userset.go model_userset_tree.go model_userset_tree_difference.go model_userset_tree_tuple_to_userset.go +model_userset_user.go model_usersets.go model_validation_error_message_response.go model_write_assertions_request.go diff --git a/README.md b/README.md index e30135d..72b6a9d 100644 --- a/README.md +++ b/README.md @@ -631,7 +631,7 @@ body := ClientBatchCheckBody{ { Object: "document:roadmap", } } -data, err := fgaClient.BatchCheck(context.Background()).Body(requestBody).Options(options).Execute() +data, err := fgaClient.BatchCheck(context.Background()).Body(body).Options(options).Execute() /* data = [{ @@ -696,7 +696,7 @@ body := ClientExpandRequest{ Relation: "viewer", Object: "document:roadmap", } -data, err := fgaClient.Expand(context.Background()).Body(requestBody).Options(options).Execute() +data, err := fgaClient.Expand(context.Background()).Body(body).Options(options).Execute() // data.Tree.Root = {"name":"document:roadmap#viewer","leaf":{"users":{"users":["user:81684243-9356-4421-8fbf-a4f8d36aa31b","user:f52a4f7a-054d-47ff-bb6e-3ac81269988f"]}}} ``` @@ -727,7 +727,7 @@ body := ClientListObjectsRequest{ } }, } data, err := fgaClient.ListObjects(context.Background()). - Body(requestBody). + Body(body). Options(options). Execute() @@ -754,13 +754,51 @@ body := ClientListRelationsRequest{ } }, } data, err := fgaClient.ListRelations(context.Background()). - Body(requestBody). + Body(body). Options(options). Execute() // data.Relations = ["can_view", "can_edit"] ``` +#### List Objects + +List all users of the given type that the object has a relation with. + +[API Documentation](https://openfga.dev/api/service#/Relationship%20Queries/ListUsers) + +```golang +options := ClientListObjectsOptions{ + // You can rely on the model id set in the configuration or override it for this specific request + AuthorizationModelId: openfga.PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"), +} +body := ClientListUsersRequest{ + Object: openfga.Object{ + Type: "document", + Id: "roadmap", + }, + Relation: "can_read", + UserFilters: []openfga.ListUsersFilter{{ + Type: "user", + }}, + ContextualTuples: []ClientContextualTupleKey{{ + User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", + Relation: "editor", + Object: "folder:product", + }, { + User: "folder:product", + Relation: "parent", + Object: "document:roadmap", + }}, +} +data, err := fgaClient.ListUsers(context.Background()). + Body(body). + Options(options). + Execute() + +// data.Users = [{"type":"user", "id":"81684243-9356-4421-8fbf-a4f8d36aa31b"}] +``` + ### Assertions #### Read Assertions @@ -816,6 +854,7 @@ Class | Method | HTTP request | Description *OpenFgaApi* | [**GetStore**](docs/OpenFgaApi.md#getstore) | **Get** /stores/{store_id} | Get a store *OpenFgaApi* | [**ListObjects**](docs/OpenFgaApi.md#listobjects) | **Post** /stores/{store_id}/list-objects | List all objects of the given type that the user has a relation with *OpenFgaApi* | [**ListStores**](docs/OpenFgaApi.md#liststores) | **Get** /stores | List all stores +*OpenFgaApi* | [**ListUsers**](docs/OpenFgaApi.md#listusers) | **Post** /stores/{store_id}/list-users | List all users of the given type that the object has a relation with *OpenFgaApi* | [**Read**](docs/OpenFgaApi.md#read) | **Post** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules *OpenFgaApi* | [**ReadAssertions**](docs/OpenFgaApi.md#readassertions) | **Get** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID *OpenFgaApi* | [**ReadAuthorizationModel**](docs/OpenFgaApi.md#readauthorizationmodel) | **Get** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model @@ -854,11 +893,15 @@ Class | Method | HTTP request | Description - [ListObjectsRequest](docs/ListObjectsRequest.md) - [ListObjectsResponse](docs/ListObjectsResponse.md) - [ListStoresResponse](docs/ListStoresResponse.md) + - [ListUsersFilter](docs/ListUsersFilter.md) + - [ListUsersRequest](docs/ListUsersRequest.md) + - [ListUsersResponse](docs/ListUsersResponse.md) - [Metadata](docs/Metadata.md) - [Node](docs/Node.md) - [Nodes](docs/Nodes.md) - [NotFoundErrorCode](docs/NotFoundErrorCode.md) - [NullValue](docs/NullValue.md) + - [Object](docs/Object.md) - [ObjectRelation](docs/ObjectRelation.md) - [PathUnknownErrorMessageResponse](docs/PathUnknownErrorMessageResponse.md) - [ReadAssertionsResponse](docs/ReadAssertionsResponse.md) @@ -881,11 +924,14 @@ Class | Method | HTTP request | Description - [TupleToUserset](docs/TupleToUserset.md) - [TypeDefinition](docs/TypeDefinition.md) - [TypeName](docs/TypeName.md) + - [TypedWildcard](docs/TypedWildcard.md) + - [User](docs/User.md) - [Users](docs/Users.md) - [Userset](docs/Userset.md) - [UsersetTree](docs/UsersetTree.md) - [UsersetTreeDifference](docs/UsersetTreeDifference.md) - [UsersetTreeTupleToUserset](docs/UsersetTreeTupleToUserset.md) + - [UsersetUser](docs/UsersetUser.md) - [Usersets](docs/Usersets.md) - [ValidationErrorMessageResponse](docs/ValidationErrorMessageResponse.md) - [WriteAssertionsRequest](docs/WriteAssertionsRequest.md) diff --git a/api_open_fga.go b/api_open_fga.go index 32c6ee9..29ed765 100644 --- a/api_open_fga.go +++ b/api_open_fga.go @@ -219,6 +219,19 @@ type OpenFgaApi interface { */ ListStoresExecute(r ApiListStoresRequest) (ListStoresResponse, *_nethttp.Response, error) + /* + * ListUsers List all users of the given type that the object has a relation with + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiListUsersRequest + */ + ListUsers(ctx _context.Context) ApiListUsersRequest + + /* + * ListUsersExecute executes the request + * @return ListUsersResponse + */ + ListUsersExecute(r ApiListUsersRequest) (ListUsersResponse, *_nethttp.Response, error) + /* * Read Get tuples from the store that matches a query, without following userset rewrite rules * The Read API will return the tuples for a certain store that match a query filter specified in the body of the request. @@ -2528,6 +2541,273 @@ func (a *OpenFgaApiService) ListStoresExecute(r ApiListStoresRequest) (ListStore return localVarReturnValue, nil, reportError("Error not handled properly") } +type ApiListUsersRequest struct { + ctx _context.Context + ApiService OpenFgaApi + + body *ListUsersRequest +} + +func (r ApiListUsersRequest) Body(body ListUsersRequest) ApiListUsersRequest { + r.body = &body + return r +} + +func (r ApiListUsersRequest) Execute() (ListUsersResponse, *_nethttp.Response, error) { + return r.ApiService.ListUsersExecute(r) +} + +/* + * ListUsers List all users of the given type that the object has a relation with + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiListUsersRequest + */ +func (a *OpenFgaApiService) ListUsers(ctx _context.Context) ApiListUsersRequest { + return ApiListUsersRequest{ + ApiService: a, + ctx: ctx, + } +} + +/* + * Execute executes the request + * @return ListUsersResponse + */ +func (a *OpenFgaApiService) ListUsersExecute(r ApiListUsersRequest) (ListUsersResponse, *_nethttp.Response, error) { + var maxRetry int + var minWaitInMs int + + if a.RetryParams != nil { + maxRetry = a.RetryParams.MinWaitInMs + minWaitInMs = a.RetryParams.MinWaitInMs + } else { + maxRetry = 0 + minWaitInMs = 0 + } + + for i := 0; i < maxRetry+1; i++ { + var ( + localVarHTTPMethod = _nethttp.MethodPost + localVarPostBody interface{} + localVarReturnValue ListUsersResponse + ) + + if a.client.cfg.StoreId == "" { + return localVarReturnValue, nil, reportError("Configuration.StoreId is required and must be specified to call this method") + } + if a.client.cfg.StoreId != "" && !internalutils.IsWellFormedUlidString(a.client.cfg.StoreId) { + return localVarReturnValue, nil, reportError("Configuration.StoreId is invalid") + } + localVarPath := "/stores/{store_id}/list-users" + localVarPath = strings.Replace(localVarPath, "{"+"store_id"+"}", _neturl.PathEscape(a.client.cfg.StoreId), -1) + + localVarHeaderParams := make(map[string]string) + localVarQueryParams := _neturl.Values{} + if r.body == nil { + return localVarReturnValue, nil, reportError("body is required and must be specified") + } + + // to determine the Content-Type header + localVarHTTPContentTypes := []string{"application/json"} + + // set Content-Type header + localVarHTTPContentType := selectHeaderContentType(localVarHTTPContentTypes) + if localVarHTTPContentType != "" { + localVarHeaderParams["Content-Type"] = localVarHTTPContentType + } + + // to determine the Accept header + localVarHTTPHeaderAccepts := []string{"application/json"} + + // set Accept header + localVarHTTPHeaderAccept := selectHeaderAccept(localVarHTTPHeaderAccepts) + if localVarHTTPHeaderAccept != "" { + localVarHeaderParams["Accept"] = localVarHTTPHeaderAccept + } + // body params + localVarPostBody = r.body + req, err := a.client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams) + if err != nil { + return localVarReturnValue, nil, err + } + + localVarHTTPResponse, err := a.client.callAPI(req) + if err != nil || localVarHTTPResponse == nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + localVarBody, err := _ioutil.ReadAll(localVarHTTPResponse.Body) + localVarHTTPResponse.Body.Close() + localVarHTTPResponse.Body = _ioutil.NopCloser(bytes.NewBuffer(localVarBody)) + if err != nil { + return localVarReturnValue, localVarHTTPResponse, err + } + + if localVarHTTPResponse.StatusCode >= _nethttp.StatusMultipleChoices { + + if localVarHTTPResponse.StatusCode == _nethttp.StatusBadRequest || localVarHTTPResponse.StatusCode == _nethttp.StatusUnprocessableEntity { + newErr := FgaApiValidationError{ + body: localVarBody, + storeId: a.client.cfg.StoreId, + endpointCategory: "ListUsers", + requestBody: localVarPostBody, + requestMethod: localVarHTTPMethod, + responseStatusCode: localVarHTTPResponse.StatusCode, + responseHeader: localVarHTTPResponse.Header, + } + // Due to CanonicalHeaderKey, header name is case-insensitive. + newErr.requestId = localVarHTTPResponse.Header.Get("Fga-Request-Id") + newErr.error = "ListUsers validation error for " + localVarHTTPMethod + " ListUsers with body " + string(localVarBody) + var v ValidationErrorMessageResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.modelDecodeError = err + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + newErr.responseCode = v.GetCode() + newErr.error += " with error code " + string(v.GetCode()) + " error message: " + v.GetMessage() + + return localVarReturnValue, localVarHTTPResponse, newErr + } + + if localVarHTTPResponse.StatusCode == _nethttp.StatusUnauthorized || localVarHTTPResponse.StatusCode == _nethttp.StatusForbidden { + newErr := FgaApiAuthenticationError{ + body: localVarBody, + + storeId: a.client.cfg.StoreId, + endpointCategory: "ListUsers", + responseStatusCode: localVarHTTPResponse.StatusCode, + responseHeader: localVarHTTPResponse.Header, + } + // Due to CanonicalHeaderKey, header name is case-insensitive. + newErr.requestId = localVarHTTPResponse.Header.Get("Fga-Request-Id") + newErr.error = "ListUsers auth error for " + localVarHTTPMethod + " ListUsers with body " + string(localVarBody) + + return localVarReturnValue, localVarHTTPResponse, newErr + } + + if localVarHTTPResponse.StatusCode == _nethttp.StatusNotFound { + newErr := FgaApiNotFoundError{ + body: localVarBody, + storeId: a.client.cfg.StoreId, + endpointCategory: "ListUsers", + requestBody: localVarPostBody, + requestMethod: localVarHTTPMethod, + responseStatusCode: localVarHTTPResponse.StatusCode, + responseHeader: localVarHTTPResponse.Header, + } + // Due to CanonicalHeaderKey, header name is case-insensitive. + newErr.requestId = localVarHTTPResponse.Header.Get("Fga-Request-Id") + newErr.error = "ListUsers validation error for " + localVarHTTPMethod + " ListUsers with body " + string(localVarBody) + var v PathUnknownErrorMessageResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.modelDecodeError = err + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + newErr.responseCode = v.GetCode() + newErr.error += " with error code " + string(v.GetCode()) + " error message: " + v.GetMessage() + + return localVarReturnValue, localVarHTTPResponse, newErr + } + + if localVarHTTPResponse.StatusCode == _nethttp.StatusTooManyRequests { + if i < maxRetry { + time.Sleep(time.Duration(internalutils.RandomTime(i, minWaitInMs)) * time.Millisecond) + continue + } + // maximum number of retry reached + newErr := FgaApiRateLimitExceededError{ + body: localVarBody, + + storeId: a.client.cfg.StoreId, + endpointCategory: "ListUsers", + requestBody: localVarPostBody, + requestMethod: localVarHTTPMethod, + responseStatusCode: localVarHTTPResponse.StatusCode, + responseHeader: localVarHTTPResponse.Header, + } + newErr.error = "ListUsers rate limit error for " + localVarHTTPMethod + " ListUsers with body " + string(localVarBody) + + // Due to CanonicalHeaderKey, header name is case-insensitive. + newErr.requestId = localVarHTTPResponse.Header.Get("Fga-Request-Id") + return localVarReturnValue, localVarHTTPResponse, newErr + } + + if localVarHTTPResponse.StatusCode >= _nethttp.StatusInternalServerError { + if localVarHTTPResponse.StatusCode != _nethttp.StatusNotImplemented && i < maxRetry { + time.Sleep(time.Duration(internalutils.RandomTime(i, minWaitInMs)) * time.Millisecond) + continue + } + newErr := FgaApiInternalError{ + body: localVarBody, + + storeId: a.client.cfg.StoreId, + endpointCategory: "ListUsers", + requestBody: localVarPostBody, + requestMethod: localVarHTTPMethod, + responseStatusCode: localVarHTTPResponse.StatusCode, + responseHeader: localVarHTTPResponse.Header, + } + newErr.error = "ListUsers internal error for " + localVarHTTPMethod + " ListUsers with body " + string(localVarBody) + newErr.requestId = localVarHTTPResponse.Header.Get("Fga-Request-Id") + + var v InternalErrorMessageResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.modelDecodeError = err + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + newErr.responseCode = v.GetCode() + newErr.error += " with error code " + string(v.GetCode()) + " error message: " + v.GetMessage() + + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr := FgaApiError{ + body: localVarBody, + + storeId: a.client.cfg.StoreId, + endpointCategory: "ListUsers", + requestBody: localVarPostBody, + requestMethod: localVarHTTPMethod, + responseStatusCode: localVarHTTPResponse.StatusCode, + responseHeader: localVarHTTPResponse.Header, + } + newErr.error = "ListUsers error for " + localVarHTTPMethod + " ListUsers with body " + string(localVarBody) + newErr.requestId = localVarHTTPResponse.Header.Get("Fga-Request-Id") + + var v ErrorResponse + err = a.client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr.modelDecodeError = err + return localVarReturnValue, localVarHTTPResponse, newErr + } + newErr.model = v + newErr.responseCode = v.Code + newErr.error += " with error code " + v.Code + " error message: " + v.Message + + return localVarReturnValue, localVarHTTPResponse, newErr + } + + err = a.client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type")) + if err != nil { + newErr := GenericOpenAPIError{ + body: localVarBody, + error: err.Error(), + } + return localVarReturnValue, localVarHTTPResponse, newErr + } + + return localVarReturnValue, localVarHTTPResponse, nil + } + // should never have reached this + var localVarReturnValue ListUsersResponse + return localVarReturnValue, nil, reportError("Error not handled properly") +} + type ApiReadRequest struct { ctx _context.Context ApiService OpenFgaApi diff --git a/api_open_fga_test.go b/api_open_fga_test.go index 82104eb..f01890e 100644 --- a/api_open_fga_test.go +++ b/api_open_fga_test.go @@ -969,6 +969,80 @@ func TestOpenFgaApi(t *testing.T) { } }) + t.Run("ListUsers", func(t *testing.T) { + test := TestDefinition{ + Name: "ListUsers", + // A real API would not return all these for the filter provided, these are just for test purposes + JsonResponse: `{"users":[{"type":"user", "id":"81684243-9356-4421-8fbf-a4f8d36aa31b"}, {"type": "team", "relation": "member"}, {"type": "user", "wildcard": {}}]}`, + ResponseStatus: http.StatusOK, + Method: http.MethodPost, + RequestPath: "list-users", + } + + requestBody := ListUsersRequest{ + AuthorizationModelId: PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"), + Object: Object{ + Type: "document", + Id: "roadmap", + }, + Relation: "can_read", + UserFilters: []ListUsersFilter{{ + Type: "user", + }}, + ContextualTuples: &ContextualTupleKeys{ + TupleKeys: []TupleKey{{ + User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", + Relation: "editor", + Object: "folder:product", + }, { + User: "folder:product", + Relation: "parent", + Object: "document:roadmap", + }}, + }, + } + + var expectedResponse ListUsersResponse + if err := json.Unmarshal([]byte(test.JsonResponse), &expectedResponse); err != nil { + t.Fatalf("%v", err) + } + + httpmock.Activate() + defer httpmock.DeactivateAndReset() + httpmock.RegisterResponder(test.Method, fmt.Sprintf("%s/stores/%s/%s", configuration.ApiUrl, configuration.StoreId, test.RequestPath), + func(req *http.Request) (*http.Response, error) { + resp, err := httpmock.NewJsonResponse(test.ResponseStatus, expectedResponse) + if err != nil { + return httpmock.NewStringResponse(500, ""), nil + } + return resp, nil + }, + ) + got, response, err := apiClient.OpenFgaApi.ListUsers(context.Background()). + Body(requestBody). + Execute() + if err != nil { + t.Fatalf("%v", err) + } + + if response.StatusCode != test.ResponseStatus { + t.Fatalf("OpenFga%v().Execute() = %v, want %v", test.Name, response.StatusCode, test.ResponseStatus) + } + + responseJson, err := got.MarshalJSON() + if err != nil { + t.Fatalf("%v", err) + } + + if len(got.Users) != len(expectedResponse.Users) || (got.Users)[0] != (expectedResponse.Users)[0] { + t.Fatalf("OpenFga%v().Execute() = %v, want %v", test.Name, string(responseJson), test.JsonResponse) + } + + if string(responseJson) != test.JsonResponse { + t.Fatalf("OpenFgaClient.%v() = %v, want %v", test.Name, string(responseJson), test.JsonResponse) + } + }) + t.Run("Check with 400 error", func(t *testing.T) { test := TestDefinition{ Name: "Check", diff --git a/client/client.go b/client/client.go index 33ebec1..d5b2817 100644 --- a/client/client.go +++ b/client/client.go @@ -388,6 +388,19 @@ type SdkClient interface { */ ListRelationsExecute(request SdkClientListRelationsRequestInterface) (*ClientListRelationsResponse, error) + /* + * ListUsers List all users of the given type that the object has a relation with + * @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background(). + * @return ApiListUsersRequest + */ + ListUsers(ctx _context.Context) SdkClientListUsersRequestInterface + + /* + * ListUsersExecute executes the request + * @return ListUsersResponse + */ + ListUsersExecute(r SdkClientListUsersRequestInterface) (*ClientListUsersResponse, error) + /* Assertions */ /* @@ -2140,6 +2153,105 @@ func (client *OpenFgaClient) ListRelationsExecute(request SdkClientListRelations return &ClientListRelationsResponse{Relations: relations}, nil } +// / ListUsers +type SdkClientListUsersRequest struct { + ctx _context.Context + Client *OpenFgaClient + + body *ClientListUsersRequest + options *ClientListUsersOptions +} + +type SdkClientListUsersRequestInterface interface { + Options(options ClientListUsersOptions) SdkClientListUsersRequestInterface + Body(body ClientListUsersRequest) SdkClientListUsersRequestInterface + Execute() (*ClientListUsersResponse, error) + GetAuthorizationModelIdOverride() *string + + GetContext() _context.Context + GetBody() *ClientListUsersRequest + GetOptions() *ClientListUsersOptions +} + +type ClientListUsersRequest struct { + Object fgaSdk.Object `json:"object"yaml:"object"` + Relation string `json:"relation"yaml:"relation"` + UserFilters []fgaSdk.ListUsersFilter `json:"user_filters"yaml:"user_filters"` + //Context *map[string]interface{} `json:"context,omitempty"` + ContextualTuples []ClientContextualTupleKey `json:"contextual_tuples,omitempty"` +} + +type ClientListUsersOptions struct { + AuthorizationModelId *string `json:"authorization_model_id,omitempty"` +} + +type ClientListUsersResponse = fgaSdk.ListUsersResponse + +func (client *OpenFgaClient) ListUsers(ctx _context.Context) SdkClientListUsersRequestInterface { + return &SdkClientListUsersRequest{ + Client: client, + ctx: ctx, + } +} + +func (request *SdkClientListUsersRequest) Options(options ClientListUsersOptions) SdkClientListUsersRequestInterface { + request.options = &options + return request +} + +func (request *SdkClientListUsersRequest) GetAuthorizationModelIdOverride() *string { + if request.options == nil { + return nil + } + return request.options.AuthorizationModelId +} + +func (request *SdkClientListUsersRequest) Body(body ClientListUsersRequest) SdkClientListUsersRequestInterface { + request.body = &body + return request +} + +func (request *SdkClientListUsersRequest) Execute() (*ClientListUsersResponse, error) { + return request.Client.ListUsersExecute(request) +} + +func (request *SdkClientListUsersRequest) GetContext() _context.Context { + return request.ctx +} + +func (request *SdkClientListUsersRequest) GetBody() *ClientListUsersRequest { + return request.body +} + +func (request *SdkClientListUsersRequest) GetOptions() *ClientListUsersOptions { + return request.options +} + +func (client *OpenFgaClient) ListUsersExecute(request SdkClientListUsersRequestInterface) (*ClientListUsersResponse, error) { + var contextualTuples []ClientContextualTupleKey + if request.GetBody().ContextualTuples != nil { + for index := 0; index < len(request.GetBody().ContextualTuples); index++ { + contextualTuples = append(contextualTuples, (request.GetBody().ContextualTuples)[index]) + } + } + authorizationModelId, err := client.getAuthorizationModelId(request.GetAuthorizationModelIdOverride()) + if err != nil { + return nil, err + } + data, _, err := client.OpenFgaApi.ListUsers(request.GetContext()).Body(fgaSdk.ListUsersRequest{ + Object: request.GetBody().Object, + Relation: request.GetBody().Relation, + UserFilters: request.GetBody().UserFilters, + ContextualTuples: fgaSdk.NewContextualTupleKeys(contextualTuples), + //Context: request.GetBody().Context, + AuthorizationModelId: authorizationModelId, + }).Execute() + if err != nil { + return nil, err + } + return &data, nil +} + // / ReadAssertions type SdkClientReadAssertionsRequest struct { ctx _context.Context diff --git a/client/client_test.go b/client/client_test.go index 5446a96..5262739 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -1869,6 +1869,95 @@ func TestOpenFgaClient(t *testing.T) { } }) + t.Run("ListUsers", func(t *testing.T) { + test := TestDefinition{ + Name: "ListUsers", + // A real API would not return all these for the filter provided, these are just for test purposes + JsonResponse: `{"users":[{"type":"user", "id":"81684243-9356-4421-8fbf-a4f8d36aa31b"}, {"type": "team", "relation": "member"}, {"type": "user", "wildcard": {}}]}`, + ResponseStatus: http.StatusOK, + Method: http.MethodPost, + RequestPath: "list-users", + } + + requestBody := ClientListUsersRequest{ + Object: openfga.Object{ + Type: "document", + Id: "roadmap", + }, + Relation: "can_read", + UserFilters: []openfga.ListUsersFilter{{ + Type: "user", + }}, + ContextualTuples: []ClientContextualTupleKey{{ + User: "user:81684243-9356-4421-8fbf-a4f8d36aa31b", + Relation: "editor", + Object: "folder:product", + }, { + User: "folder:product", + Relation: "parent", + Object: "document:roadmap", + }}, + } + options := ClientListUsersOptions{ + AuthorizationModelId: openfga.PtrString("01GAHCE4YVKPQEKZQHT2R89MQV"), + } + + var expectedResponse openfga.ListUsersResponse + if err := json.Unmarshal([]byte(test.JsonResponse), &expectedResponse); err != nil { + t.Fatalf("%v", err) + } + + httpmock.Activate() + defer httpmock.DeactivateAndReset() + httpmock.RegisterResponder(test.Method, fmt.Sprintf("%s/stores/%s/%s", fgaClient.GetConfig().ApiUrl, fgaClient.GetConfig().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 + }, + ) + got, err := fgaClient.ListUsers(context.Background()). + Body(requestBody). + Options(options). + Execute() + if err != nil { + t.Fatalf("%v", err) + } + + responseJson, err := got.MarshalJSON() + if err != nil { + t.Fatalf("%v", err) + } + + if len(got.Users) != len(expectedResponse.Users) || (got.Users)[0] != (expectedResponse.Users)[0] { + t.Fatalf("OpenFgaClient.%v() = %v, want %v", test.Name, string(responseJson), test.JsonResponse) + } + + if string(responseJson) != test.JsonResponse { + t.Fatalf("OpenFgaClient.%v() = %v, want %v", test.Name, string(responseJson), test.JsonResponse) + } + + // ListUsers without options should work + _, err = fgaClient.ListUsers(context.Background()).Body(requestBody).Execute() + if err != nil { + t.Fatalf("%v", err) + } + + // Invalid auth model id should result in error + badOptions := ClientListUsersOptions{ + AuthorizationModelId: openfga.PtrString("INVALID"), + } + _, err = fgaClient.ListUsers(context.Background()). + Body(requestBody). + Options(badOptions). + Execute() + if err == nil { + t.Fatalf("Expect error with invalid auth model id but there is none") + } + }) + /* Assertions */ t.Run("ReadAssertions", func(t *testing.T) { modelId := "01GAHCE4YVKPQEKZQHT2R89MQV" diff --git a/docs/ListUsersFilter.md b/docs/ListUsersFilter.md new file mode 100644 index 0000000..baadeca --- /dev/null +++ b/docs/ListUsersFilter.md @@ -0,0 +1,77 @@ +# ListUsersFilter + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Type** | **string** | | +**Relation** | Pointer to **string** | | [optional] + +## Methods + +### NewListUsersFilter + +`func NewListUsersFilter(type_ string, ) *ListUsersFilter` + +NewListUsersFilter instantiates a new ListUsersFilter 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 + +### NewListUsersFilterWithDefaults + +`func NewListUsersFilterWithDefaults() *ListUsersFilter` + +NewListUsersFilterWithDefaults instantiates a new ListUsersFilter 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 + +### GetType + +`func (o *ListUsersFilter) GetType() string` + +GetType returns the Type field if non-nil, zero value otherwise. + +### GetTypeOk + +`func (o *ListUsersFilter) GetTypeOk() (*string, bool)` + +GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetType + +`func (o *ListUsersFilter) SetType(v string)` + +SetType sets Type field to given value. + + +### GetRelation + +`func (o *ListUsersFilter) GetRelation() string` + +GetRelation returns the Relation field if non-nil, zero value otherwise. + +### GetRelationOk + +`func (o *ListUsersFilter) GetRelationOk() (*string, bool)` + +GetRelationOk returns a tuple with the Relation field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetRelation + +`func (o *ListUsersFilter) SetRelation(v string)` + +SetRelation sets Relation field to given value. + +### HasRelation + +`func (o *ListUsersFilter) HasRelation() bool` + +HasRelation 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) + + diff --git a/docs/ListUsersRequest.md b/docs/ListUsersRequest.md new file mode 100644 index 0000000..5653621 --- /dev/null +++ b/docs/ListUsersRequest.md @@ -0,0 +1,145 @@ +# ListUsersRequest + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**AuthorizationModelId** | Pointer to **string** | | [optional] +**Object** | [**Object**](Object.md) | | +**Relation** | **string** | | +**UserFilters** | [**[]ListUsersFilter**](ListUsersFilter.md) | | +**ContextualTuples** | Pointer to [**ContextualTupleKeys**](ContextualTupleKeys.md) | | [optional] + +## Methods + +### NewListUsersRequest + +`func NewListUsersRequest(object Object, relation string, userFilters []ListUsersFilter, ) *ListUsersRequest` + +NewListUsersRequest instantiates a new ListUsersRequest 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 + +### NewListUsersRequestWithDefaults + +`func NewListUsersRequestWithDefaults() *ListUsersRequest` + +NewListUsersRequestWithDefaults instantiates a new ListUsersRequest 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 + +### GetAuthorizationModelId + +`func (o *ListUsersRequest) GetAuthorizationModelId() string` + +GetAuthorizationModelId returns the AuthorizationModelId field if non-nil, zero value otherwise. + +### GetAuthorizationModelIdOk + +`func (o *ListUsersRequest) GetAuthorizationModelIdOk() (*string, bool)` + +GetAuthorizationModelIdOk returns a tuple with the AuthorizationModelId field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetAuthorizationModelId + +`func (o *ListUsersRequest) SetAuthorizationModelId(v string)` + +SetAuthorizationModelId sets AuthorizationModelId field to given value. + +### HasAuthorizationModelId + +`func (o *ListUsersRequest) HasAuthorizationModelId() bool` + +HasAuthorizationModelId returns a boolean if a field has been set. + +### GetObject + +`func (o *ListUsersRequest) GetObject() Object` + +GetObject returns the Object field if non-nil, zero value otherwise. + +### GetObjectOk + +`func (o *ListUsersRequest) GetObjectOk() (*Object, bool)` + +GetObjectOk returns a tuple with the Object field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetObject + +`func (o *ListUsersRequest) SetObject(v Object)` + +SetObject sets Object field to given value. + + +### GetRelation + +`func (o *ListUsersRequest) GetRelation() string` + +GetRelation returns the Relation field if non-nil, zero value otherwise. + +### GetRelationOk + +`func (o *ListUsersRequest) GetRelationOk() (*string, bool)` + +GetRelationOk returns a tuple with the Relation field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetRelation + +`func (o *ListUsersRequest) SetRelation(v string)` + +SetRelation sets Relation field to given value. + + +### GetUserFilters + +`func (o *ListUsersRequest) GetUserFilters() []ListUsersFilter` + +GetUserFilters returns the UserFilters field if non-nil, zero value otherwise. + +### GetUserFiltersOk + +`func (o *ListUsersRequest) GetUserFiltersOk() (*[]ListUsersFilter, bool)` + +GetUserFiltersOk returns a tuple with the UserFilters field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetUserFilters + +`func (o *ListUsersRequest) SetUserFilters(v []ListUsersFilter)` + +SetUserFilters sets UserFilters field to given value. + + +### GetContextualTuples + +`func (o *ListUsersRequest) GetContextualTuples() ContextualTupleKeys` + +GetContextualTuples returns the ContextualTuples field if non-nil, zero value otherwise. + +### GetContextualTuplesOk + +`func (o *ListUsersRequest) GetContextualTuplesOk() (*ContextualTupleKeys, bool)` + +GetContextualTuplesOk returns a tuple with the ContextualTuples field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetContextualTuples + +`func (o *ListUsersRequest) SetContextualTuples(v ContextualTupleKeys)` + +SetContextualTuples sets ContextualTuples field to given value. + +### HasContextualTuples + +`func (o *ListUsersRequest) HasContextualTuples() bool` + +HasContextualTuples 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) + + diff --git a/docs/ListUsersResponse.md b/docs/ListUsersResponse.md new file mode 100644 index 0000000..46897c8 --- /dev/null +++ b/docs/ListUsersResponse.md @@ -0,0 +1,51 @@ +# ListUsersResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Users** | [**[]User**](User.md) | | + +## Methods + +### NewListUsersResponse + +`func NewListUsersResponse(users []User, ) *ListUsersResponse` + +NewListUsersResponse instantiates a new ListUsersResponse 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 + +### NewListUsersResponseWithDefaults + +`func NewListUsersResponseWithDefaults() *ListUsersResponse` + +NewListUsersResponseWithDefaults instantiates a new ListUsersResponse 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 + +### GetUsers + +`func (o *ListUsersResponse) GetUsers() []User` + +GetUsers returns the Users field if non-nil, zero value otherwise. + +### GetUsersOk + +`func (o *ListUsersResponse) GetUsersOk() (*[]User, bool)` + +GetUsersOk returns a tuple with the Users field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetUsers + +`func (o *ListUsersResponse) SetUsers(v []User)` + +SetUsers sets Users field to given value. + + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/Object.md b/docs/Object.md new file mode 100644 index 0000000..290ac19 --- /dev/null +++ b/docs/Object.md @@ -0,0 +1,72 @@ +# Object + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Type** | **string** | | +**Id** | **string** | | + +## Methods + +### NewObject + +`func NewObject(type_ string, id string, ) *Object` + +NewObject instantiates a new Object 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 + +### NewObjectWithDefaults + +`func NewObjectWithDefaults() *Object` + +NewObjectWithDefaults instantiates a new Object 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 + +### GetType + +`func (o *Object) GetType() string` + +GetType returns the Type field if non-nil, zero value otherwise. + +### GetTypeOk + +`func (o *Object) GetTypeOk() (*string, bool)` + +GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetType + +`func (o *Object) SetType(v string)` + +SetType sets Type field to given value. + + +### GetId + +`func (o *Object) GetId() string` + +GetId returns the Id field if non-nil, zero value otherwise. + +### GetIdOk + +`func (o *Object) GetIdOk() (*string, bool)` + +GetIdOk returns a tuple with the Id field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetId + +`func (o *Object) SetId(v string)` + +SetId sets Id field to given value. + + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/OpenFgaApi.md b/docs/OpenFgaApi.md index 5adc01e..2b8f11f 100644 --- a/docs/OpenFgaApi.md +++ b/docs/OpenFgaApi.md @@ -11,6 +11,7 @@ Method | HTTP request | Description [**GetStore**](OpenFgaApi.md#GetStore) | **Get** /stores/{store_id} | Get a store [**ListObjects**](OpenFgaApi.md#ListObjects) | **Post** /stores/{store_id}/list-objects | List all objects of the given type that the user has a relation with [**ListStores**](OpenFgaApi.md#ListStores) | **Get** /stores | List all stores +[**ListUsers**](OpenFgaApi.md#ListUsers) | **Post** /stores/{store_id}/list-users | List all users of the given type that the object has a relation with [**Read**](OpenFgaApi.md#Read) | **Post** /stores/{store_id}/read | Get tuples from the store that matches a query, without following userset rewrite rules [**ReadAssertions**](OpenFgaApi.md#ReadAssertions) | **Get** /stores/{store_id}/assertions/{authorization_model_id} | Read assertions for an authorization model ID [**ReadAuthorizationModel**](OpenFgaApi.md#ReadAuthorizationModel) | **Get** /stores/{store_id}/authorization-models/{id} | Return a particular version of an authorization model @@ -661,6 +662,97 @@ No authorization required [[Back to README]](../README.md) +## ListUsers + +> ListUsersResponse ListUsers(ctx).Body(body).Execute() + +List all users of the given type that the object has a relation with + +### Example + +```go +package main + +import ( + "context" + "fmt" + "os" + openfga "github.com/openfga/go-sdk" +) + +func main() { + + body := *openapiclient.NewListUsersRequest(*openapiclient.NewObject("document", "Id_example"), "reader", []openapiclient.ListUsersFilter{*openapiclient.NewListUsersFilter("group")}) // ListUsersRequest | + + configuration, err := openfga.NewConfiguration(openfga.Configuration{ + ApiUrl: os.Getenv("FGA_API_URL"), // required, e.g. https://api.fga.example + StoreId: os.Getenv("OPENFGA_STORE_ID"), // not needed when calling `CreateStore` or `ListStores` + }) + + if err != nil { + // .. Handle error + } + + apiClient := openfga.NewAPIClient(configuration) + + resp, r, err := apiClient.OpenFgaApi.ListUsers(context.Background()).Body(body).Execute() + if err != nil { + fmt.Fprintf(os.Stderr, "Error when calling `OpenFgaApi.ListUsers``: %v\n", err) + fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) + switch v := err.(type) { + case FgaApiAuthenticationError: + // Handle authentication error + case FgaApiValidationError: + // Handle parameter validation error + case FgaApiNotFoundError: + // Handle not found error + case FgaApiInternalError: + // Handle API internal error + case FgaApiRateLimitError: + // Exponential backoff in handling rate limit error + default: + // Handle unknown/undefined error + } + } + // response from `ListUsers`: ListUsersResponse + fmt.Fprintf(os.Stdout, "Response from `OpenFgaApi.ListUsers`: %v\n", resp) +} +``` + +### Path Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc. + +### Other Parameters + +Other parameters are passed through a pointer to a apiListUsersRequest struct via the builder pattern + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- +**body** | [**ListUsersRequest**](ListUsersRequest.md) | | + +### Return type + +[**ListUsersResponse**](ListUsersResponse.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) +[[Back to Model list]](../README.md#documentation-for-models) +[[Back to README]](../README.md) + + ## Read > ReadResponse Read(ctx).Body(body).Execute() diff --git a/docs/TypedWildcard.md b/docs/TypedWildcard.md new file mode 100644 index 0000000..520b880 --- /dev/null +++ b/docs/TypedWildcard.md @@ -0,0 +1,77 @@ +# TypedWildcard + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Type** | **string** | | +**Wildcard** | Pointer to **map[string]interface{}** | | [optional] + +## Methods + +### NewTypedWildcard + +`func NewTypedWildcard(type_ string, ) *TypedWildcard` + +NewTypedWildcard instantiates a new TypedWildcard 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 + +### NewTypedWildcardWithDefaults + +`func NewTypedWildcardWithDefaults() *TypedWildcard` + +NewTypedWildcardWithDefaults instantiates a new TypedWildcard 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 + +### GetType + +`func (o *TypedWildcard) GetType() string` + +GetType returns the Type field if non-nil, zero value otherwise. + +### GetTypeOk + +`func (o *TypedWildcard) GetTypeOk() (*string, bool)` + +GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetType + +`func (o *TypedWildcard) SetType(v string)` + +SetType sets Type field to given value. + + +### GetWildcard + +`func (o *TypedWildcard) GetWildcard() map[string]interface{}` + +GetWildcard returns the Wildcard field if non-nil, zero value otherwise. + +### GetWildcardOk + +`func (o *TypedWildcard) GetWildcardOk() (*map[string]interface{}, bool)` + +GetWildcardOk returns a tuple with the Wildcard field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetWildcard + +`func (o *TypedWildcard) SetWildcard(v map[string]interface{})` + +SetWildcard sets Wildcard field to given value. + +### HasWildcard + +`func (o *TypedWildcard) HasWildcard() bool` + +HasWildcard 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) + + diff --git a/docs/User.md b/docs/User.md new file mode 100644 index 0000000..3e73fdb --- /dev/null +++ b/docs/User.md @@ -0,0 +1,108 @@ +# User + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Object** | Pointer to [**Object**](Object.md) | | [optional] +**Userset** | Pointer to [**UsersetUser**](UsersetUser.md) | | [optional] +**Wildcard** | Pointer to [**TypedWildcard**](TypedWildcard.md) | | [optional] + +## Methods + +### NewUser + +`func NewUser() *User` + +NewUser instantiates a new User 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 + +### NewUserWithDefaults + +`func NewUserWithDefaults() *User` + +NewUserWithDefaults instantiates a new User 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 + +### GetObject + +`func (o *User) GetObject() Object` + +GetObject returns the Object field if non-nil, zero value otherwise. + +### GetObjectOk + +`func (o *User) GetObjectOk() (*Object, bool)` + +GetObjectOk returns a tuple with the Object field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetObject + +`func (o *User) SetObject(v Object)` + +SetObject sets Object field to given value. + +### HasObject + +`func (o *User) HasObject() bool` + +HasObject returns a boolean if a field has been set. + +### GetUserset + +`func (o *User) GetUserset() UsersetUser` + +GetUserset returns the Userset field if non-nil, zero value otherwise. + +### GetUsersetOk + +`func (o *User) GetUsersetOk() (*UsersetUser, bool)` + +GetUsersetOk returns a tuple with the Userset field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetUserset + +`func (o *User) SetUserset(v UsersetUser)` + +SetUserset sets Userset field to given value. + +### HasUserset + +`func (o *User) HasUserset() bool` + +HasUserset returns a boolean if a field has been set. + +### GetWildcard + +`func (o *User) GetWildcard() TypedWildcard` + +GetWildcard returns the Wildcard field if non-nil, zero value otherwise. + +### GetWildcardOk + +`func (o *User) GetWildcardOk() (*TypedWildcard, bool)` + +GetWildcardOk returns a tuple with the Wildcard field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetWildcard + +`func (o *User) SetWildcard(v TypedWildcard)` + +SetWildcard sets Wildcard field to given value. + +### HasWildcard + +`func (o *User) HasWildcard() bool` + +HasWildcard 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) + + diff --git a/docs/UsersetUser.md b/docs/UsersetUser.md new file mode 100644 index 0000000..04d2d73 --- /dev/null +++ b/docs/UsersetUser.md @@ -0,0 +1,93 @@ +# UsersetUser + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**Type** | **string** | | +**Id** | **string** | | +**Relation** | **string** | | + +## Methods + +### NewUsersetUser + +`func NewUsersetUser(type_ string, id string, relation string, ) *UsersetUser` + +NewUsersetUser instantiates a new UsersetUser 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 + +### NewUsersetUserWithDefaults + +`func NewUsersetUserWithDefaults() *UsersetUser` + +NewUsersetUserWithDefaults instantiates a new UsersetUser 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 + +### GetType + +`func (o *UsersetUser) GetType() string` + +GetType returns the Type field if non-nil, zero value otherwise. + +### GetTypeOk + +`func (o *UsersetUser) GetTypeOk() (*string, bool)` + +GetTypeOk returns a tuple with the Type field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetType + +`func (o *UsersetUser) SetType(v string)` + +SetType sets Type field to given value. + + +### GetId + +`func (o *UsersetUser) GetId() string` + +GetId returns the Id field if non-nil, zero value otherwise. + +### GetIdOk + +`func (o *UsersetUser) GetIdOk() (*string, bool)` + +GetIdOk returns a tuple with the Id field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetId + +`func (o *UsersetUser) SetId(v string)` + +SetId sets Id field to given value. + + +### GetRelation + +`func (o *UsersetUser) GetRelation() string` + +GetRelation returns the Relation field if non-nil, zero value otherwise. + +### GetRelationOk + +`func (o *UsersetUser) GetRelationOk() (*string, bool)` + +GetRelationOk returns a tuple with the Relation field if it's non-nil, zero value otherwise +and a boolean to check if the value has been set. + +### SetRelation + +`func (o *UsersetUser) SetRelation(v string)` + +SetRelation sets Relation field to given value. + + + +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/example/example1/example1.go b/example/example1/example1.go index 3b42858..c2c7644 100644 --- a/example/example1/example1.go +++ b/example/example1/example1.go @@ -243,6 +243,38 @@ func mainInner() error { } fmt.Printf("Allowed: %v\n", checkResponse.Allowed) + // ListObjects + fmt.Println("Listing objects user has access to") + listObjectsResponse, err := fgaClient.ListObjects(ctx).Body(client.ClientListObjectsRequest{ + User: "user:anne", + Relation: "viewer", + Type: "document", + }).Execute() + fmt.Printf("Response: Objects = %v\n", listObjectsResponse.Objects) + + // ListRelations + fmt.Println("Listing relations user has with object") + listRelationsResponse, err := fgaClient.ListRelations(ctx).Body(client.ClientListRelationsRequest{ + User: "user:anne", + Object: "document:roadmap", + Relations: []string{"viewer"}, + }).Execute() + fmt.Printf("Response: Relations = %v\n", listRelationsResponse.Relations) + + // ListUsers + fmt.Println("Listing user who have access to object") + listUsersResponse, err := fgaClient.ListUsers(ctx).Body(client.ClientListUsersRequest{ + Relation: "viewer", + Object: openfga.Object{ + Type: "document", + Id: "roadmap", + }, + UserFilters: []openfga.ListUsersFilter{{ + Type: "user", + }}, + }).Execute() + fmt.Printf("Response: Users = %v\n", listUsersResponse.Users) + // WriteAssertions _, err = fgaClient.WriteAssertions(ctx).Body([]client.ClientAssertion{ { diff --git a/model_list_users_filter.go b/model_list_users_filter.go new file mode 100644 index 0000000..b27d453 --- /dev/null +++ b/model_list_users_filter.go @@ -0,0 +1,151 @@ +/** + * Go SDK for OpenFGA + * + * API version: 0.1 + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/go-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + +package openfga + +import ( + "bytes" + + "encoding/json" +) + +// ListUsersFilter struct for ListUsersFilter +type ListUsersFilter struct { + Type string `json:"type"yaml:"type"` + Relation *string `json:"relation,omitempty"yaml:"relation,omitempty"` +} + +// NewListUsersFilter instantiates a new ListUsersFilter 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 +func NewListUsersFilter(type_ string) *ListUsersFilter { + this := ListUsersFilter{} + this.Type = type_ + return &this +} + +// NewListUsersFilterWithDefaults instantiates a new ListUsersFilter 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 +func NewListUsersFilterWithDefaults() *ListUsersFilter { + this := ListUsersFilter{} + return &this +} + +// GetType returns the Type field value +func (o *ListUsersFilter) GetType() string { + if o == nil { + var ret string + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *ListUsersFilter) GetTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *ListUsersFilter) SetType(v string) { + o.Type = v +} + +// GetRelation returns the Relation field value if set, zero value otherwise. +func (o *ListUsersFilter) GetRelation() string { + if o == nil || o.Relation == nil { + var ret string + return ret + } + return *o.Relation +} + +// GetRelationOk returns a tuple with the Relation field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ListUsersFilter) GetRelationOk() (*string, bool) { + if o == nil || o.Relation == nil { + return nil, false + } + return o.Relation, true +} + +// HasRelation returns a boolean if a field has been set. +func (o *ListUsersFilter) HasRelation() bool { + if o != nil && o.Relation != nil { + return true + } + + return false +} + +// SetRelation gets a reference to the given string and assigns it to the Relation field. +func (o *ListUsersFilter) SetRelation(v string) { + o.Relation = &v +} + +func (o ListUsersFilter) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + toSerialize["type"] = o.Type + if o.Relation != nil { + toSerialize["relation"] = o.Relation + } + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil +} + +type NullableListUsersFilter struct { + value *ListUsersFilter + isSet bool +} + +func (v NullableListUsersFilter) Get() *ListUsersFilter { + return v.value +} + +func (v *NullableListUsersFilter) Set(val *ListUsersFilter) { + v.value = val + v.isSet = true +} + +func (v NullableListUsersFilter) IsSet() bool { + return v.isSet +} + +func (v *NullableListUsersFilter) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableListUsersFilter(val *ListUsersFilter) *NullableListUsersFilter { + return &NullableListUsersFilter{value: val, isSet: true} +} + +func (v NullableListUsersFilter) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableListUsersFilter) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/model_list_users_request.go b/model_list_users_request.go new file mode 100644 index 0000000..fa3de32 --- /dev/null +++ b/model_list_users_request.go @@ -0,0 +1,241 @@ +/** + * Go SDK for OpenFGA + * + * API version: 0.1 + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/go-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + +package openfga + +import ( + "bytes" + + "encoding/json" +) + +// ListUsersRequest struct for ListUsersRequest +type ListUsersRequest struct { + AuthorizationModelId *string `json:"authorization_model_id,omitempty"yaml:"authorization_model_id,omitempty"` + Object Object `json:"object"yaml:"object"` + Relation string `json:"relation"yaml:"relation"` + UserFilters []ListUsersFilter `json:"user_filters"yaml:"user_filters"` + ContextualTuples *ContextualTupleKeys `json:"contextual_tuples,omitempty"yaml:"contextual_tuples,omitempty"` +} + +// NewListUsersRequest instantiates a new ListUsersRequest 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 +func NewListUsersRequest(object Object, relation string, userFilters []ListUsersFilter) *ListUsersRequest { + this := ListUsersRequest{} + this.Object = object + this.Relation = relation + this.UserFilters = userFilters + return &this +} + +// NewListUsersRequestWithDefaults instantiates a new ListUsersRequest 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 +func NewListUsersRequestWithDefaults() *ListUsersRequest { + this := ListUsersRequest{} + return &this +} + +// GetAuthorizationModelId returns the AuthorizationModelId field value if set, zero value otherwise. +func (o *ListUsersRequest) GetAuthorizationModelId() string { + if o == nil || o.AuthorizationModelId == nil { + var ret string + return ret + } + return *o.AuthorizationModelId +} + +// GetAuthorizationModelIdOk returns a tuple with the AuthorizationModelId field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ListUsersRequest) GetAuthorizationModelIdOk() (*string, bool) { + if o == nil || o.AuthorizationModelId == nil { + return nil, false + } + return o.AuthorizationModelId, true +} + +// HasAuthorizationModelId returns a boolean if a field has been set. +func (o *ListUsersRequest) HasAuthorizationModelId() bool { + if o != nil && o.AuthorizationModelId != nil { + return true + } + + return false +} + +// SetAuthorizationModelId gets a reference to the given string and assigns it to the AuthorizationModelId field. +func (o *ListUsersRequest) SetAuthorizationModelId(v string) { + o.AuthorizationModelId = &v +} + +// GetObject returns the Object field value +func (o *ListUsersRequest) GetObject() Object { + if o == nil { + var ret Object + return ret + } + + return o.Object +} + +// GetObjectOk returns a tuple with the Object field value +// and a boolean to check if the value has been set. +func (o *ListUsersRequest) GetObjectOk() (*Object, bool) { + if o == nil { + return nil, false + } + return &o.Object, true +} + +// SetObject sets field value +func (o *ListUsersRequest) SetObject(v Object) { + o.Object = v +} + +// GetRelation returns the Relation field value +func (o *ListUsersRequest) GetRelation() string { + if o == nil { + var ret string + return ret + } + + return o.Relation +} + +// GetRelationOk returns a tuple with the Relation field value +// and a boolean to check if the value has been set. +func (o *ListUsersRequest) GetRelationOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Relation, true +} + +// SetRelation sets field value +func (o *ListUsersRequest) SetRelation(v string) { + o.Relation = v +} + +// GetUserFilters returns the UserFilters field value +func (o *ListUsersRequest) GetUserFilters() []ListUsersFilter { + if o == nil { + var ret []ListUsersFilter + return ret + } + + return o.UserFilters +} + +// GetUserFiltersOk returns a tuple with the UserFilters field value +// and a boolean to check if the value has been set. +func (o *ListUsersRequest) GetUserFiltersOk() (*[]ListUsersFilter, bool) { + if o == nil { + return nil, false + } + return &o.UserFilters, true +} + +// SetUserFilters sets field value +func (o *ListUsersRequest) SetUserFilters(v []ListUsersFilter) { + o.UserFilters = v +} + +// GetContextualTuples returns the ContextualTuples field value if set, zero value otherwise. +func (o *ListUsersRequest) GetContextualTuples() ContextualTupleKeys { + if o == nil || o.ContextualTuples == nil { + var ret ContextualTupleKeys + return ret + } + return *o.ContextualTuples +} + +// GetContextualTuplesOk returns a tuple with the ContextualTuples field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *ListUsersRequest) GetContextualTuplesOk() (*ContextualTupleKeys, bool) { + if o == nil || o.ContextualTuples == nil { + return nil, false + } + return o.ContextualTuples, true +} + +// HasContextualTuples returns a boolean if a field has been set. +func (o *ListUsersRequest) HasContextualTuples() bool { + if o != nil && o.ContextualTuples != nil { + return true + } + + return false +} + +// SetContextualTuples gets a reference to the given ContextualTupleKeys and assigns it to the ContextualTuples field. +func (o *ListUsersRequest) SetContextualTuples(v ContextualTupleKeys) { + o.ContextualTuples = &v +} + +func (o ListUsersRequest) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.AuthorizationModelId != nil { + toSerialize["authorization_model_id"] = o.AuthorizationModelId + } + toSerialize["object"] = o.Object + toSerialize["relation"] = o.Relation + toSerialize["user_filters"] = o.UserFilters + if o.ContextualTuples != nil { + toSerialize["contextual_tuples"] = o.ContextualTuples + } + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil +} + +type NullableListUsersRequest struct { + value *ListUsersRequest + isSet bool +} + +func (v NullableListUsersRequest) Get() *ListUsersRequest { + return v.value +} + +func (v *NullableListUsersRequest) Set(val *ListUsersRequest) { + v.value = val + v.isSet = true +} + +func (v NullableListUsersRequest) IsSet() bool { + return v.isSet +} + +func (v *NullableListUsersRequest) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableListUsersRequest(val *ListUsersRequest) *NullableListUsersRequest { + return &NullableListUsersRequest{value: val, isSet: true} +} + +func (v NullableListUsersRequest) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableListUsersRequest) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/model_list_users_response.go b/model_list_users_response.go new file mode 100644 index 0000000..bb267e5 --- /dev/null +++ b/model_list_users_response.go @@ -0,0 +1,115 @@ +/** + * Go SDK for OpenFGA + * + * API version: 0.1 + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/go-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + +package openfga + +import ( + "bytes" + + "encoding/json" +) + +// ListUsersResponse struct for ListUsersResponse +type ListUsersResponse struct { + Users []User `json:"users"yaml:"users"` +} + +// NewListUsersResponse instantiates a new ListUsersResponse 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 +func NewListUsersResponse(users []User) *ListUsersResponse { + this := ListUsersResponse{} + this.Users = users + return &this +} + +// NewListUsersResponseWithDefaults instantiates a new ListUsersResponse 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 +func NewListUsersResponseWithDefaults() *ListUsersResponse { + this := ListUsersResponse{} + return &this +} + +// GetUsers returns the Users field value +func (o *ListUsersResponse) GetUsers() []User { + if o == nil { + var ret []User + return ret + } + + return o.Users +} + +// GetUsersOk returns a tuple with the Users field value +// and a boolean to check if the value has been set. +func (o *ListUsersResponse) GetUsersOk() (*[]User, bool) { + if o == nil { + return nil, false + } + return &o.Users, true +} + +// SetUsers sets field value +func (o *ListUsersResponse) SetUsers(v []User) { + o.Users = v +} + +func (o ListUsersResponse) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + toSerialize["users"] = o.Users + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil +} + +type NullableListUsersResponse struct { + value *ListUsersResponse + isSet bool +} + +func (v NullableListUsersResponse) Get() *ListUsersResponse { + return v.value +} + +func (v *NullableListUsersResponse) Set(val *ListUsersResponse) { + v.value = val + v.isSet = true +} + +func (v NullableListUsersResponse) IsSet() bool { + return v.isSet +} + +func (v *NullableListUsersResponse) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableListUsersResponse(val *ListUsersResponse) *NullableListUsersResponse { + return &NullableListUsersResponse{value: val, isSet: true} +} + +func (v NullableListUsersResponse) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableListUsersResponse) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/model_object.go b/model_object.go new file mode 100644 index 0000000..e90280b --- /dev/null +++ b/model_object.go @@ -0,0 +1,142 @@ +/** + * Go SDK for OpenFGA + * + * API version: 0.1 + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/go-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + +package openfga + +import ( + "bytes" + + "encoding/json" +) + +// Object Object represents an OpenFGA Object. An Object is composed of a type and identifier (e.g. 'document:1') See https://openfga.dev/docs/concepts#what-is-an-object +type Object struct { + Type string `json:"type"yaml:"type"` + Id string `json:"id"yaml:"id"` +} + +// NewObject instantiates a new Object 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 +func NewObject(type_ string, id string) *Object { + this := Object{} + this.Type = type_ + this.Id = id + return &this +} + +// NewObjectWithDefaults instantiates a new Object 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 +func NewObjectWithDefaults() *Object { + this := Object{} + return &this +} + +// GetType returns the Type field value +func (o *Object) GetType() string { + if o == nil { + var ret string + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *Object) GetTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *Object) SetType(v string) { + o.Type = v +} + +// GetId returns the Id field value +func (o *Object) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *Object) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *Object) SetId(v string) { + o.Id = v +} + +func (o Object) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + toSerialize["type"] = o.Type + toSerialize["id"] = o.Id + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil +} + +type NullableObject struct { + value *Object + isSet bool +} + +func (v NullableObject) Get() *Object { + return v.value +} + +func (v *NullableObject) Set(val *Object) { + v.value = val + v.isSet = true +} + +func (v NullableObject) IsSet() bool { + return v.isSet +} + +func (v *NullableObject) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableObject(val *Object) *NullableObject { + return &NullableObject{value: val, isSet: true} +} + +func (v NullableObject) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableObject) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/model_typed_wildcard.go b/model_typed_wildcard.go new file mode 100644 index 0000000..f9de2d8 --- /dev/null +++ b/model_typed_wildcard.go @@ -0,0 +1,151 @@ +/** + * Go SDK for OpenFGA + * + * API version: 0.1 + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/go-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + +package openfga + +import ( + "bytes" + + "encoding/json" +) + +// TypedWildcard struct for TypedWildcard +type TypedWildcard struct { + Type string `json:"type"yaml:"type"` + Wildcard *map[string]interface{} `json:"wildcard,omitempty"yaml:"wildcard,omitempty"` +} + +// NewTypedWildcard instantiates a new TypedWildcard 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 +func NewTypedWildcard(type_ string) *TypedWildcard { + this := TypedWildcard{} + this.Type = type_ + return &this +} + +// NewTypedWildcardWithDefaults instantiates a new TypedWildcard 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 +func NewTypedWildcardWithDefaults() *TypedWildcard { + this := TypedWildcard{} + return &this +} + +// GetType returns the Type field value +func (o *TypedWildcard) GetType() string { + if o == nil { + var ret string + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *TypedWildcard) GetTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *TypedWildcard) SetType(v string) { + o.Type = v +} + +// GetWildcard returns the Wildcard field value if set, zero value otherwise. +func (o *TypedWildcard) GetWildcard() map[string]interface{} { + if o == nil || o.Wildcard == nil { + var ret map[string]interface{} + return ret + } + return *o.Wildcard +} + +// GetWildcardOk returns a tuple with the Wildcard field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *TypedWildcard) GetWildcardOk() (*map[string]interface{}, bool) { + if o == nil || o.Wildcard == nil { + return nil, false + } + return o.Wildcard, true +} + +// HasWildcard returns a boolean if a field has been set. +func (o *TypedWildcard) HasWildcard() bool { + if o != nil && o.Wildcard != nil { + return true + } + + return false +} + +// SetWildcard gets a reference to the given map[string]interface{} and assigns it to the Wildcard field. +func (o *TypedWildcard) SetWildcard(v map[string]interface{}) { + o.Wildcard = &v +} + +func (o TypedWildcard) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + toSerialize["type"] = o.Type + if o.Wildcard != nil { + toSerialize["wildcard"] = o.Wildcard + } + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil +} + +type NullableTypedWildcard struct { + value *TypedWildcard + isSet bool +} + +func (v NullableTypedWildcard) Get() *TypedWildcard { + return v.value +} + +func (v *NullableTypedWildcard) Set(val *TypedWildcard) { + v.value = val + v.isSet = true +} + +func (v NullableTypedWildcard) IsSet() bool { + return v.isSet +} + +func (v *NullableTypedWildcard) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableTypedWildcard(val *TypedWildcard) *NullableTypedWildcard { + return &NullableTypedWildcard{value: val, isSet: true} +} + +func (v NullableTypedWildcard) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableTypedWildcard) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/model_user.go b/model_user.go new file mode 100644 index 0000000..a3403c7 --- /dev/null +++ b/model_user.go @@ -0,0 +1,196 @@ +/** + * Go SDK for OpenFGA + * + * API version: 0.1 + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/go-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + +package openfga + +import ( + "bytes" + + "encoding/json" +) + +// User struct for User +type User struct { + Object *Object `json:"object,omitempty"yaml:"object,omitempty"` + Userset *UsersetUser `json:"userset,omitempty"yaml:"userset,omitempty"` + Wildcard *TypedWildcard `json:"wildcard,omitempty"yaml:"wildcard,omitempty"` +} + +// NewUser instantiates a new User 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 +func NewUser() *User { + this := User{} + return &this +} + +// NewUserWithDefaults instantiates a new User 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 +func NewUserWithDefaults() *User { + this := User{} + return &this +} + +// GetObject returns the Object field value if set, zero value otherwise. +func (o *User) GetObject() Object { + if o == nil || o.Object == nil { + var ret Object + return ret + } + return *o.Object +} + +// GetObjectOk returns a tuple with the Object field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *User) GetObjectOk() (*Object, bool) { + if o == nil || o.Object == nil { + return nil, false + } + return o.Object, true +} + +// HasObject returns a boolean if a field has been set. +func (o *User) HasObject() bool { + if o != nil && o.Object != nil { + return true + } + + return false +} + +// SetObject gets a reference to the given Object and assigns it to the Object field. +func (o *User) SetObject(v Object) { + o.Object = &v +} + +// GetUserset returns the Userset field value if set, zero value otherwise. +func (o *User) GetUserset() UsersetUser { + if o == nil || o.Userset == nil { + var ret UsersetUser + return ret + } + return *o.Userset +} + +// GetUsersetOk returns a tuple with the Userset field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *User) GetUsersetOk() (*UsersetUser, bool) { + if o == nil || o.Userset == nil { + return nil, false + } + return o.Userset, true +} + +// HasUserset returns a boolean if a field has been set. +func (o *User) HasUserset() bool { + if o != nil && o.Userset != nil { + return true + } + + return false +} + +// SetUserset gets a reference to the given UsersetUser and assigns it to the Userset field. +func (o *User) SetUserset(v UsersetUser) { + o.Userset = &v +} + +// GetWildcard returns the Wildcard field value if set, zero value otherwise. +func (o *User) GetWildcard() TypedWildcard { + if o == nil || o.Wildcard == nil { + var ret TypedWildcard + return ret + } + return *o.Wildcard +} + +// GetWildcardOk returns a tuple with the Wildcard field value if set, nil otherwise +// and a boolean to check if the value has been set. +func (o *User) GetWildcardOk() (*TypedWildcard, bool) { + if o == nil || o.Wildcard == nil { + return nil, false + } + return o.Wildcard, true +} + +// HasWildcard returns a boolean if a field has been set. +func (o *User) HasWildcard() bool { + if o != nil && o.Wildcard != nil { + return true + } + + return false +} + +// SetWildcard gets a reference to the given TypedWildcard and assigns it to the Wildcard field. +func (o *User) SetWildcard(v TypedWildcard) { + o.Wildcard = &v +} + +func (o User) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + if o.Object != nil { + toSerialize["object"] = o.Object + } + if o.Userset != nil { + toSerialize["userset"] = o.Userset + } + if o.Wildcard != nil { + toSerialize["wildcard"] = o.Wildcard + } + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil +} + +type NullableUser struct { + value *User + isSet bool +} + +func (v NullableUser) Get() *User { + return v.value +} + +func (v *NullableUser) Set(val *User) { + v.value = val + v.isSet = true +} + +func (v NullableUser) IsSet() bool { + return v.isSet +} + +func (v *NullableUser) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUser(val *User) *NullableUser { + return &NullableUser{value: val, isSet: true} +} + +func (v NullableUser) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUser) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +} diff --git a/model_userset_user.go b/model_userset_user.go new file mode 100644 index 0000000..981aef0 --- /dev/null +++ b/model_userset_user.go @@ -0,0 +1,169 @@ +/** + * Go SDK for OpenFGA + * + * API version: 0.1 + * Website: https://openfga.dev + * Documentation: https://openfga.dev/docs + * Support: https://openfga.dev/community + * License: [Apache-2.0](https://github.com/openfga/go-sdk/blob/main/LICENSE) + * + * NOTE: This file was auto generated by OpenAPI Generator (https://openapi-generator.tech). DO NOT EDIT. + */ + +package openfga + +import ( + "bytes" + + "encoding/json" +) + +// UsersetUser struct for UsersetUser +type UsersetUser struct { + Type string `json:"type"yaml:"type"` + Id string `json:"id"yaml:"id"` + Relation string `json:"relation"yaml:"relation"` +} + +// NewUsersetUser instantiates a new UsersetUser 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 +func NewUsersetUser(type_ string, id string, relation string) *UsersetUser { + this := UsersetUser{} + this.Type = type_ + this.Id = id + this.Relation = relation + return &this +} + +// NewUsersetUserWithDefaults instantiates a new UsersetUser 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 +func NewUsersetUserWithDefaults() *UsersetUser { + this := UsersetUser{} + return &this +} + +// GetType returns the Type field value +func (o *UsersetUser) GetType() string { + if o == nil { + var ret string + return ret + } + + return o.Type +} + +// GetTypeOk returns a tuple with the Type field value +// and a boolean to check if the value has been set. +func (o *UsersetUser) GetTypeOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Type, true +} + +// SetType sets field value +func (o *UsersetUser) SetType(v string) { + o.Type = v +} + +// GetId returns the Id field value +func (o *UsersetUser) GetId() string { + if o == nil { + var ret string + return ret + } + + return o.Id +} + +// GetIdOk returns a tuple with the Id field value +// and a boolean to check if the value has been set. +func (o *UsersetUser) GetIdOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Id, true +} + +// SetId sets field value +func (o *UsersetUser) SetId(v string) { + o.Id = v +} + +// GetRelation returns the Relation field value +func (o *UsersetUser) GetRelation() string { + if o == nil { + var ret string + return ret + } + + return o.Relation +} + +// GetRelationOk returns a tuple with the Relation field value +// and a boolean to check if the value has been set. +func (o *UsersetUser) GetRelationOk() (*string, bool) { + if o == nil { + return nil, false + } + return &o.Relation, true +} + +// SetRelation sets field value +func (o *UsersetUser) SetRelation(v string) { + o.Relation = v +} + +func (o UsersetUser) MarshalJSON() ([]byte, error) { + toSerialize := map[string]interface{}{} + toSerialize["type"] = o.Type + toSerialize["id"] = o.Id + toSerialize["relation"] = o.Relation + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + err := enc.Encode(toSerialize) + if err != nil { + return nil, err + } + return b.Bytes(), nil +} + +type NullableUsersetUser struct { + value *UsersetUser + isSet bool +} + +func (v NullableUsersetUser) Get() *UsersetUser { + return v.value +} + +func (v *NullableUsersetUser) Set(val *UsersetUser) { + v.value = val + v.isSet = true +} + +func (v NullableUsersetUser) IsSet() bool { + return v.isSet +} + +func (v *NullableUsersetUser) Unset() { + v.value = nil + v.isSet = false +} + +func NewNullableUsersetUser(val *UsersetUser) *NullableUsersetUser { + return &NullableUsersetUser{value: val, isSet: true} +} + +func (v NullableUsersetUser) MarshalJSON() ([]byte, error) { + return json.Marshal(v.value) +} + +func (v *NullableUsersetUser) UnmarshalJSON(src []byte) error { + v.isSet = true + return json.Unmarshal(src, &v.value) +}