diff --git a/cmd/model/write.go b/cmd/model/write.go index 02f969e..87d6d78 100644 --- a/cmd/model/write.go +++ b/cmd/model/write.go @@ -34,12 +34,13 @@ func Write( fgaClient client.SdkClient, inputModel authorizationmodel.AuthzModel, ) (*client.ClientWriteAuthorizationModelResponse, error) { - body := &client.ClientWriteAuthorizationModelRequest{ + body := client.ClientWriteAuthorizationModelRequest{ SchemaVersion: inputModel.GetSchemaVersion(), TypeDefinitions: inputModel.GetTypeDefinitions(), + Conditions: inputModel.GetConditions(), } - model, err := fgaClient.WriteAuthorizationModel(context.Background()).Body(*body).Execute() + model, err := fgaClient.WriteAuthorizationModel(context.Background()).Body(body).Execute() if err != nil { return nil, fmt.Errorf("failed to write model due to %w", err) } diff --git a/cmd/model/write_test.go b/cmd/model/write_test.go index ca24506..75ce260 100644 --- a/cmd/model/write_test.go +++ b/cmd/model/write_test.go @@ -22,7 +22,7 @@ func TestWriteModelFail(t *testing.T) { defer mockCtrl.Finish() mockFgaClient := mockclient.NewMockSdkClient(mockCtrl) - modelJSONTxt := `{"schema_version":"1.1","type_definitions":[{"relations":{"viewer":{"this":{}}},"type":"github-repo"}]}` //nolint:lll + modelJSONTxt := `{"schema_version":"1.1","type_definitions":[{"relations":{"viewer":{"this":{}}},"type":"github-repo"}],"conditions":{}}` //nolint:lll body := &client.ClientWriteAuthorizationModelRequest{} err := json.Unmarshal([]byte(modelJSONTxt), &body) @@ -58,7 +58,7 @@ func TestWriteModel(t *testing.T) { defer mockCtrl.Finish() mockFgaClient := mockclient.NewMockSdkClient(mockCtrl) - modelJSONTxt := `{"schema_version":"1.1","type_definitions":[{"relations":{"viewer":{"this":{}}},"type":"github-repo"}]}` //nolint:lll + modelJSONTxt := `{"schema_version":"1.1","type_definitions":[{"relations":{"viewer":{"this":{}}},"type":"github-repo"}],"conditions":{}}` //nolint:lll body := &client.ClientWriteAuthorizationModelRequest{} diff --git a/internal/authorizationmodel/model.go b/internal/authorizationmodel/model.go index 2adead4..a04a4ce 100644 --- a/internal/authorizationmodel/model.go +++ b/internal/authorizationmodel/model.go @@ -83,6 +83,20 @@ func (model *AuthzModel) GetTypeDefinitions() []openfga.TypeDefinition { return *model.TypeDefinitions } +func (model *AuthzModel) GetConditions() *map[string]openfga.Condition { + conditions := make(map[string]openfga.Condition) + + if model == nil || model.Conditions == nil { + return &conditions + } + + for conditionName, condition := range model.Conditions { + conditions[conditionName] = *condition + } + + return &conditions +} + func (model *AuthzModel) GetProtoModel() *pb.AuthorizationModel { if model == nil { return nil