summaryrefslogtreecommitdiff
path: root/bin/api
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-03-05 17:24:44 -0700
committermo khan <mo@mokhan.ca>2025-03-05 17:24:44 -0700
commit6300c4130099b016c7dd3bfcb17d541e77d79d72 (patch)
treef4bd491daed32d5e5d9e68afa219a86dec360abd /bin/api
parent61b6d010fce0925e3d27ff33484153170e28147c (diff)
feat: connect REST API to gRPC Ability.allowed? service
Diffstat (limited to 'bin/api')
-rwxr-xr-xbin/api15
1 files changed, 14 insertions, 1 deletions
diff --git a/bin/api b/bin/api
index 1bce8d95..212e31a2 100755
--- a/bin/api
+++ b/bin/api
@@ -6,13 +6,21 @@ gemfile do
source 'https://rubygems.org'
gem "erb", "~> 4.0"
+ gem "grpc", "~> 1.0"
gem "json", "~> 2.0"
+ gem "logger", "~> 1.0"
gem "rack", "~> 3.0"
gem "rackup", "~> 2.0"
gem "securerandom", "~> 0.1"
gem "webrick", "~> 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'
+
+GRPC.logger = Logger.new($stderr, level: :debug)
$scheme = ENV.fetch("SCHEME", "http")
$port = ENV.fetch("PORT", 8284).to_i
$host = ENV.fetch("HOST", "localhost:#{$port}")
@@ -71,7 +79,12 @@ class API
def authorized?(request, permission)
# TODO:: Check the JWT for the appropriate claim
# Connect to the Authz RPC endpoint Ability.allowed?(subject, permission, resource)
- true
+ client = ::Ability::Stub.new('localhost:50051', :this_channel_is_insecure) # TODO:: memorize client
+ reply = client.allowed(AllowRequest.new(subject: "", permission: permission, resource: ""))
+ puts "***" * 10
+ puts reply.inspect
+ puts "***" * 10
+ reply&.result
end
def json_not_found