summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-05 17:12:02 -0700
committermo khan <mo@mokhan.ca>2025-03-05 17:12:35 -0700
commit61b6d010fce0925e3d27ff33484153170e28147c (patch)
tree0ad4b678d0b0dc7d6b75fc29624d1f0c5b49672b /bin
parent4100066e1d4dfc50f74e4d749ce29c8db2d3fa63 (diff)
feat: define the protobuf service definition
Diffstat (limited to 'bin')
-rwxr-xr-xbin/rpc34
1 files changed, 34 insertions, 0 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'])