grpc_toolbox 0.0.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/README.md +128 -0
- data/lib/auditor_pb.rb +2 -2
- data/lib/grpc_toolbox/client.rb +29 -18
- data/lib/grpc_toolbox/configuration.rb +1 -1
- data/lib/grpc_toolbox/version.rb +5 -0
- data/lib/grpc_toolbox.rb +2 -1
- metadata +83 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 732e7da9e1516a9874903eb6c23e79524abd00bd13e66c9a03ababb86ba4a0f8
|
4
|
+
data.tar.gz: 983fcd3880d64149681633808be70a64e0b37d88f733a63fa0a9add74f172660
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3807eebd4573933256b6ba1c08bf262b52c0d9c91d80a3d3cbe9beb69fe8fd05810da34b3c6295279120a95b26d03423e0206ed452574d88593d2f5b9c4f5179
|
7
|
+
data.tar.gz: 0603ca06512bcbe05e9d4f1add9a8dc64b16389ed4c2fdb8f2dd57b387651e57ea758b9e452b9146da8573cf4dafa9deb2eb43194b2e1521bfeb6a1adcc31531
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
|
+
and this project adheres to [Semantic Versioning 2.0.0](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [0.1.1] - 2023-04-06
|
8
|
+
### Changed
|
9
|
+
- Republish with a different version due to yank.
|
10
|
+
|
11
|
+
## [0.1.0] - 2023-04-06
|
12
|
+
### Added
|
13
|
+
- Changed gemspec configuration
|
14
|
+
- Changed `.send_audit_request` based on grpc server changes
|
15
|
+
- Added validation on `.send_audit_request` parameters
|
16
|
+
|
17
|
+
## [0.0.0] - 2023-04-04
|
18
|
+
### Added
|
19
|
+
- Created GRPC Toolbox MVP
|
data/README.md
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
# GrpcToolbox
|
2
|
+
|
3
|
+
This is a Gem created to manage the connection of a ruby/rails service
|
4
|
+
to Guide's GRPC Server (Sidecar). With it you can simplify the connection
|
5
|
+
process and send data to the sidecar both synchronously and asynchronously.
|
6
|
+
|
7
|
+
## Pre-requisites
|
8
|
+
|
9
|
+
In order to connect to the grpc server, the app *must* use the https protocol.
|
10
|
+
In order to successfully connect to the server through https - instead of having it's connection
|
11
|
+
refused -, a `.crt ` security certificate file must be provided.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
You can do that by either adding this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'grpc_toolbox'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then executing:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
bundle install
|
25
|
+
```
|
26
|
+
|
27
|
+
Or by installing directly with:
|
28
|
+
|
29
|
+
```bash
|
30
|
+
gem install grpc_toolbox
|
31
|
+
```
|
32
|
+
|
33
|
+
## Configuration
|
34
|
+
## Step 1 - Configure the Certificate Volume
|
35
|
+
|
36
|
+
You only need to this step if you're using `docker` or `docker-compose` to run the application.
|
37
|
+
As said on the `Pre-requisites` section, you'll need a `.crt` file that can authenticate your connection
|
38
|
+
to the grpc server.
|
39
|
+
This step is to make it so the container can copy the `.crt` file provided by the host.
|
40
|
+
|
41
|
+
If you're using docker-compose, all you'll need to do is to make sure the `volumes` section of your
|
42
|
+
`docker-compose.yaml` has this line:
|
43
|
+
|
44
|
+
```yaml
|
45
|
+
volumes:
|
46
|
+
- "${HOST_CERTIFICATES}/:${CONTAINER_CERTIFICATES_FOLDER}/"
|
47
|
+
```
|
48
|
+
|
49
|
+
Where:
|
50
|
+
|
51
|
+
* `HOST_CERTIFICATES` is the path to the folder on the HOST machine where the .crt file is located
|
52
|
+
* `CONTAINER_CERTIFICATES_FOLDER` is the path to folder on the CONTAINER where the host's files are going to be copied to.
|
53
|
+
|
54
|
+
Example:
|
55
|
+
|
56
|
+
```yaml
|
57
|
+
volumes:
|
58
|
+
- "/home/master/certificates/:/https/"
|
59
|
+
```
|
60
|
+
|
61
|
+
if you're using `docker run`, you'll need to add the following option to your command:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
-v {HOST_CERTIFICATES}:{CONTAINER_CERTIFICATES_FOLDER}
|
65
|
+
```
|
66
|
+
|
67
|
+
Where:
|
68
|
+
|
69
|
+
* `HOST_CERTIFICATES` is the path to the folder on the HOST machine where the .crt file is located
|
70
|
+
* `CONTAINER_CERTIFICATES_FOLDER` is the path to folder on the CONTAINER where the host's files are going to be copied to.
|
71
|
+
|
72
|
+
Example:
|
73
|
+
|
74
|
+
```bash
|
75
|
+
docker run --name your_service -v /home/master/certificates:/https/ your-image
|
76
|
+
```
|
77
|
+
|
78
|
+
## Step 2 - Configure the Environment Variables
|
79
|
+
|
80
|
+
Create a file named `grpc_toolbox.rb` inside the `config/initializers`, then add the following lines:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
GRPCToolbox.configure do |config|
|
84
|
+
config.server = {GRPC_SERVER_HOST}
|
85
|
+
config.certificate_path = {CONTAINER_CERTIFICATES_FULLPATH}
|
86
|
+
end
|
87
|
+
```
|
88
|
+
|
89
|
+
Where
|
90
|
+
|
91
|
+
* `GRPC_SERVER_HOST` is the address the gem will use to communicate to the grpc_server
|
92
|
+
* `CONTAINER_CERTIFICATES_FULLPATH` is the full path to the `.crt` file the gem will use, including the file name.
|
93
|
+
* If this gem is being used on a docker container, the path should relate to a path inside the container.
|
94
|
+
|
95
|
+
Example:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
GRPCToolbox.configure do |config|
|
99
|
+
config.server = "sidecar:443"
|
100
|
+
config.certificate_path = "/https/example.crt"
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
## Usage
|
105
|
+
|
106
|
+
Once configured, you'll just need to create an client object:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
client = GRPCToolbox::Client.new
|
110
|
+
```
|
111
|
+
|
112
|
+
then, pass the params you want to send as hash to the function `send_audit_request`:
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
params = {
|
116
|
+
origin_ip: '127.0.0.1',
|
117
|
+
username: 'rlnascimento',
|
118
|
+
origin_type: 'num-sei',
|
119
|
+
system: 'gem-toolbox',
|
120
|
+
module: 'gem',
|
121
|
+
operation_type: 'update'
|
122
|
+
}
|
123
|
+
|
124
|
+
client.async.send_audit_request(params)
|
125
|
+
```
|
126
|
+
|
127
|
+
You can either use `client.async.send_audit_request` or `client.send_audit_request`. The logic is
|
128
|
+
the same, the only difference is that the first one is asynchronous and the second one is not.
|
data/lib/auditor_pb.rb
CHANGED
@@ -15,8 +15,8 @@ Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
15
15
|
optional :system, :string, 5
|
16
16
|
optional :module, :string, 6
|
17
17
|
optional :operation_type, :string, 7
|
18
|
-
optional :
|
19
|
-
optional :
|
18
|
+
optional :changed_data, :bytes, 8
|
19
|
+
optional :audited_data, :bytes, 9
|
20
20
|
end
|
21
21
|
add_message "auditor.SendAuditReply" do
|
22
22
|
optional :accepted, :bool, 1
|
data/lib/grpc_toolbox/client.rb
CHANGED
@@ -2,27 +2,34 @@
|
|
2
2
|
|
3
3
|
require 'grpc'
|
4
4
|
require 'concurrent-ruby'
|
5
|
+
require 'google/protobuf/well_known_types'
|
5
6
|
|
7
|
+
require 'auditor_pb'
|
6
8
|
require 'auditor_services_pb'
|
7
9
|
|
8
10
|
module GRPCToolbox
|
9
11
|
class Client
|
10
12
|
include Concurrent::Async
|
11
13
|
|
14
|
+
REQUIRED_PARAMS = %i[system module username origin_ip audited_data].freeze
|
15
|
+
|
12
16
|
def config
|
13
17
|
@config ||= GRPCToolbox.configuration
|
14
18
|
end
|
15
19
|
|
16
20
|
def send_audit_request(params)
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
)
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
validate_params(params)
|
22
|
+
|
23
|
+
stub = Auditor::Auditor::Stub.new(config.server, channel_credentials)
|
24
|
+
|
25
|
+
stub.send_audit(
|
26
|
+
Auditor::SendAuditRequest.new(audit_request_params(params))
|
27
|
+
)
|
28
|
+
rescue StandardError => e
|
29
|
+
Auditor::SendAuditReply.new(
|
30
|
+
accepted: false,
|
31
|
+
message: "EXCEPTION - #{e.class} : #{e.message}"
|
32
|
+
)
|
26
33
|
end
|
27
34
|
|
28
35
|
private
|
@@ -34,19 +41,23 @@ module GRPCToolbox
|
|
34
41
|
end
|
35
42
|
|
36
43
|
def audit_request_params(params)
|
37
|
-
# TODO: pensar numa forma de indicar ao cliente como mandar os parametros corretos
|
38
|
-
# TODO: adicionar uma clausula que quebra caso algum dado importante nao seja mandado
|
39
44
|
{
|
40
|
-
origin_ip: params[:origin_ip],
|
41
|
-
username: params[:username],
|
45
|
+
origin_ip: params[:origin_ip], username: params[:username],
|
42
46
|
origin_type: params[:origin_type],
|
43
|
-
operation_timestamp: Time.now
|
44
|
-
system: params[:system],
|
45
|
-
module: params[:module],
|
47
|
+
operation_timestamp: Google::Protobuf::Timestamp.new.from_time(Time.now),
|
48
|
+
system: params[:system], module: params[:module],
|
46
49
|
operation_type: params[:operation_type],
|
47
|
-
|
48
|
-
|
50
|
+
changed_data: params[:changed_data],
|
51
|
+
audited_data: params[:audited_data]
|
49
52
|
}
|
50
53
|
end
|
54
|
+
|
55
|
+
def validate_params(params)
|
56
|
+
errors = REQUIRED_PARAMS.filter_map do |param|
|
57
|
+
"#{param} can't be nil" if params[param].nil?
|
58
|
+
end
|
59
|
+
|
60
|
+
raise ArgumentError, errors.join('; ') unless errors.empty?
|
61
|
+
end
|
51
62
|
end
|
52
63
|
end
|
data/lib/grpc_toolbox.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grpc_toolbox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo de Lucas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: concurrent-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.2.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.2.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: google-protobuf
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.21'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.21'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: grpc
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,61 +53,89 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: 1.52.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - '='
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 13.0.6
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - '='
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 13.0.6
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: dotenv
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.8.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.8.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: grpc_mock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
55
97
|
- !ruby/object:Gem::Dependency
|
56
98
|
name: grpc-tools
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
|
-
- - "
|
101
|
+
- - "~>"
|
60
102
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
103
|
+
version: 1.50.0
|
62
104
|
type: :development
|
63
105
|
prerelease: false
|
64
106
|
version_requirements: !ruby/object:Gem::Requirement
|
65
107
|
requirements:
|
66
|
-
- - "
|
108
|
+
- - "~>"
|
67
109
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
110
|
+
version: 1.50.0
|
69
111
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
112
|
+
name: pry
|
71
113
|
requirement: !ruby/object:Gem::Requirement
|
72
114
|
requirements:
|
73
|
-
- - "
|
115
|
+
- - "~>"
|
74
116
|
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
117
|
+
version: '0.13'
|
76
118
|
type: :development
|
77
119
|
prerelease: false
|
78
120
|
version_requirements: !ruby/object:Gem::Requirement
|
79
121
|
requirements:
|
80
|
-
- - "
|
122
|
+
- - "~>"
|
81
123
|
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
124
|
+
version: '0.13'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: pry-byebug
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
86
128
|
requirements:
|
87
|
-
- - "
|
129
|
+
- - "~>"
|
88
130
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
131
|
+
version: '3.10'
|
90
132
|
type: :development
|
91
133
|
prerelease: false
|
92
134
|
version_requirements: !ruby/object:Gem::Requirement
|
93
135
|
requirements:
|
94
|
-
- - "
|
136
|
+
- - "~>"
|
95
137
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
138
|
+
version: '3.10'
|
97
139
|
- !ruby/object:Gem::Dependency
|
98
140
|
name: rspec
|
99
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,6 +150,20 @@ dependencies:
|
|
108
150
|
- - "~>"
|
109
151
|
- !ruby/object:Gem::Version
|
110
152
|
version: '3.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rubocop
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '1.49'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '1.49'
|
111
167
|
- !ruby/object:Gem::Dependency
|
112
168
|
name: shoulda-matchers
|
113
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,18 +178,21 @@ dependencies:
|
|
122
178
|
- - "~>"
|
123
179
|
- !ruby/object:Gem::Version
|
124
180
|
version: '3.1'
|
125
|
-
description: A simple grpc
|
181
|
+
description: A simple grpc client for Guide's Sidecar
|
126
182
|
email: rlnascimento@guide.com.br
|
127
183
|
executables: []
|
128
184
|
extensions: []
|
129
185
|
extra_rdoc_files: []
|
130
186
|
files:
|
187
|
+
- CHANGELOG.md
|
188
|
+
- README.md
|
131
189
|
- lib/auditor_pb.rb
|
132
190
|
- lib/auditor_services_pb.rb
|
133
191
|
- lib/grpc_toolbox.rb
|
134
192
|
- lib/grpc_toolbox/client.rb
|
135
193
|
- lib/grpc_toolbox/configuration.rb
|
136
|
-
|
194
|
+
- lib/grpc_toolbox/version.rb
|
195
|
+
homepage: https://bitbucket.org/guideinvestimentos/grpc_toolbox/src/master/
|
137
196
|
licenses:
|
138
197
|
- MIT
|
139
198
|
metadata: {}
|
@@ -145,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
204
|
requirements:
|
146
205
|
- - ">="
|
147
206
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
207
|
+
version: 3.1.0
|
149
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
209
|
requirements:
|
151
210
|
- - ">="
|