summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/rpc34
-rw-r--r--lib/.keep0
-rw-r--r--magefile.go23
-rw-r--r--protos/ability.proto13
4 files changed, 69 insertions, 1 deletions
diff --git a/bin/rpc b/bin/rpc
new file mode 100755
index 0000000..1449018
--- /dev/null
+++ b/bin/rpc
@@ -0,0 +1,34 @@
+#!/usr/bin/env ruby
+
+require "bundler/inline"
+
+gemfile do
+ source "https://rubygems.org"
+
+ gem "grpc", "~> 1.0"
+ gem "grpc-tools", "~> 1.0"
+ gem "logger", "~> 1.0"
+end
+
+lib_path = Pathname.new(__FILE__).parent.parent.join('lib').realpath.to_s
+$LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
+
+require 'ability_services_pb'
+
+class AbilityHandler < ::Ability::Service
+ def allowed(request, _call)
+ puts [request, _call].inspect
+ # TODO:: entrypoint to declarative policies
+ AllowReply.new(result: true)
+ end
+end
+
+host = ENV.fetch("HOST", "localhost")
+port = ENV.fetch("PORT", "50051")
+bind_addr = "#{host}:#{port}"
+server = GRPC::RpcServer.new
+server.add_http2_port(bind_addr, :this_port_is_insecure)
+GRPC.logger = Logger.new($stderr, level: :debug)
+GRPC.logger.info("... running insecurely on #{bind_addr}")
+server.handle(AbilityHandler.new)
+server.run_till_terminated_or_interrupted([1, 'int', 'SIGQUIT'])
diff --git a/lib/.keep b/lib/.keep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lib/.keep
diff --git a/magefile.go b/magefile.go
index 8e1b969..5e17799 100644
--- a/magefile.go
+++ b/magefile.go
@@ -54,6 +54,16 @@ func Api() error {
return sh.RunWithV(env, "ruby", "./bin/api")
}
+// Run the gRPC Server
+func Rpc(ctx context.Context) error {
+ mg.CtxDeps(ctx, Protos)
+ env := map[string]string{
+ "PORT": "50051",
+ "HOST": "localhost",
+ }
+ return sh.RunWithV(env, "ruby", "./bin/rpc")
+}
+
// Open a web browser to the login page
func Browser() error {
url := "http://localhost:8080/ui/sessions/new"
@@ -64,7 +74,18 @@ func Browser() error {
}
}
+// Generate gRPC from protocal buffers
+func Protos() error {
+ return sh.RunV(
+ "grpc_tools_ruby_protoc",
+ "--proto_path=./protos",
+ "--ruby_out=lib",
+ "--grpc_out=lib",
+ "protos/ability.proto",
+ )
+}
+
// Run All the servers
func Run(ctx context.Context) {
- mg.CtxDeps(ctx, Idp, UI, Api, Gateway)
+ mg.CtxDeps(ctx, Idp, UI, Api, Rpc, Gateway)
}
diff --git a/protos/ability.proto b/protos/ability.proto
new file mode 100644
index 0000000..656f4f9
--- /dev/null
+++ b/protos/ability.proto
@@ -0,0 +1,13 @@
+service Ability {
+ rpc Allowed (AllowRequest) returns (AllowReply) {}
+}
+
+message AllowRequest {
+ required string subject = 1;
+ required string permission = 2;
+ required string resource = 3;
+}
+
+message AllowReply {
+ required bool result = 1;
+}