gds-api-adapters 0.0.29 → 0.0.30
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/gds_api/panopticon.rb +1 -0
- data/lib/gds_api/panopticon/registerer.rb +51 -0
- data/lib/gds_api/version.rb +1 -1
- data/test/panopticon_api_test.rb +11 -0
- metadata +4 -3
data/lib/gds_api/panopticon.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
module GdsApi
|
2
|
+
class Panopticon < GdsApi::Base
|
3
|
+
class Registerer
|
4
|
+
attr_accessor :logger, :owning_app, :kind
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@logger = options[:logger] || GdsApi::Base.logger
|
8
|
+
@owning_app = options[:owning_app]
|
9
|
+
@kind = options[:kind] || 'custom-application'
|
10
|
+
@panopticon = options[:panopticon]
|
11
|
+
end
|
12
|
+
|
13
|
+
def record_to_artefact(record)
|
14
|
+
{slug: record.slug, owning_app: owning_app, kind: kind, name: record.title}
|
15
|
+
end
|
16
|
+
|
17
|
+
# record should respond to #slug and #title, or override #record_to_artefact
|
18
|
+
def register(record)
|
19
|
+
register_artefact(record_to_artefact(record))
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def register_artefact(artefact)
|
25
|
+
logger.info "Checking #{artefact[:slug]}"
|
26
|
+
existing = panopticon.artefact_for_slug(artefact[:slug])
|
27
|
+
if ! existing
|
28
|
+
logger.info "Creating #{artefact[:slug]}"
|
29
|
+
panopticon.create_artefact(artefact)
|
30
|
+
elsif existing.owning_app == artefact[:owning_app]
|
31
|
+
logger.info "Updating #{artefact[:slug]}"
|
32
|
+
panopticon.update_artefact(artefact)
|
33
|
+
else
|
34
|
+
raise "Slug #{artefact[:slug]} already registered to application '#{existing.owning_app}'"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def panopticon
|
39
|
+
options = {
|
40
|
+
timeout: 5
|
41
|
+
}
|
42
|
+
platform = ENV['FACTER_govuk_platform'] || 'development'
|
43
|
+
@panopticon ||= GdsApi::Panopticon.new(platform, options.merge(panopticon_api_credentials))
|
44
|
+
end
|
45
|
+
|
46
|
+
def panopticon_api_credentials
|
47
|
+
Object::const_defined?(:PANOPTICON_API_CREDENTIALS) ? PANOPTICON_API_CREDENTIALS : {}
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/gds_api/version.rb
CHANGED
data/test/panopticon_api_test.rb
CHANGED
@@ -93,4 +93,15 @@ class PanopticonApiTest < MiniTest::Unit::TestCase
|
|
93
93
|
|
94
94
|
api.update_artefact(1, basic_artefact)
|
95
95
|
end
|
96
|
+
|
97
|
+
def test_can_register_artefacts_en_masse
|
98
|
+
panopticon = stub_everything('Panopticon api client')
|
99
|
+
r = GdsApi::Panopticon::Registerer.new(owning_app: 'my-app', panopticon: panopticon)
|
100
|
+
record = OpenStruct.new(slug: '/foo', title: 'MyFoo')
|
101
|
+
|
102
|
+
panopticon.stubs(:artefact_for_slug).returns(nil)
|
103
|
+
panopticon.expects(:create_artefact).with({slug: '/foo', owning_app: 'my-app', kind: 'custom-application', name: 'MyFoo'})
|
104
|
+
|
105
|
+
r.register(record)
|
106
|
+
end
|
96
107
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: gds-api-adapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.30
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James Stewart
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- lib/gds_api/json_client.rb
|
131
131
|
- lib/gds_api/needotron.rb
|
132
132
|
- lib/gds_api/oauth2_client.rb
|
133
|
+
- lib/gds_api/panopticon/registerer.rb
|
133
134
|
- lib/gds_api/panopticon.rb
|
134
135
|
- lib/gds_api/part_methods.rb
|
135
136
|
- lib/gds_api/publisher.rb
|
@@ -160,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
161
|
requirements:
|
161
162
|
- - ">="
|
162
163
|
- !ruby/object:Gem::Version
|
163
|
-
hash: -
|
164
|
+
hash: -1184344581881622705
|
164
165
|
segments:
|
165
166
|
- 0
|
166
167
|
version: "0"
|
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
requirements:
|
170
171
|
- - ">="
|
171
172
|
- !ruby/object:Gem::Version
|
172
|
-
hash: -
|
173
|
+
hash: -1184344581881622705
|
173
174
|
segments:
|
174
175
|
- 0
|
175
176
|
version: "0"
|