-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adce193
commit e4ec417
Showing
22 changed files
with
312 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
# frozen_string_literal: true | ||
|
||
source 'https://rubygems.org' | ||
gem 'sinatra-cross_origin' | ||
gemspec |
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,48 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: false | ||
|
||
# Copyright 2015 gRPC authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Sample gRPC server that implements the Greeter::Helloworld service. | ||
# | ||
# Usage: $ path/to/greeter_server.rb | ||
|
||
lib_dir = File.join(__dir__, '..', 'proto') | ||
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) | ||
|
||
require 'grpc' | ||
require 'helloworld_services_pb' | ||
|
||
# GreeterServer is simple server that implements the Helloworld Greeter server. | ||
class GreeterServer < Helloworld::Greeter::Service | ||
# say_hello implements the SayHello rpc method. | ||
def say_hello(hello_req, _unused_call) | ||
Helloworld::HelloReply.new(message: "Hello with message #{hello_req.name}") | ||
end | ||
end | ||
|
||
# main starts an RpcServer that receives requests to GreeterServer at the sample | ||
# server port. | ||
def main | ||
s = GRPC::RpcServer.new | ||
s.add_http2_port('0.0.0.0:50051', :this_port_is_insecure) | ||
s.handle(GreeterServer) | ||
# Runs the server with SIGHUP, SIGINT and SIGQUIT signal handlers to | ||
# gracefully shutdown. | ||
# User could also choose to run server via call to run_till_terminated | ||
s.run_till_terminated_or_interrupted([1, 'int', 'SIGQUIT']) | ||
end | ||
|
||
main |
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 @@ | ||
--- | ||
grpc: | ||
port: 5678 | ||
proto_dir: 'proto' | ||
services: | ||
'helloworld_services_pb': | ||
module: 'Helloworld::Greeter' | ||
hostname: '0.0.0.0:50051' | ||
request: | ||
timeout: 10 | ||
domains: | ||
'http://localhost:9090': | ||
name: 'components' | ||
skip_query_params: | ||
- b | ||
paths: | ||
- /users | ||
- /resources |
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,6 @@ | ||
Feature: Save response on call real grpc and return on second call | ||
|
||
Scenario: Save response body | ||
Given a valid gRPC method "helloworld.Greeter" | ||
When this method called throught tshield | ||
Then response should be saved in "grpc/helloworld/Greeter/hashrequest/response" |
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,57 @@ | ||
# frozen_string_literal: false | ||
|
||
require 'grpc' | ||
require 'byebug' | ||
|
||
require 'tshield/configuration' | ||
|
||
module TShield | ||
class Grpc | ||
def self.run! | ||
@configuration = TShield::Configuration.singleton.grpc | ||
|
||
lib_dir = File.join(Dir.pwd, @configuration['proto_dir']) | ||
$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) | ||
|
||
TShield.logger.info("loading proto files from #{lib_dir}") | ||
|
||
bind = "0.0.0.0:#{@configuration['port']}" | ||
|
||
server = GRPC::RpcServer.new | ||
server.add_http2_port(bind, :this_port_is_insecure) | ||
|
||
services = load_services(@configuration['services']) | ||
services.each do |class_service| | ||
server.handle(class_service) | ||
end | ||
|
||
server.run unless services.empty? | ||
end | ||
|
||
def self.load_services(services) | ||
implementations = [] | ||
number_of_implementations = 0 | ||
services.each do |file, options| | ||
require file | ||
|
||
base = Object.const_get("#{options['module']}::Service") | ||
number_of_implementations += 1 | ||
|
||
implementation = Class.new(base) do | ||
base.rpc_descs.each do |method_name, _description| | ||
method_name = method_name.to_s.underscore.to_sym | ||
define_method(method_name) do |request, _unused_call| | ||
client_class = Object.const_get("#{options['module']}::Stub") | ||
client_instance = client_class.new(options['hostname'], :this_channel_is_insecure) | ||
client_instance.send(method_name, request) | ||
end | ||
end | ||
end | ||
Object.const_set "GrpcService#{number_of_implementations}", implementation | ||
|
||
implementations << implementation | ||
end | ||
implementations | ||
end | ||
end | ||
end |
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 |
---|---|---|
|
@@ -57,7 +57,6 @@ def self.load_controllers | |
|
||
def self.run! | ||
register_resources | ||
require 'byebug' | ||
super | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
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,34 @@ | ||
// Copyright 2015 gRPC authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
syntax = "proto3"; | ||
|
||
option java_multiple_files = true; | ||
option java_package = "io.grpc.examples.helloworld"; | ||
option java_outer_classname = "HelloWorldProto"; | ||
option objc_class_prefix = "HLW"; | ||
|
||
package helloworld; | ||
|
||
// The greeting service definition. | ||
service Greeter { | ||
// Sends a greeting | ||
rpc SayHello(HelloRequest) returns (HelloReply) {} | ||
} | ||
|
||
// The request message containing the user's name. | ||
message HelloRequest { string name = 1; } | ||
|
||
// The response message containing the greetings | ||
message HelloReply { string message = 1; } |
Oops, something went wrong.