Skip to content

Commit

Permalink
docs: clarify that CLI remotes should be addresses and not URIs (#808)
Browse files Browse the repository at this point in the history
  • Loading branch information
zepatrik committed Jan 7, 2022
1 parent c605690 commit 7ce7973
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ $(call make-lint-dependency)
node_modules: package.json package-lock.json Makefile
npm ci

.PHONY: .bin/clidoc
.bin/clidoc:
go build -o .bin/clidoc ./cmd/clidoc/.

Expand Down
15 changes: 11 additions & 4 deletions cmd/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"strings"
"time"

"github.com/ory/x/flagx"
Expand All @@ -25,15 +26,21 @@ const (
ContextKeyTimeout contextKeys = "timeout"
)

func getRemote(cmd *cobra.Command, flagRemote, envRemote string) string {
func getRemote(cmd *cobra.Command, flagRemote, envRemote string) (remote string) {
defer (func() {
if strings.HasPrefix(remote, "http://") || strings.HasPrefix(remote, "https://") {
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "remote \"%s\" seems to be an http URL instead of a remote address\n", remote)
}
})()

if cmd.Flags().Changed(flagRemote) {
return flagx.MustGetString(cmd, flagRemote)
} else if remote, isSet := os.LookupEnv(envRemote); isSet {
return remote
}

// no value is set, use fallback from the flag and warn about that
remote := flagx.MustGetString(cmd, flagRemote)
remote = flagx.MustGetString(cmd, flagRemote)
_, _ = fmt.Fprintf(cmd.ErrOrStderr(), "neither flag --%s nor env var %s are set, falling back to %s\n", flagRemote, envRemote, remote)
return remote
}
Expand All @@ -58,6 +65,6 @@ func Conn(ctx context.Context, remote string) (*grpc.ClientConn, error) {
}

func RegisterRemoteURLFlags(flags *pflag.FlagSet) {
flags.String(FlagReadRemote, "127.0.0.1:4466", "Remote URL of the read API endpoint.")
flags.String(FlagWriteRemote, "127.0.0.1:4467", "Remote URL of the write API endpoint.")
flags.String(FlagReadRemote, "127.0.0.1:4466", "Remote address of the read API endpoint.")
flags.String(FlagWriteRemote, "127.0.0.1:4467", "Remote address of the write API endpoint.")
}
4 changes: 2 additions & 2 deletions docs/docs/cli/keto-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ keto check <subject> <relation> <namespace> <object> [fl
-h, --help help for check
-d, --max-depth int32 Maximum depth of the search tree. If the value is less than 1 or greater than the global max-depth then the global max-depth will be used instead.
-q, --quiet Be quiet with output printing.
--read-remote string Remote URL of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote URL of the write API endpoint. (default "127.0.0.1:4467")
--read-remote string Remote address of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote address of the write API endpoint. (default "127.0.0.1:4467")
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cli/keto-expand.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ keto expand <relation> <namespace> <object> [flags]
-h, --help help for expand
-d, --max-depth int32 Maximum depth of the tree to be returned. If the value is less than 1 or greater than the global max-depth then the global max-depth will be used instead.
-q, --quiet Be quiet with output printing.
--read-remote string Remote URL of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote URL of the write API endpoint. (default "127.0.0.1:4467")
--read-remote string Remote address of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote address of the write API endpoint. (default "127.0.0.1:4467")
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cli/keto-namespace-migrate-legacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ keto namespace migrate legacy [<namespace-name>] [flags]
-f, --format string Set the output format. One of table, json, and json-pretty. (default "default")
-h, --help help for legacy
-q, --quiet Be quiet with output printing.
--read-remote string Remote URL of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote URL of the write API endpoint. (default "127.0.0.1:4467")
--read-remote string Remote address of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote address of the write API endpoint. (default "127.0.0.1:4467")
-y, --yes yes to all questions, no user input required
```

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cli/keto-relation-tuple-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ keto relation-tuple create <relation-tuple.json> [<relation-tuple-dir&g
-f, --format string Set the output format. One of table, json, and json-pretty. (default "default")
-h, --help help for create
-q, --quiet Be quiet with output printing.
--read-remote string Remote URL of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote URL of the write API endpoint. (default "127.0.0.1:4467")
--read-remote string Remote address of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote address of the write API endpoint. (default "127.0.0.1:4467")
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cli/keto-relation-tuple-delete.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ keto relation-tuple delete <relation-tuple.json> [<relation-tuple-dir&g
-f, --format string Set the output format. One of table, json, and json-pretty. (default "default")
-h, --help help for delete
-q, --quiet Be quiet with output printing.
--read-remote string Remote URL of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote URL of the write API endpoint. (default "127.0.0.1:4467")
--read-remote string Remote address of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote address of the write API endpoint. (default "127.0.0.1:4467")
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cli/keto-relation-tuple-get.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ keto relation-tuple get <namespace> [flags]
--page-size int32 maximum number of items to return (default 100)
--page-token string page token acquired from a previous response
-q, --quiet Be quiet with output printing.
--read-remote string Remote URL of the read API endpoint. (default "127.0.0.1:4466")
--read-remote string Remote address of the read API endpoint. (default "127.0.0.1:4466")
--relation string Set the requested relation
--subject-id string Set the requested subject ID
--subject-set string Set the requested subject set; format: "namespace:object#relation"
--write-remote string Remote URL of the write API endpoint. (default "127.0.0.1:4467")
--write-remote string Remote address of the write API endpoint. (default "127.0.0.1:4467")
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/cli/keto-status.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ keto status [flags]
--endpoint string which endpoint to use; one of {read, write} (default "read")
-h, --help help for status
-q, --quiet Be quiet with output printing.
--read-remote string Remote URL of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote URL of the write API endpoint. (default "127.0.0.1:4467")
--read-remote string Remote address of the read API endpoint. (default "127.0.0.1:4466")
--write-remote string Remote address of the write API endpoint. (default "127.0.0.1:4467")
```

### Options inherited from parent commands
Expand Down

0 comments on commit 7ce7973

Please sign in to comment.