plek 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/plek.rb +75 -19
- data/lib/plek/version.rb +1 -1
- metadata +2 -2
data/lib/plek.rb
CHANGED
@@ -1,10 +1,56 @@
|
|
1
1
|
require 'plek/version'
|
2
2
|
|
3
3
|
class Plek
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
DEFAULT_PATTERN = "pattern".freeze
|
5
|
+
|
6
|
+
SERVICES = {
|
7
|
+
"staging.frontend" => "demo.alphagov.co.uk",
|
8
|
+
"staging.authentication" => "signonotron.alpha.gov.uk",
|
9
|
+
"staging.needs" => "needotron.alpha.gov.uk",
|
10
|
+
"staging.publisher" => "guides.staging.alphagov.co.uk:8080",
|
11
|
+
"staging.data" => "imminence.staging.alphagov.co.uk:8080",
|
12
|
+
"staging.arbiter" => "panopticon.staging.alphagov.co.uk:8080",
|
13
|
+
"staging.#{DEFAULT_PATTERN}" => "%s.staging.alphagov.co.uk:8080",
|
14
|
+
|
15
|
+
"development.authentication" => "signonotron.dev.gov.uk",
|
16
|
+
"development.needs" => "needotron.dev.gov.uk",
|
17
|
+
"development.data" => "imminence.dev.gov.uk",
|
18
|
+
"development.arbiter" => "panopticon.dev.gov.uk",
|
19
|
+
"development.#{DEFAULT_PATTERN}" => "%s.dev.gov.uk",
|
20
|
+
|
21
|
+
"test.authentication" => "signonotron.test.gov.uk",
|
22
|
+
"test.needs" => "needotron.test.gov.uk",
|
23
|
+
"test.data" => "imminence.test.gov.uk",
|
24
|
+
"test.arbiter" => "panopticon.test.gov.uk",
|
25
|
+
"test.#{DEFAULT_PATTERN}" => "%s.test.gov.uk",
|
26
|
+
}.freeze
|
27
|
+
|
28
|
+
PURPOSE_FOR_SERVICE = {
|
29
|
+
"need-o-tron" => "needs",
|
30
|
+
"sign-on-o-tron" => "authentication",
|
31
|
+
"imminence" => "data",
|
32
|
+
"panopticon" => "arbiter"
|
33
|
+
}.freeze
|
34
|
+
|
35
|
+
SERVICE_NAMES = %w(
|
36
|
+
panopticon
|
37
|
+
sign-on-o-tron
|
38
|
+
imminence
|
39
|
+
publisher
|
40
|
+
need-o-tron
|
41
|
+
frontend
|
42
|
+
).freeze
|
43
|
+
|
44
|
+
SERVICE_NAMES.each do |service_name|
|
45
|
+
# Backward compatibility
|
46
|
+
method_name = service_name.gsub(/[^a-z]+/, '_')
|
47
|
+
define_method method_name do
|
48
|
+
name = PURPOSE_FOR_SERVICE[service_name] || service_name
|
49
|
+
puts "Plek##{method_name} is deprecated and will be removed in an " +
|
50
|
+
"upcoming release.\nUse `Plek#find('#{name}')` instead."
|
51
|
+
find name
|
52
|
+
end
|
53
|
+
end
|
8
54
|
|
9
55
|
attr_accessor :environment
|
10
56
|
private :environment=, :environment
|
@@ -13,28 +59,38 @@ class Plek
|
|
13
59
|
self.environment = environment
|
14
60
|
end
|
15
61
|
|
62
|
+
# Find the URI for a service.
|
63
|
+
#
|
64
|
+
# Services don't map directly to applications since we may replace an
|
65
|
+
# application but retain the service.
|
66
|
+
#
|
67
|
+
# Currently we have these services:
|
68
|
+
#
|
69
|
+
# frontend: Where the public can see our output.
|
70
|
+
# authentication: Where we send staff so they can log in.
|
71
|
+
# publisher: Where we write content.
|
72
|
+
# needs: Where we record the needs that we're going to fulfill.
|
73
|
+
# data: Where our datasets live.
|
74
|
+
# arbiter: organises data shared between the applications
|
75
|
+
#
|
16
76
|
def find service
|
77
|
+
name = name_for service
|
78
|
+
host = SERVICES[service_key_for(name)]
|
79
|
+
host ||= SERVICES["#{environment}.#{DEFAULT_PATTERN}"].to_s % name
|
17
80
|
# FIXME: *Everything* should be SSL
|
18
|
-
"http://#{
|
81
|
+
"http://#{host}"
|
19
82
|
end
|
20
83
|
|
21
|
-
|
22
|
-
|
23
|
-
find service
|
24
|
-
end
|
84
|
+
def service_key_for name
|
85
|
+
"#{environment}.#{name}"
|
25
86
|
end
|
26
87
|
|
27
88
|
def name_for service
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def domain
|
37
|
-
DOMAIN[environment]
|
89
|
+
name = service.to_s.dup
|
90
|
+
name.downcase!
|
91
|
+
name.strip!
|
92
|
+
name.gsub! /[^a-z]+/, ''
|
93
|
+
name
|
38
94
|
end
|
39
95
|
|
40
96
|
def self.current
|
data/lib/plek/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-28 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Find the right hostname for each service in an environment-dependent
|
15
15
|
manner
|