plek 1.12.0 → 4.0.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.
Files changed (5) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +21 -7
  3. data/lib/plek.rb +37 -28
  4. data/lib/plek/version.rb +1 -1
  5. metadata +13 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e1314ffc3512610c4d3b415b260286a96e21219f
4
- data.tar.gz: 6c93d8d7b008a5c3c33e5dbfb0e04d748a086bca
2
+ SHA256:
3
+ metadata.gz: dce9ccd2cdfbd98e5f5d400b89afc268e7ac85eede91425d6999a45d8c8241e7
4
+ data.tar.gz: fb644ee1e4abefa8d133083e6dae182c4d6292cd9079a39e890a7d81a7d7846e
5
5
  SHA512:
6
- metadata.gz: 38c576ef1e98d8d05a9e74e95f0475f5ca72409b93c30b32c6d656f4df14f0c9851c64fe073e48c425576802406425157c6828a92efbf1487179169df2d2406c
7
- data.tar.gz: d93efae49515bc45665f2a57953c156f523f46cc4c2e4bf44af89a6083361f817bf977dc039c7ff68033d0bd50ede418283eb17ed47b18a644f366d76d520412
6
+ metadata.gz: 152b9b257a2d0ccc8dc1a0854e0e63ee75464173561d4b6eb781caafbb9a89abcd56ff9bb0cd31bb24f297a23a45d07f6bbd45ceb7911ff34ca88b8539391211
7
+ data.tar.gz: df7e4c1d134ede43491e7bb1e8ff0f1568bf3e9b39a64a2487fae48f800fdda709ca43f092bbaa1eca451a6e3324a7d5c33d73b6e23ea9947032d2efb6e85dd5
data/README.md CHANGED
@@ -3,14 +3,28 @@
3
3
  "Plek" is Afrikaans. It means "Location". Plek is used to generate the correct
4
4
  base URLs for internal GOV.UK services, eg:
5
5
 
6
- ```ruby
7
- Plek.find('frontend')
8
6
  ```
7
+ # on a dev machine
8
+ > Plek.find('frontend')
9
+ => "http://frontend.dev.gov.uk"
10
+ # on a production machine
11
+ > Plek.find('frontend')
12
+ => "https://frontend.publishing.service.gov.uk"
13
+ ```
14
+
15
+ This means we can use this in our code and let our environment configuration
16
+ figure out the correct hosts for us at runtime.
17
+
18
+ In an environment where we have internal hostnames and external ones an option
19
+ of `external` can be provided to determine whether an internal or external
20
+ host is returned.
9
21
 
10
- returns `http://frontend.dev.gov.uk` on a development machine and
11
- `https://frontend.production.alphagov.co.uk` on a production machine. This
12
- means we can use this in our code and let our environment configuration figure
13
- out the correct hosts for us at runtime.
22
+ ```
23
+ > Plek.find('frontend')
24
+ => "https://frontend.integration.govuk-internal.digital"
25
+ > Plek.find('frontend', external: true)
26
+ => "https://frontend.integration.publishing.service.gov.uk"
27
+ ```
14
28
 
15
29
  ## Technical documentation
16
30
 
@@ -34,7 +48,7 @@ For example, the variable for `static` would be `PLEK_SERVICE_STATIC_URI`.
34
48
 
35
49
  #### Others
36
50
 
37
- To override the development environment base domain, set `DEV_DOMAIN`. The default is `dev.gov.uk`. The environment can be set using either `RAILS_ENV` or `RACK_ENV`.
51
+ To domain is based on the environment, and defaults to 'dev.gov.uk'. The environment can be set using either `RAILS_ENV` or `RACK_ENV`.
38
52
 
39
53
  You can prepend strings to the hostnames generated using: `PLEK_HOSTNAME_PREFIX`.
40
54
 
@@ -1,5 +1,5 @@
1
- require 'plek/version'
2
- require 'uri'
1
+ require "plek/version"
2
+ require "uri"
3
3
 
4
4
  # Plek resolves service names to a corresponding base URL.
5
5
  #
@@ -17,22 +17,28 @@ class Plek
17
17
  class NoConfigurationError < StandardError; end
18
18
 
19
19
  # The fallback parent domain to use in development mode.
20
- DEV_DOMAIN = ENV['DEV_DOMAIN'] || 'dev.gov.uk'
20
+ DEV_DOMAIN = "dev.gov.uk".freeze
21
21
 
22
22
  # Domains to return http URLs for.
23
- HTTP_DOMAINS = [ DEV_DOMAIN ]
23
+ HTTP_DOMAINS = [DEV_DOMAIN].freeze
24
24
 
25
- attr_accessor :parent_domain
25
+ attr_accessor :parent_domain, :external_domain
26
26
 
27
27
  # Construct a new Plek instance.
28
28
  #
29
- # @param domain_to_use [String] Optionally override the parent domain to use.
30
- # If unspecified, this uses the +GOVUK_APP_DOMAIN+ environment variable.
29
+ # @param domain_to_use [String, nil] Optionally override the parent domain
30
+ # to use. If unspecified, this uses the +GOVUK_APP_DOMAIN+ environment
31
+ # variable.
31
32
  #
32
33
  # In development mode, this falls back to {DEV_DOMAIN} if the environment
33
34
  # variable is unset.
34
- def initialize(domain_to_use = nil)
35
+ # @param external_domain [String, nil] Optionally override the external
36
+ # domain to use. If unspecified it will fall back to using
37
+ # +GOVUK_APP_DOMAIN_EXTERNAL+ and if that is unavailable the parent domain
38
+ # will be used
39
+ def initialize(domain_to_use = nil, external_domain = nil)
35
40
  self.parent_domain = domain_to_use || env_var_or_dev_fallback("GOVUK_APP_DOMAIN", DEV_DOMAIN)
41
+ self.external_domain = external_domain || ENV["GOVUK_APP_DOMAIN_EXTERNAL"] || parent_domain
36
42
  end
37
43
 
38
44
  # Find the base URL for a service/application. This constructs the URL from
@@ -57,25 +63,34 @@ class Plek
57
63
  # @return [String] The base URL for the service.
58
64
  def find(service, options = {})
59
65
  name = name_for(service)
60
- if service_uri = defined_service_uri_for(name)
66
+ if (service_uri = defined_service_uri_for(name))
61
67
  return service_uri
62
68
  end
63
69
 
64
- host = "#{name}.#{parent_domain}"
70
+ host = "#{name}.#{options[:external] ? external_domain : parent_domain}"
65
71
 
66
- if host_prefix = ENV['PLEK_HOSTNAME_PREFIX']
72
+ if (host_prefix = ENV["PLEK_HOSTNAME_PREFIX"])
67
73
  host = "#{host_prefix}#{host}"
68
74
  end
69
75
 
70
76
  if options[:scheme_relative]
71
- "//#{host}"
72
- elsif options[:force_http] or HTTP_DOMAINS.include?(parent_domain)
73
- "http://#{host}"
77
+ "//#{host}".freeze
78
+ elsif options[:force_http] || HTTP_DOMAINS.include?(parent_domain)
79
+ "http://#{host}".freeze
74
80
  else
75
- "https://#{host}"
81
+ "https://#{host}".freeze
76
82
  end
77
83
  end
78
84
 
85
+ # Find the external URL for a service/application.
86
+ #
87
+ # @param service [String] the name of the service to lookup. This should be
88
+ # the hostname of the service.
89
+ # @param options [Hash] see the documentation for find.
90
+ def external_url_for(service, options = {})
91
+ find(service, options.merge(external: true))
92
+ end
93
+
79
94
  # Find the base URL for a service/application, and parse as a URI object.
80
95
  # This wraps #find and returns the parsed result.
81
96
  #
@@ -92,13 +107,6 @@ class Plek
92
107
  env_var_or_dev_fallback("GOVUK_ASSET_ROOT") { find("static") }
93
108
  end
94
109
 
95
- # Find the asset host used to serve assets to the public
96
- #
97
- # @return [String] The public-facing asset base URL
98
- def public_asset_host
99
- env_var_or_dev_fallback("GOVUK_ASSET_HOST") { find("static") }
100
- end
101
-
102
110
  # Find the base URL for the public website frontend.
103
111
  #
104
112
  # @return [String] The website base URL.
@@ -125,7 +133,7 @@ class Plek
125
133
  name = service.to_s.dup
126
134
  name.downcase!
127
135
  name.strip!
128
- name.gsub!(/[^a-z\.-]+/, '')
136
+ name.gsub!(/[^a-z\.-]+/, "")
129
137
  name
130
138
  end
131
139
 
@@ -149,10 +157,10 @@ class Plek
149
157
  end
150
158
  end
151
159
 
152
- private
160
+ private
153
161
 
154
162
  def env_var_or_dev_fallback(var_name, fallback_str = nil)
155
- if var = ENV[var_name]
163
+ if (var = ENV[var_name])
156
164
  var
157
165
  elsif ENV["RAILS_ENV"] == "production" || ENV["RACK_ENV"] == "production"
158
166
  raise(NoConfigurationError, "Expected #{var_name} to be set. Perhaps you should run your task through govuk_setenv <appname>?")
@@ -164,12 +172,13 @@ class Plek
164
172
  end
165
173
 
166
174
  def defined_service_uri_for(service)
167
- service_name = service.upcase.gsub(/-/,'_')
175
+ service_name = service.upcase.gsub(/-/, "_")
168
176
  var_name = "PLEK_SERVICE_#{service_name}_URI"
169
177
 
170
- if (uri = ENV[var_name] and ! uri.empty?)
178
+ if (uri = ENV[var_name]) && !uri.empty?
171
179
  return uri
172
180
  end
173
- return nil
181
+
182
+ nil
174
183
  end
175
184
  end
@@ -1,3 +1,3 @@
1
1
  class Plek
2
- VERSION = '1.12.0'
2
+ VERSION = "4.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plek
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Craig R Webster
7
+ - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-04 00:00:00.000000000 Z
11
+ date: 2020-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: climate_control
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,21 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: gem_publisher
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.1.1
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.1.1
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: minitest
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: climate_control
56
+ name: rubocop-govuk
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -69,7 +69,7 @@ dependencies:
69
69
  description: Find the right hostname for each service in an environment-dependent
70
70
  manner
71
71
  email:
72
- - craig@barkingiguana.com
72
+ - govuk-dev@digital.cabinet-office.gov.uk
73
73
  executables: []
74
74
  extensions: []
75
75
  extra_rdoc_files: []
@@ -97,8 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.4.5.1
100
+ rubygems_version: 3.0.3
102
101
  signing_key:
103
102
  specification_version: 4
104
103
  summary: Locations for services