snapshot of https://github.com/ory/keto.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
CI / Run lints and checks (push) Failing after 47s
CI / Run tests (push) Failing after 1s
CI / Run race tests (push) Failing after 5s
CI / Build CLI docs (push) Has been skipped
CI / Run buf actions (push) Failing after 5s
CodeQL / Analyze (go) (push) Failing after 3s
CodeQL / Analyze (javascript) (push) Failing after 2s
Docker Image Scanners / scanners (push) Failing after 3s
Format / format (push) Failing after 3s
Synchronize Issue Labels / Synchronize Issue Labels (push) Has been skipped
CI / Generate release (push) Has been skipped
CI / Draft newsletter (push) Has been skipped
CI / Pending approval Slack notification (push) Has been skipped
CI / Send newsletter (push) Has been skipped

This commit is contained in:
upstream-mirror
2026-09-16 01:08:34 +05:00
commit 9456a4e922
2560 changed files with 120911 additions and 0 deletions

46
cmd/helpers/helpers.go Normal file
View File

@@ -0,0 +1,46 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package helpers
import (
"fmt"
"strings"
"github.com/spf13/cobra"
rts "github.com/ory/keto/gen/go/ory/keto/relation_tuples/v1alpha2"
"github.com/ory/keto/ketoapi"
)
func ParseSubject(s string) (*rts.Subject, error) {
if strings.Contains(s, ":") {
su, err := (&ketoapi.SubjectSet{}).FromString(s)
if err != nil {
return nil, err
}
return rts.NewSubjectSet(su.Namespace, su.Object, su.Relation), nil
}
return rts.NewSubjectID(s), nil
}
// ParseNamespaceObject parses namespace and object from args that may be in the
// combined format ["namespace:object"] or the legacy format ["namespace", "object"].
// It writes a deprecation warning to cmd.ErrOrStderr if the legacy format is used.
func ParseNamespaceObject(cmd *cobra.Command, args []string) (namespace, object string, err error) {
switch len(args) {
case 2:
_, _ = fmt.Fprintln(cmd.ErrOrStderr(), "Warning: passing namespace and object as separate arguments is deprecated. Use <object_namespace>:<object_id> instead.")
return args[0], args[1], nil
case 1:
namespace, object, ok := strings.Cut(args[0], ":")
// empty ObjectID is allowed
if !ok || namespace == "" {
return "", "", fmt.Errorf("expected <object_namespace>:<object_id> format, got %q", args[0])
}
return namespace, object, nil
default:
return "", "", fmt.Errorf("unexpected number of arguments for <object_namespace>:<object_id>: got %d arguments - %s", len(args), strings.Join(args, ","))
}
}

View File

@@ -0,0 +1,39 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package helpers
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
rts "github.com/ory/keto/gen/go/ory/keto/relation_tuples/v1alpha2"
)
func TestParseSubject(t *testing.T) {
for _, tc := range []struct {
input string
expected *rts.Subject
}{
{
input: "nspace:obj#rel",
expected: rts.NewSubjectSet("nspace", "obj", "rel"),
},
{
input: "someid",
expected: rts.NewSubjectID("someid"),
},
{
input: "nspace:id",
expected: rts.NewSubjectSet("nspace", "id", ""),
},
} {
t.Run("subject="+tc.input, func(t *testing.T) {
actual, err := ParseSubject(tc.input)
require.NoError(t, err)
assert.Equal(t, tc.expected, actual)
})
}
}