dor-event-client 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +10 -0
- data/.github/pull_request_template.md +10 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.rubocop.yml +164 -0
- data/.rubocop_todo.yml +0 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +94 -0
- data/LICENSE +14 -0
- data/README.md +80 -0
- data/Rakefile +11 -0
- data/dor-event-client.gemspec +38 -0
- data/lib/dor/event/client/create_operation.rb +29 -0
- data/lib/dor/event/client/rabbit_channel_factory.rb +38 -0
- data/lib/dor/event/client/version.rb +9 -0
- data/lib/dor/event/client.rb +57 -0
- metadata +210 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8d3ca1afb0370d0a9ab616bc94cad7ee3d38e0cc5f9f3ba5bbe1183a3d660329
|
4
|
+
data.tar.gz: 916f4121e8948e3a93f6055e4a8565ddb192a4bdb24117e28704929a43f72cab
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 570533c87783ef07304db49ab95b0d2886dbe0113709df5e1e6dc8c4cdee022f5f0d8172cda537b58ade12a5d4004b6809d64b646f4fff8eb523b40c160a2f87
|
7
|
+
data.tar.gz: d0117b3d2d0a21302ca19d92aaaad5a11397dda8d11b647848dfa7e6fa6e86c4e71a43dafcea0a0bca68dc313f2ad28a5e3033dcb1b827d99cffc86921dfe62b
|
@@ -0,0 +1,10 @@
|
|
1
|
+
## Why was this change made? 🤔
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
## How was this change tested? 🤨
|
6
|
+
|
7
|
+
âš¡ âš If this change affects the API or other fundamentals of this service, ***run [integration tests](https://github.com/sul-dlss/infrastructure-integration-test)*** that exercise this service and/or test in [stage|qa] environment, in addition to specs. âš¡
|
8
|
+
|
9
|
+
|
10
|
+
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
TargetRubyVersion: 3.0
|
8
|
+
SuggestExtensions: false
|
9
|
+
|
10
|
+
Metrics/BlockLength:
|
11
|
+
Exclude:
|
12
|
+
- 'dor-event-client.gemspec'
|
13
|
+
- 'spec/**/*'
|
14
|
+
|
15
|
+
RSpec/MultipleMemoizedHelpers:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
RSpec/MultipleExpectations:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Layout/SpaceBeforeBrackets: # (new in 1.7)
|
22
|
+
Enabled: true
|
23
|
+
Lint/AmbiguousAssignment: # (new in 1.7)
|
24
|
+
Enabled: true
|
25
|
+
Lint/DeprecatedConstants: # (new in 1.8)
|
26
|
+
Enabled: true
|
27
|
+
Lint/DuplicateBranch: # (new in 1.3)
|
28
|
+
Enabled: true
|
29
|
+
Lint/DuplicateRegexpCharacterClassElement: # (new in 1.1)
|
30
|
+
Enabled: true
|
31
|
+
Lint/EmptyBlock: # (new in 1.1)
|
32
|
+
Enabled: true
|
33
|
+
Lint/EmptyClass: # (new in 1.3)
|
34
|
+
Enabled: true
|
35
|
+
Lint/EmptyInPattern: # (new in 1.16)
|
36
|
+
Enabled: true
|
37
|
+
Lint/LambdaWithoutLiteralBlock: # (new in 1.8)
|
38
|
+
Enabled: true
|
39
|
+
Lint/NoReturnInBeginEndBlocks: # (new in 1.2)
|
40
|
+
Enabled: true
|
41
|
+
Lint/NumberedParameterAssignment: # (new in 1.9)
|
42
|
+
Enabled: true
|
43
|
+
Lint/OrAssignmentToConstant: # (new in 1.9)
|
44
|
+
Enabled: true
|
45
|
+
Lint/RedundantDirGlobSort: # (new in 1.8)
|
46
|
+
Enabled: true
|
47
|
+
Lint/SymbolConversion: # (new in 1.9)
|
48
|
+
Enabled: true
|
49
|
+
Lint/ToEnumArguments: # (new in 1.1)
|
50
|
+
Enabled: true
|
51
|
+
Lint/TripleQuotes: # (new in 1.9)
|
52
|
+
Enabled: true
|
53
|
+
Lint/UnexpectedBlockArity: # (new in 1.5)
|
54
|
+
Enabled: true
|
55
|
+
Lint/UnmodifiedReduceAccumulator: # (new in 1.1)
|
56
|
+
Enabled: true
|
57
|
+
Style/ArgumentsForwarding: # (new in 1.1)
|
58
|
+
Enabled: true
|
59
|
+
Style/CollectionCompact: # (new in 1.2)
|
60
|
+
Enabled: true
|
61
|
+
Style/DocumentDynamicEvalDefinition: # (new in 1.1)
|
62
|
+
Enabled: true
|
63
|
+
Style/EndlessMethod: # (new in 1.8)
|
64
|
+
Enabled: true
|
65
|
+
Style/HashConversion: # (new in 1.10)
|
66
|
+
Enabled: true
|
67
|
+
Style/HashExcept: # (new in 1.7)
|
68
|
+
Enabled: true
|
69
|
+
Style/IfWithBooleanLiteralBranches: # (new in 1.9)
|
70
|
+
Enabled: true
|
71
|
+
Style/InPatternThen: # (new in 1.16)
|
72
|
+
Enabled: true
|
73
|
+
Style/MultilineInPatternThen: # (new in 1.16)
|
74
|
+
Enabled: true
|
75
|
+
Style/NegatedIfElseCondition: # (new in 1.2)
|
76
|
+
Enabled: true
|
77
|
+
Style/NilLambda: # (new in 1.3)
|
78
|
+
Enabled: true
|
79
|
+
Style/QuotedSymbols: # (new in 1.16)
|
80
|
+
Enabled: true
|
81
|
+
Style/RedundantArgument: # (new in 1.4)
|
82
|
+
Enabled: true
|
83
|
+
Style/StringChars: # (new in 1.12)
|
84
|
+
Enabled: true
|
85
|
+
Style/SwapValues: # (new in 1.1)
|
86
|
+
Enabled: true
|
87
|
+
Layout/LineEndStringConcatenationIndentation: # (new in 1.18)
|
88
|
+
Enabled: true
|
89
|
+
Naming/InclusiveLanguage: # (new in 1.18)
|
90
|
+
Enabled: true
|
91
|
+
|
92
|
+
Gemspec/RequireMFA: # new in 1.23
|
93
|
+
Enabled: true
|
94
|
+
Lint/AmbiguousOperatorPrecedence: # new in 1.21
|
95
|
+
Enabled: true
|
96
|
+
Lint/AmbiguousRange: # new in 1.19
|
97
|
+
Enabled: true
|
98
|
+
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
|
99
|
+
Enabled: true
|
100
|
+
Lint/RequireRelativeSelfPath: # new in 1.22
|
101
|
+
Enabled: true
|
102
|
+
Lint/UselessRuby2Keywords: # new in 1.23
|
103
|
+
Enabled: true
|
104
|
+
Naming/BlockForwarding: # new in 1.24
|
105
|
+
Enabled: true
|
106
|
+
Security/IoMethods: # new in 1.22
|
107
|
+
Enabled: true
|
108
|
+
Style/FileRead: # new in 1.24
|
109
|
+
Enabled: true
|
110
|
+
Style/FileWrite: # new in 1.24
|
111
|
+
Enabled: true
|
112
|
+
Style/MapToHash: # new in 1.24
|
113
|
+
Enabled: true
|
114
|
+
Style/NumberedParameters: # new in 1.22
|
115
|
+
Enabled: true
|
116
|
+
Style/NumberedParametersLimit: # new in 1.22
|
117
|
+
Enabled: true
|
118
|
+
Style/OpenStructUse: # new in 1.23
|
119
|
+
Enabled: true
|
120
|
+
Style/RedundantSelfAssignmentBranch: # new in 1.19
|
121
|
+
Enabled: true
|
122
|
+
Style/SelectByRegexp: # new in 1.22
|
123
|
+
Enabled: true
|
124
|
+
|
125
|
+
RSpec/ExcessiveDocstringSpacing: # new in 2.5
|
126
|
+
Enabled: true
|
127
|
+
RSpec/IdenticalEqualityAssertion: # new in 2.4
|
128
|
+
Enabled: true
|
129
|
+
RSpec/SubjectDeclaration: # new in 2.5
|
130
|
+
Enabled: true
|
131
|
+
RSpec/FactoryBot/SyntaxMethods: # new in 2.7
|
132
|
+
Enabled: true
|
133
|
+
RSpec/Rails/AvoidSetupHook: # new in 2.4
|
134
|
+
Enabled: true
|
135
|
+
|
136
|
+
Lint/RefinementImportMethods: # new in 1.27
|
137
|
+
Enabled: true
|
138
|
+
Security/CompoundHash: # new in 1.28
|
139
|
+
Enabled: true
|
140
|
+
Style/FetchEnvVar: # new in 1.28
|
141
|
+
Enabled: true
|
142
|
+
Style/NestedFileDirname: # new in 1.26
|
143
|
+
Enabled: true
|
144
|
+
Style/ObjectThen: # new in 1.28
|
145
|
+
Enabled: true
|
146
|
+
Style/RedundantInitialize: # new in 1.27
|
147
|
+
Enabled: true
|
148
|
+
RSpec/BeEq: # new in 2.9.0
|
149
|
+
Enabled: true
|
150
|
+
RSpec/BeNil: # new in 2.9.0
|
151
|
+
Enabled: true
|
152
|
+
RSpec/VerifiedDoubleReference: # new in 2.10.0
|
153
|
+
Enabled: true
|
154
|
+
|
155
|
+
Gemspec/DateAssignment: # new in 1.10
|
156
|
+
Enabled: true
|
157
|
+
Gemspec/DeprecatedAttributeAssignment: # new in 1.30
|
158
|
+
Enabled: true
|
159
|
+
Style/EnvHome: # new in 1.29
|
160
|
+
Enabled: true
|
161
|
+
Style/MapCompactWithConditionalBlock: # new in 1.30
|
162
|
+
Enabled: true
|
163
|
+
RSpec/ChangeByZero: # new in 2.11.0
|
164
|
+
Enabled: true
|
data/.rubocop_todo.yml
ADDED
File without changes
|
data/Gemfile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
6
|
+
|
7
|
+
gem 'activesupport', ENV.fetch('RAILS_VERSION', nil) if ENV['RAILS_VERSION']
|
8
|
+
|
9
|
+
# Specify your gem's dependencies in dor-services-client.gemspec
|
10
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
dor-event-client (1.0.0)
|
5
|
+
activesupport (>= 4.2, < 8)
|
6
|
+
bunny (~> 2.17)
|
7
|
+
zeitwerk (~> 2.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
activesupport (7.0.3)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 1.6, < 2)
|
15
|
+
minitest (>= 5.1)
|
16
|
+
tzinfo (~> 2.0)
|
17
|
+
amq-protocol (2.3.2)
|
18
|
+
ast (2.4.2)
|
19
|
+
bunny (2.19.0)
|
20
|
+
amq-protocol (~> 2.3, >= 2.3.1)
|
21
|
+
sorted_set (~> 1, >= 1.0.2)
|
22
|
+
byebug (11.1.3)
|
23
|
+
concurrent-ruby (1.1.10)
|
24
|
+
diff-lcs (1.5.0)
|
25
|
+
docile (1.4.0)
|
26
|
+
i18n (1.10.0)
|
27
|
+
concurrent-ruby (~> 1.0)
|
28
|
+
minitest (5.16.1)
|
29
|
+
parallel (1.22.1)
|
30
|
+
parser (3.1.2.0)
|
31
|
+
ast (~> 2.4.1)
|
32
|
+
rainbow (3.1.1)
|
33
|
+
rake (13.0.6)
|
34
|
+
rbtree (0.4.5)
|
35
|
+
regexp_parser (2.5.0)
|
36
|
+
rexml (3.2.5)
|
37
|
+
rspec (3.11.0)
|
38
|
+
rspec-core (~> 3.11.0)
|
39
|
+
rspec-expectations (~> 3.11.0)
|
40
|
+
rspec-mocks (~> 3.11.0)
|
41
|
+
rspec-core (3.11.0)
|
42
|
+
rspec-support (~> 3.11.0)
|
43
|
+
rspec-expectations (3.11.0)
|
44
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
45
|
+
rspec-support (~> 3.11.0)
|
46
|
+
rspec-mocks (3.11.1)
|
47
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
48
|
+
rspec-support (~> 3.11.0)
|
49
|
+
rspec-support (3.11.0)
|
50
|
+
rubocop (1.30.1)
|
51
|
+
parallel (~> 1.10)
|
52
|
+
parser (>= 3.1.0.0)
|
53
|
+
rainbow (>= 2.2.2, < 4.0)
|
54
|
+
regexp_parser (>= 1.8, < 3.0)
|
55
|
+
rexml (>= 3.2.5, < 4.0)
|
56
|
+
rubocop-ast (>= 1.18.0, < 2.0)
|
57
|
+
ruby-progressbar (~> 1.7)
|
58
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
59
|
+
rubocop-ast (1.18.0)
|
60
|
+
parser (>= 3.1.1.0)
|
61
|
+
rubocop-rspec (2.11.1)
|
62
|
+
rubocop (~> 1.19)
|
63
|
+
ruby-progressbar (1.11.0)
|
64
|
+
set (1.0.2)
|
65
|
+
simplecov (0.21.2)
|
66
|
+
docile (~> 1.1)
|
67
|
+
simplecov-html (~> 0.11)
|
68
|
+
simplecov_json_formatter (~> 0.1)
|
69
|
+
simplecov-html (0.12.3)
|
70
|
+
simplecov_json_formatter (0.1.4)
|
71
|
+
sorted_set (1.0.3)
|
72
|
+
rbtree
|
73
|
+
set (~> 1.0)
|
74
|
+
tzinfo (2.0.4)
|
75
|
+
concurrent-ruby (~> 1.0)
|
76
|
+
unicode-display_width (2.1.0)
|
77
|
+
zeitwerk (2.6.0)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
x86_64-darwin-20
|
81
|
+
x86_64-linux
|
82
|
+
|
83
|
+
DEPENDENCIES
|
84
|
+
bundler
|
85
|
+
byebug
|
86
|
+
dor-event-client!
|
87
|
+
rake (>= 12.3.3)
|
88
|
+
rspec (~> 3.0)
|
89
|
+
rubocop (~> 1.0)
|
90
|
+
rubocop-rspec (~> 2.1)
|
91
|
+
simplecov
|
92
|
+
|
93
|
+
BUNDLED WITH
|
94
|
+
2.3.14
|
data/LICENSE
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Copyright (c) 2018 by The Board of Trustees of the Leland Stanford
|
2
|
+
Junior University. All rights reserved.
|
3
|
+
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you
|
5
|
+
may not use this file except in compliance with the License. You
|
6
|
+
may obtain a copy of the License at
|
7
|
+
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
13
|
+
implied. See the License for the specific language governing
|
14
|
+
permissions and limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/dor-event-client.svg)](https://badge.fury.io/rb/dor-event-client)
|
2
|
+
[![CircleCI](https://circleci.com/gh/sul-dlss/dor-event-client.svg?style=svg)](https://circleci.com/gh/sul-dlss/dor-event-client)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/sul-dlss/dor-event-client/badges/gpa.svg)](https://codeclimate.com/github/sul-dlss/dor-event-client)
|
4
|
+
[![Code Climate Test Coverage](https://codeclimate.com/github/sul-dlss/dor-event-client/badges/coverage.svg)](https://codeclimate.com/github/sul-dlss/dorevent-client/coverage)
|
5
|
+
|
6
|
+
# Dor::Event::Client
|
7
|
+
|
8
|
+
Dor::Event::Client is a Ruby gem that acts as a client for the event services provided by [dor-services-app](https://github.com/sul-dlss/dor-services-app).
|
9
|
+
|
10
|
+
Currently, the client only supports the asynchronous creation of events (via RabbitMQ). In the future, other operations
|
11
|
+
(including synchronous operations via HTTP) may be supported. At present, additional event operations are supported by
|
12
|
+
[dor-services-client](https://github.com/sul-dlss/dor-services-client).
|
13
|
+
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'dor-event-client'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install dor-event-client
|
30
|
+
|
31
|
+
## Configuration
|
32
|
+
|
33
|
+
To configure and use the client, here's an example for a Rails app:
|
34
|
+
|
35
|
+
In `config/initializers/dor_event_client.rb`:
|
36
|
+
```ruby
|
37
|
+
Dor::Event::Client.configure(hostname: Settings.rabbitmq.hostname,
|
38
|
+
vhost: Settings.rabbitmq.vhost,
|
39
|
+
username: Settings.rabbitmq.username,
|
40
|
+
password: Settings.rabbitmq.password)
|
41
|
+
```
|
42
|
+
|
43
|
+
|
44
|
+
## Operations
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
# Create and list events for an object
|
48
|
+
Dor::Event::Client.create(druid:, type:, data:)
|
49
|
+
|
50
|
+
# For example:
|
51
|
+
Dor::Event::Client.create(
|
52
|
+
druid: 'druid:bb408qn5061',
|
53
|
+
type: 'druid_version_replicated',
|
54
|
+
data {
|
55
|
+
host: 'preservation-catalog-qa-02.stanford.edu',
|
56
|
+
version: 19,
|
57
|
+
invoked_by: 'preservation-catalog',
|
58
|
+
parts_info: [
|
59
|
+
{
|
60
|
+
md5: '1a528419dea59d86cfd0c456e9f10024',
|
61
|
+
size: 123630,
|
62
|
+
s3_key: 'bb/408/qn/5061/bb408qn5061.v0019.zip'
|
63
|
+
}
|
64
|
+
],
|
65
|
+
endpoint_name: 'aws_s3_east_1'
|
66
|
+
}:
|
67
|
+
)
|
68
|
+
```
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sul-dlss/dor-event-client
|
77
|
+
|
78
|
+
## Copyright
|
79
|
+
|
80
|
+
Copyright (c) 2018 Stanford Libraries. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'dor/event/client/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'dor-event-client'
|
9
|
+
spec.version = Dor::Event::Client::VERSION
|
10
|
+
spec.authors = ['Justin Coyne', 'Michael Giarlo']
|
11
|
+
spec.email = ['jcoyne@justincoyne.com', 'leftwing@alumni.rutgers.edu']
|
12
|
+
|
13
|
+
spec.summary = 'A client for event services provided by DOR Services App'
|
14
|
+
spec.homepage = 'https://github.com/sul-dlss/event-client'
|
15
|
+
|
16
|
+
# Specify which files should be added to the gem when it is released.
|
17
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
18
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
19
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ['lib']
|
24
|
+
spec.required_ruby_version = '>= 3.0', '< 4'
|
25
|
+
|
26
|
+
spec.add_dependency 'activesupport', '>= 4.2', '< 8'
|
27
|
+
spec.add_dependency 'bunny', '~> 2.17' # Send messages to RabbitMQ
|
28
|
+
spec.add_dependency 'zeitwerk', '~> 2.1'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler'
|
31
|
+
spec.add_development_dependency 'byebug'
|
32
|
+
spec.add_development_dependency 'rake', '>= 12.3.3'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 1.0'
|
35
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.1'
|
36
|
+
spec.add_development_dependency 'simplecov'
|
37
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
38
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dor
|
4
|
+
module Event
|
5
|
+
class Client
|
6
|
+
# Create an Event
|
7
|
+
class CreateOperation
|
8
|
+
def initialize(channel:)
|
9
|
+
@channel = channel
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param druid [String] object identifier
|
13
|
+
# @param type [String] a type for the event, e.g., publish, shelve
|
14
|
+
# @param data [Hash] an unstructured hash of event data
|
15
|
+
# @return [Boolean] true if successful
|
16
|
+
def create(druid:, type:, data:)
|
17
|
+
message = { druid: druid, event_type: type, data: data }
|
18
|
+
channel.topic('sdr.objects.event').publish(message.to_json, routing_key: type)
|
19
|
+
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
attr_reader :channel
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dor
|
4
|
+
module Event
|
5
|
+
class Client
|
6
|
+
# Factory for creating Rabbit channel.
|
7
|
+
# Note that that channel is lazily created.
|
8
|
+
class RabbitChannelFactory
|
9
|
+
def initialize(hostname:, vhost:, username:, password:)
|
10
|
+
@hostname = hostname
|
11
|
+
@vhost = vhost
|
12
|
+
@username = username
|
13
|
+
@password = password
|
14
|
+
end
|
15
|
+
|
16
|
+
delegate :topic, to: :channel
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
attr_reader :vhost, :username, :password
|
21
|
+
|
22
|
+
def hostname
|
23
|
+
@hostname || raise(Error, 'hostname has not yet been configured')
|
24
|
+
end
|
25
|
+
|
26
|
+
def channel
|
27
|
+
@channel ||= begin
|
28
|
+
connection = Bunny.new(hostname: hostname,
|
29
|
+
vhost: vhost,
|
30
|
+
username: username,
|
31
|
+
password: password).tap(&:start)
|
32
|
+
connection.create_channel
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
require 'active_support/json'
|
5
|
+
require 'active_support/core_ext/object/json'
|
6
|
+
require 'bunny'
|
7
|
+
require 'singleton'
|
8
|
+
require 'zeitwerk'
|
9
|
+
|
10
|
+
loader = Zeitwerk::Loader.new
|
11
|
+
loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
|
12
|
+
loader.push_dir(File.absolute_path("#{__FILE__}/../../.."))
|
13
|
+
loader.setup
|
14
|
+
|
15
|
+
module Dor
|
16
|
+
module Event
|
17
|
+
# Client for event services.
|
18
|
+
class Client
|
19
|
+
include Singleton
|
20
|
+
|
21
|
+
# Base class for Dor::Event::Client exceptions
|
22
|
+
class Error < StandardError; end
|
23
|
+
|
24
|
+
delegate :create, to: :create_operation
|
25
|
+
|
26
|
+
class << self
|
27
|
+
def configure(hostname:, vhost:, username:, password:)
|
28
|
+
instance.hostname = hostname
|
29
|
+
instance.vhost = vhost
|
30
|
+
instance.username = username
|
31
|
+
instance.password = password
|
32
|
+
|
33
|
+
# Force channel to be re-established when `.configure` is called
|
34
|
+
instance.channel = nil
|
35
|
+
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
delegate :create, to: :instance
|
40
|
+
end
|
41
|
+
|
42
|
+
attr_writer :hostname, :vhost, :username, :password, :channel
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
attr_reader :hostname, :vhost, :username, :password
|
47
|
+
|
48
|
+
def channel
|
49
|
+
@channel ||= RabbitChannelFactory.new(hostname: hostname, vhost: vhost, username: username, password: password)
|
50
|
+
end
|
51
|
+
|
52
|
+
def create_operation
|
53
|
+
@create_operation ||= CreateOperation.new(channel: channel)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,210 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dor-event-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Justin Coyne
|
8
|
+
- Michael Giarlo
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2022-06-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.2'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '8'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '4.2'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '8'
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: bunny
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.17'
|
41
|
+
type: :runtime
|
42
|
+
prerelease: false
|
43
|
+
version_requirements: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.17'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: zeitwerk
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
type: :development
|
70
|
+
prerelease: false
|
71
|
+
version_requirements: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
name: byebug
|
78
|
+
requirement: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
- !ruby/object:Gem::Dependency
|
91
|
+
name: rake
|
92
|
+
requirement: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 12.3.3
|
97
|
+
type: :development
|
98
|
+
prerelease: false
|
99
|
+
version_requirements: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 12.3.3
|
104
|
+
- !ruby/object:Gem::Dependency
|
105
|
+
name: rspec
|
106
|
+
requirement: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
- !ruby/object:Gem::Dependency
|
119
|
+
name: rubocop
|
120
|
+
requirement: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '1.0'
|
132
|
+
- !ruby/object:Gem::Dependency
|
133
|
+
name: rubocop-rspec
|
134
|
+
requirement: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '2.1'
|
139
|
+
type: :development
|
140
|
+
prerelease: false
|
141
|
+
version_requirements: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '2.1'
|
146
|
+
- !ruby/object:Gem::Dependency
|
147
|
+
name: simplecov
|
148
|
+
requirement: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
type: :development
|
154
|
+
prerelease: false
|
155
|
+
version_requirements: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
description:
|
161
|
+
email:
|
162
|
+
- jcoyne@justincoyne.com
|
163
|
+
- leftwing@alumni.rutgers.edu
|
164
|
+
executables: []
|
165
|
+
extensions: []
|
166
|
+
extra_rdoc_files: []
|
167
|
+
files:
|
168
|
+
- ".circleci/config.yml"
|
169
|
+
- ".github/pull_request_template.md"
|
170
|
+
- ".gitignore"
|
171
|
+
- ".rspec"
|
172
|
+
- ".rubocop.yml"
|
173
|
+
- ".rubocop_todo.yml"
|
174
|
+
- Gemfile
|
175
|
+
- Gemfile.lock
|
176
|
+
- LICENSE
|
177
|
+
- README.md
|
178
|
+
- Rakefile
|
179
|
+
- dor-event-client.gemspec
|
180
|
+
- lib/dor/event/client.rb
|
181
|
+
- lib/dor/event/client/create_operation.rb
|
182
|
+
- lib/dor/event/client/rabbit_channel_factory.rb
|
183
|
+
- lib/dor/event/client/version.rb
|
184
|
+
homepage: https://github.com/sul-dlss/event-client
|
185
|
+
licenses: []
|
186
|
+
metadata:
|
187
|
+
rubygems_mfa_required: 'true'
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '3.0'
|
197
|
+
- - "<"
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '4'
|
200
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
|
+
requirements:
|
202
|
+
- - ">="
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
requirements: []
|
206
|
+
rubygems_version: 3.3.7
|
207
|
+
signing_key:
|
208
|
+
specification_version: 4
|
209
|
+
summary: A client for event services provided by DOR Services App
|
210
|
+
test_files: []
|