Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
}
]
},
"oauth2_provider": {},
"selfservice": {
"allowed_return_urls": [],
"default_browser_return_url": "/ui/welcome",
Expand Down Expand Up @@ -393,9 +394,9 @@
"refresh_token": "720h0m0s"
},
"urls": {
"consent": "/oauth2/fallbacks/consent",
"error": "/oauth2/fallbacks/error",
"login": "/oauth2/fallbacks/login",
"consent": "/ui/consent",
"error": "/ui/error",
"login": "/ui/login",
"post_logout_redirect": "/oauth2/fallbacks/logout"
},
"webfinger": {
Expand Down
7 changes: 4 additions & 3 deletions cmd/cloudx/client/fixtures/update_project/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
}
]
},
"oauth2_provider": {},
"selfservice": {
"allowed_return_urls": [],
"default_browser_return_url": "/ui/welcome",
Expand Down Expand Up @@ -340,9 +341,9 @@
"refresh_token": "720h0m0s"
},
"urls": {
"consent": "/oauth2/fallbacks/consent",
"error": "/oauth2/fallbacks/error",
"login": "/oauth2/fallbacks/login",
"consent": "/ui/consent",
"error": "/ui/error",
"login": "/ui/login",
"post_logout_redirect": "/oauth2/fallbacks/logout"
},
"webfinger": {
Expand Down
24 changes: 24 additions & 0 deletions cmd/cloudx/is.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cloudx

import (
"github.com/spf13/cobra"

"github.com/ory/cli/cmd/cloudx/client"
"github.com/ory/cli/cmd/cloudx/relationtuples"
"github.com/ory/x/cmdx"
)

func NewIsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "is",
Short: "Assert the state of Ory Network resources",
}
cmd.AddCommand(relationtuples.NewAllowedCmd())

client.RegisterConfigFlag(cmd.PersistentFlags())
client.RegisterYesFlag(cmd.PersistentFlags())
cmdx.RegisterNoiseFlags(cmd.PersistentFlags())
cmdx.RegisterJSONFormatFlags(cmd.PersistentFlags())

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
}
]
},
"oauth2_provider": {},
"selfservice": {
"allowed_return_urls": [],
"default_browser_return_url": "/ui/welcome",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
}
]
},
"oauth2_provider": {},
"selfservice": {
"allowed_return_urls": [],
"default_browser_return_url": "/ui/welcome",
Expand Down Expand Up @@ -392,9 +393,9 @@
"refresh_token": "720h0m0s"
},
"urls": {
"consent": "/oauth2/fallbacks/consent",
"error": "/oauth2/fallbacks/error",
"login": "/oauth2/fallbacks/login",
"consent": "/ui/consent",
"error": "/ui/error",
"login": "/ui/login",
"post_logout_redirect": "/oauth2/fallbacks/logout"
},
"webfinger": {
Expand Down
1 change: 1 addition & 0 deletions cmd/cloudx/project/fixtures/update-kratos/json/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
}
}
},
"oauth2_provider": {},
"identity": {
"default_schema_id": "from-disk",
"schemas": [
Expand Down
7 changes: 4 additions & 3 deletions cmd/cloudx/project/fixtures/update/json/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
}
]
},
"oauth2_provider": {},
"selfservice": {
"allowed_return_urls": [],
"default_browser_return_url": "/ui/welcome",
Expand Down Expand Up @@ -397,9 +398,9 @@
"refresh_token": "720h0m0s"
},
"urls": {
"consent": "/oauth2/fallbacks/consent",
"error": "/oauth2/fallbacks/error",
"login": "/oauth2/fallbacks/login",
"consent": "/ui/consent",
"error": "/ui/error",
"login": "/ui/login",
"post_logout_redirect": "/oauth2/fallbacks/logout"
},
"webfinger": {
Expand Down
15 changes: 15 additions & 0 deletions cmd/cloudx/relationtuples/permissions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package relationtuples

import (
"github.com/spf13/cobra"

"github.com/ory/keto/cmd/check"
)

func NewAllowedCmd() *cobra.Command {
cmd := check.NewCheckCmd()
wrapForOryCLI(cmd)
cmd.Use = "allowed <subject> <relation> <namespace> <object>"

return cmd
}
21 changes: 21 additions & 0 deletions cmd/cloudx/relationtuples/permissions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package relationtuples_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/ory/cli/cmd/cloudx/client"
"github.com/ory/cli/cmd/cloudx/testhelpers"
)

func TestIsAllowedNoUnauthenticated(t *testing.T) {
t.Parallel()

configDir := testhelpers.NewConfigDir(t)
cmd := testhelpers.ConfigAwareCmd(configDir)
_, _, err := cmd.Exec(nil,
"is", "allowed", "user", "relation", "namespace", "object",
"--quiet", "--project", project)
require.ErrorIsf(t, err, client.ErrNoConfigQuiet, "got error: %v", err)
}
3 changes: 2 additions & 1 deletion cmd/cloudx/relationtuples/relationtuples.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ func hideKetoFlags(cmd *cobra.Command) {

// wrapForOryCLI wraps the Keto command to be used in the ORY CLI.
func wrapForOryCLI(cmd *cobra.Command) {
cmd.Use = "relation-tuples"
cmd.Use = "relationships"
cmd.Aliases = []string{"relation-tuples", "relationship", "relation-tuple"}
client.RegisterProjectFlag(cmd.Flags())
forwardConnectionInfo(cmd)
hideKetoFlags(cmd)
Expand Down
13 changes: 12 additions & 1 deletion cmd/cloudx/relationtuples/relationtuples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestNoUnauthenticated(t *testing.T) {
t.Run("verb="+tc.verb, func(t *testing.T) {
configDir := testhelpers.NewConfigDir(t)
cmd := testhelpers.ConfigAwareCmd(configDir)
args := append([]string{tc.verb, "relation-tuples", "--quiet", "--project", project},
args := append([]string{tc.verb, "relationships", "--quiet", "--project", project},
tc.extraArgs...)
_, _, err := cmd.Exec(nil, args...)
require.ErrorIsf(t, err, client.ErrNoConfigQuiet, "got error: %v", err)
Expand Down Expand Up @@ -108,6 +108,13 @@ func TestCRUD(t *testing.T) {
require.NoError(t, err, stderr)
return stdout
}
isAllowed := func(t *testing.T, subject, relation, namespace, object string) string {
stdout, stderr, err := defaultCmd.Exec(nil,
"is", "allowed", subject, relation, namespace, object,
"--project", project, "--format", "json")
require.NoError(t, err, stderr)
return stdout
}

// 1. create a tuple
stdout := create(t, "o1")
Expand All @@ -117,6 +124,10 @@ func TestCRUD(t *testing.T) {
stdout = list(t)
require.JSONEq(t, tuple("o1"), gjson.Get(stdout, "relation_tuples").Raw, stdout)

// check that it is allowed
stdout = isAllowed(t, "s", "r", "n", "o1")
require.JSONEq(t, `{"allowed":true}`, stdout, stdout)

// 3. delete with --all but without --force
stdout, stderr, err := defaultCmd.Exec(nil, "delete", "relation-tuples", "--format", "json", "--project", project,
"--all")
Expand Down
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func NewRootCmd() *cobra.Command {
cloudx.NewValidateCmd(),
cloudx.NewRevokeCmd(),
cloudx.NewIntrospectCmd(),
cloudx.NewIsCmd(),
versionCmd,
)
cmdx.EnableUsageTemplating(c)
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace (
github.com/gorilla/sessions => github.com/ory/sessions v1.2.2-0.20220110165800-b09c17334dc2
github.com/mattn/go-sqlite3 => github.com/mattn/go-sqlite3 v1.14.9
github.com/ory/hydra-client-go => github.com/ory/hydra-client-go v1.11.9-0.20221025084544-5e50d3cc8604
github.com/ory/keto/proto => github.com/ory/keto/proto v0.10.0-alpha.0
github.com/ory/keto/proto => github.com/ory/keto/proto v0.10.0-alpha.0.0.20221026143738-31e323a91b68
// Required because github.com/ory/kratos rewrites github.com/ory/kratos-client-go to
// github.com/ory/kratos/internal/httpclient
github.com/ory/kratos-client-go => github.com/ory/kratos/internal/httpclient v0.0.0-20221004123324-f002649d4565
Expand Down Expand Up @@ -37,10 +37,10 @@ require (
github.com/ory/hydra v1.11.11-0.20221025084653-ca724399bd25
github.com/ory/hydra-client-go v1.11.8
github.com/ory/jsonschema/v3 v3.0.7
github.com/ory/keto v0.10.0-alpha.0
github.com/ory/keto v0.10.0-alpha.0.0.20221026143738-31e323a91b68
github.com/ory/kratos v0.10.2-0.20221004123324-f002649d4565
github.com/ory/kratos-client-go v0.9.0-alpha.3
github.com/ory/x v0.0.486
github.com/ory/x v0.0.487
github.com/pkg/errors v0.9.1
github.com/pquerna/otp v1.3.0
github.com/rs/cors v1.8.2
Expand Down Expand Up @@ -226,7 +226,7 @@ require (
github.com/ory/fosite v0.42.3-0.20220801115804-c557908b0db2 // indirect
github.com/ory/go-acc v0.2.8 // indirect
github.com/ory/go-convenience v0.1.0 // indirect
github.com/ory/keto/proto v0.9.0-alpha.0.0.20220923124203-fa69fb33eb4c // indirect
github.com/ory/keto/proto v0.10.0-alpha.0.0.20221026143738-31e323a91b68 // indirect
github.com/ory/mail/v3 v3.0.0 // indirect
github.com/ory/nosurf v1.2.7 // indirect
github.com/ory/viper v1.7.5 // indirect
Expand All @@ -247,6 +247,7 @@ require (
github.com/sawadashota/encrypta v0.0.2 // indirect
github.com/seatgeek/logrus-gelf-formatter v0.0.0-20210414080842-5b05eb8ff761 // indirect
github.com/segmentio/backo-go v1.0.1 // indirect
github.com/segmentio/objconv v1.0.1 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1352,8 +1352,12 @@ github.com/ory/jsonschema/v3 v3.0.7 h1:GQ9qfZDiJqs4l2d3p56dozCChvejQFZyLKGHYzDzO
github.com/ory/jsonschema/v3 v3.0.7/go.mod h1:g8c8YOtN4TrR2wYeMdT02GDmzJDI0fEW2nI26BECafY=
github.com/ory/keto v0.10.0-alpha.0 h1:XoxoQG6cu4bhjYDektN+YWwxkIJgWXRyrod8P2DWtck=
github.com/ory/keto v0.10.0-alpha.0/go.mod h1:NTOmOIdHTfqFOVVuOJSe+ZlGERfG2VELxq/YrfPA3RY=
github.com/ory/keto v0.10.0-alpha.0.0.20221026143738-31e323a91b68 h1:YeC56K9uMkXnzSo7SvaMpzXLZBfkchiFQDDmzXtrhZU=
github.com/ory/keto v0.10.0-alpha.0.0.20221026143738-31e323a91b68/go.mod h1:gB3sHgjaayg0sS8f8z6CiVMLRgLyowSbGrmfBYrVER8=
github.com/ory/keto/proto v0.10.0-alpha.0 h1:35+Xf0gE3jeQEgosbFB9NxgbKIQRo/HAtknKTeqhz2Q=
github.com/ory/keto/proto v0.10.0-alpha.0/go.mod h1:g89tEf3y7WE1E5wPPVsWU36/qP1SAvjQ+LoQaLa1QF0=
github.com/ory/keto/proto v0.10.0-alpha.0.0.20221026143738-31e323a91b68 h1:9W7/nF++V6do3vfi3koaEP5kUJqna7JV0okzgiy3unQ=
github.com/ory/keto/proto v0.10.0-alpha.0.0.20221026143738-31e323a91b68/go.mod h1:g89tEf3y7WE1E5wPPVsWU36/qP1SAvjQ+LoQaLa1QF0=
github.com/ory/kratos v0.10.2-0.20221004123324-f002649d4565 h1:if4S6lx4lFTag1ieSnSyHnVp8ermoNoEpfRlyE3O6Q4=
github.com/ory/kratos v0.10.2-0.20221004123324-f002649d4565/go.mod h1:qZ2gs2XItrRYHVQEIgtMtA0JoGnJra8I6l6zR0ceIu8=
github.com/ory/kratos/internal/httpclient v0.0.0-20221004123324-f002649d4565 h1:CTahz6LK17ycZO0AbneTmhHjcp5mkJYG4kFoWW0QXSQ=
Expand All @@ -1369,6 +1373,8 @@ github.com/ory/viper v1.7.5 h1:+xVdq7SU3e1vNaCsk/ixsfxE4zylk1TJUiJrY647jUE=
github.com/ory/viper v1.7.5/go.mod h1:ypOuyJmEUb3oENywQZRgeAMwqgOyDqwboO1tj3DjTaM=
github.com/ory/x v0.0.486 h1:/f0FNgwbBkaJkXcxpDo01rOPl+E1S1byzEMaIOeapAA=
github.com/ory/x v0.0.486/go.mod h1:w2gwqgw3XqKTxW8wURVxUFI2NuDyIC2rGxvEsnBJqjs=
github.com/ory/x v0.0.487 h1:A4LxhmfP3hnRhnRUvdo8/s60s473JLQce5Z9VqDJzmo=
github.com/ory/x v0.0.487/go.mod h1:dJ800rWC2/eNECWhXMyI9kSd7lO2LTOu6R8oS0lQZ38=
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs=
Expand Down Expand Up @@ -1524,6 +1530,7 @@ github.com/segmentio/backo-go v1.0.1/go.mod h1:9/Rh6yILuLysoQnZ2oNooD2g7aBnvM7r/
github.com/segmentio/conf v1.2.0/go.mod h1:Y3B9O/PqqWqjyxyWWseyj/quPEtMu1zDp/kVbSWWaB0=
github.com/segmentio/go-snakecase v1.1.0/go.mod h1:jk1miR5MS7Na32PZUykG89Arm+1BUSYhuGR6b7+hJto=
github.com/segmentio/kafka-go v0.4.29/go.mod h1:m1lXeqJtIFYZayv0shM/tjrAFljvWLTprxBHd+3PnaU=
github.com/segmentio/objconv v1.0.1 h1:QjfLzwriJj40JibCV3MGSEiAoXixbp4ybhwfTB8RXOM=
github.com/segmentio/objconv v1.0.1/go.mod h1:auayaH5k3137Cl4SoXTgrzQcuQDmvuVtZgS0fb1Ahys=
github.com/serenize/snaker v0.0.0-20171204205717-a683aaf2d516/go.mod h1:Yow6lPLSAXx2ifx470yD/nUe22Dv5vBvxK/UK9UUTVs=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
Expand Down