Skip to content

Commit

Permalink
fix API breakages
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Dec 19, 2024
1 parent 2293c22 commit d95d526
Show file tree
Hide file tree
Showing 32 changed files with 1,944 additions and 399 deletions.
6 changes: 6 additions & 0 deletions .schema/openapi/patches/health.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@
type: object
type: object
description: Ory Kratos is not yet ready to accept requests.
default:
content:
text/plain:
schema:
type: string
description: Unexpected error
summary: Check HTTP Server and Database Status
tags: {{ .HealthPathTags | toJson }}
- op: replace
Expand Down
1 change: 1 addition & 0 deletions .schema/openapi/patches/replacements.sed
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ s/ory.keto.relation_tuples.v1alpha2.ErrorResponse.Error/genericError/g
s/ory.keto.relation_tuples.v1alpha2.CreateRelationTupleRequest.Relationship/createRelationshipBody/g
s/ory.keto.relation_tuples.v1alpha2.SubjectSet/subjectSet/g
s/ory.keto.relation_tuples.v1alpha2.SubjectTree/expandedPermissionTree/g
s/ory.keto.relation_tuples.v1alpha2.RelationTupleDelta/relationshipPatch/g
s/ory.keto.relation_tuples.v1alpha2.RelationTuple/relationship/g
s/ory.keto.relation_tuples.v1alpha2.ListRelationTuplesResponse/relationships/g
s/ory.keto.relation_tuples.v1alpha2.ListNamespacesResponse/relationshipNamespaces/g
Expand Down
21 changes: 21 additions & 0 deletions internal/driver/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
package driver

import (
"bytes"
"context"
"encoding/json"
"io"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -385,6 +388,24 @@ func (r *RegistryDefault) OPLSyntaxRouter(ctx context.Context, apiHandler http.H
}
n.UseFunc(semconv.Middleware)
n.Use(reqlog.NewMiddlewareFromLogger(r.l, "syntax#Ory Keto").ExcludePaths(healthx.AliveCheckPath, healthx.ReadyCheckPath))
n.UseFunc(func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
if r.URL.Path == "/opl/syntax/check" && r.Header.Get("Content-Type") != "application/json" {
body, err := io.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
newBody, err := json.Marshal(body)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
r.Body = io.NopCloser(bytes.NewReader(newBody))
r.ContentLength = int64(len(newBody))
r.Header.Set("Content-Type", "application/json")
}
next(w, r)
})

pr := &x.OPLSyntaxRouter{Router: httprouter.New()}
r.PrometheusManager().RegisterRouter(pr.Router)
Expand Down
13 changes: 7 additions & 6 deletions internal/e2e/rest_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import (
"github.com/ory/keto/ketoapi"
rts "github.com/ory/keto/proto/ory/keto/relation_tuples/v1alpha2"

"github.com/ory/herodot"
"github.com/tidwall/gjson"

"github.com/ory/herodot"

"github.com/ory/keto/internal/x"

"github.com/stretchr/testify/assert"
Expand All @@ -46,9 +47,7 @@ func (rc *restClient) queryNamespaces(t require.TestingT) (res ketoapi.GetNamesp
}

func (rc *restClient) oplCheckSyntax(t require.TestingT, content []byte) []*ketoapi.ParseError {
enc, err := json.Marshal(content)
require.NoError(t, err)
body, code := rc.makeRequest(t, http.MethodPost, schema.RouteBase, string(enc), rc.oplSyntaxURL)
body, code := rc.makeRequest(t, http.MethodPost, schema.RouteBase, string(content), rc.oplSyntaxURL)
assert.Equal(t, http.StatusOK, code, body)
var response ketoapi.CheckOPLSyntaxResponse
require.NoError(t, json.Unmarshal([]byte(body), &response))
Expand Down Expand Up @@ -171,8 +170,10 @@ func (rc *restClient) expand(t require.TestingT, r *ketoapi.SubjectSet, depth in
return tree
}

func healthReady(_ require.TestingT, readURL string) bool {
resp, err := http.Get(readURL + healthx.ReadyCheckPath)
func healthReady(t require.TestingT, readURL string) bool {
req, err := http.NewRequest("GET", readURL+healthx.ReadyCheckPath, nil)
require.NoError(t, err)
resp, err := http.DefaultClient.Do(req)
if err != nil {
return false
}
Expand Down
13 changes: 10 additions & 3 deletions internal/e2e/sdk_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ func (c *sdkClient) requestCtx() context.Context {
}

func (c *sdkClient) oplCheckSyntax(t require.TestingT, content []byte) (parseErrors []*ketoapi.ParseError) {
enc, err := json.Marshal(content)
require.NoError(t, err)
res, _, err := c.getOPLSyntaxClient().
RelationshipApi.
CheckOplSyntax(c.requestCtx()).
Body(string(enc)).
Body(string(content)).
Execute()
require.NoError(t, err)

//enc, err := json.Marshal(content)
//require.NoError(t, err)
//res, _, err := c.getOPLSyntaxClient().
// RelationshipApi.
// CheckOplSyntax(c.requestCtx()).
// Body(string(enc)).
// Execute()
//require.NoError(t, err)

raw, err := json.Marshal(res.Errors)
require.NoError(t, err)
err = json.Unmarshal(raw, &parseErrors)
Expand Down
8 changes: 4 additions & 4 deletions internal/httpclient/.openapi-generator/FILES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/httpclient/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 31 additions & 17 deletions internal/httpclient/api/openapi.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion internal/httpclient/api_metadata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions internal/httpclient/api_relationship.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions internal/httpclient/docs/CheckPermissionResult.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/httpclient/docs/MetadataApi.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d95d526

Please sign in to comment.