-
-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a first draft of the read API. It is reachable by REST and gRPC calls. The main purpose of this PR is to establish the basic repository structure and define the API.
- Loading branch information
Showing
20 changed files
with
916 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/pflag" | ||
"google.golang.org/grpc" | ||
"time" | ||
) | ||
|
||
const ( | ||
FlagRemoteURL = "remote" | ||
) | ||
|
||
func GetGRPCConn(cmd *cobra.Command) (*grpc.ClientConn, error) { | ||
remote, err := cmd.Flags().GetString(FlagRemoteURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ctx, _ := context.WithTimeout(context.Background(), 3*time.Second) | ||
return grpc.DialContext(ctx, remote, grpc.WithInsecure(), grpc.WithBlock()) | ||
} | ||
|
||
func RegisterRemoteURLFlag(flags *pflag.FlagSet) { | ||
flags.StringP(FlagRemoteURL, "r", "", "TODO") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package relation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/ory/keto/cmd/client" | ||
"github.com/ory/keto/models" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var getByUserRelationCmd = &cobra.Command{ | ||
Use: "get-by-user <id>", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
conn, err := client.GetGRPCConn(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
defer conn.Close() | ||
|
||
cl := models.NewGRPCRelationReaderClient(conn) | ||
resp, err := cl.RelationsByUser(context.Background(), &models.GRPCRelationsReadRequest{ | ||
Page: 0, | ||
PerPage: 100, | ||
Id: args[0], | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("Got %d relations for user %s\n", len(resp.Relations), args[0]) | ||
for _, r := range resp.Relations { | ||
fmt.Printf("%+v\n", r) | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package relation | ||
|
||
import ( | ||
"github.com/ory/keto/cmd/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var relationCmd = &cobra.Command{ | ||
Use: "relation", | ||
} | ||
|
||
func RegisterCommandRecursive(parent *cobra.Command) { | ||
parent.AddCommand(relationCmd) | ||
|
||
relationCmd.AddCommand(getByUserRelationCmd) | ||
|
||
client.RegisterRemoteURLFlag(relationCmd.PersistentFlags()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package driver | ||
|
||
import ( | ||
"github.com/ory/herodot" | ||
"github.com/ory/keto/persistence/memory" | ||
"github.com/ory/keto/relation" | ||
"github.com/ory/keto/x" | ||
"github.com/ory/x/logrusx" | ||
) | ||
|
||
var _ relation.ManagerProvider = &RegistryDefault{} | ||
var _ x.WriterProvider = &RegistryDefault{} | ||
var _ x.LoggerProvider = &RegistryDefault{} | ||
|
||
type RegistryDefault struct { | ||
p *memory.Persister | ||
l *logrusx.Logger | ||
w herodot.Writer | ||
} | ||
|
||
func (r *RegistryDefault) Logger() *logrusx.Logger { | ||
if r.l == nil { | ||
r.l = logrusx.New("keto", "dev") | ||
} | ||
return r.l | ||
} | ||
|
||
func (r *RegistryDefault) Writer() herodot.Writer { | ||
if r.w == nil { | ||
r.w = herodot.NewJSONWriter(r.Logger()) | ||
} | ||
return r.w | ||
} | ||
|
||
func (r *RegistryDefault) RelationManager() relation.Manager { | ||
if r.p == nil { | ||
r.p = memory.NewPersister() | ||
} | ||
return r.p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,43 @@ | ||
module github.com/ory/keto | ||
|
||
require ( | ||
github.com/akutz/goof v0.1.2 // indirect | ||
github.com/akutz/gotil v0.1.0 | ||
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect | ||
github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c // indirect | ||
github.com/go-errors/errors v1.0.1 | ||
github.com/go-openapi/errors v0.19.4 | ||
github.com/go-openapi/runtime v0.19.5 | ||
github.com/go-openapi/strfmt v0.19.5 | ||
github.com/go-openapi/swag v0.19.5 | ||
github.com/go-openapi/validate v0.19.3 | ||
github.com/go-sql-driver/mysql v1.5.0 | ||
github.com/go-swagger/go-swagger v0.21.1-0.20200107003254-1c98855b472d | ||
github.com/gobuffalo/packr v1.24.1 | ||
github.com/gobwas/glob v0.2.3 // indirect | ||
github.com/golang/protobuf v1.4.2 // indirect | ||
github.com/gofrs/uuid v3.2.0+incompatible | ||
github.com/golang/protobuf v1.4.2 | ||
github.com/gorilla/sessions v1.1.3 | ||
github.com/gorilla/websocket v1.4.2 | ||
github.com/jackc/pgx/v4 v4.4.1 | ||
github.com/jmoiron/sqlx v1.2.0 | ||
github.com/julienschmidt/httprouter v1.2.0 | ||
github.com/kardianos/osext v0.0.0-20170510131534-ae77be60afb1 // indirect | ||
github.com/open-policy-agent/opa v0.10.1 | ||
github.com/ory/analytics-go/v4 v4.0.1 | ||
github.com/ory/cli v0.0.11 | ||
github.com/ory/go-acc v0.2.3 | ||
github.com/ory/graceful v0.1.1 | ||
github.com/ory/herodot v0.9.1 | ||
github.com/ory/viper v1.7.5 | ||
github.com/ory/x v0.0.128 | ||
github.com/pborman/uuid v1.2.0 | ||
github.com/pkg/errors v0.9.1 | ||
github.com/pkg/profile v1.3.0 // indirect | ||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a // indirect | ||
github.com/rs/cors v1.6.0 | ||
github.com/rubenv/sql-migrate v0.0.0-20190327083759-54bad0a9b051 | ||
github.com/rubenv/sql-migrate v0.0.0-20190327083759-54bad0a9b051 // indirect | ||
github.com/shopspring/decimal v1.2.0 // indirect | ||
github.com/spf13/cobra v1.0.0 | ||
github.com/spf13/pflag v1.0.5 | ||
github.com/spf13/viper v1.7.0 // indirect | ||
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518 | ||
github.com/stretchr/testify v1.5.1 | ||
github.com/tidwall/sjson v1.1.1 // indirect | ||
github.com/urfave/negroni v1.0.0 | ||
github.com/yashtewari/glob-intersection v0.0.0-20180916065949-5c77d914dd0b // indirect | ||
go.mongodb.org/mongo-driver v1.3.4 // indirect | ||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect | ||
golang.org/x/tools v0.0.0-20200401192744-099440627f01 | ||
google.golang.org/grpc v1.29.1 // indirect | ||
google.golang.org/protobuf v1.24.0 // indirect | ||
google.golang.org/grpc v1.33.0 | ||
google.golang.org/protobuf v1.25.0 | ||
) | ||
|
||
go 1.14 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.