govuk_app_config 2.8.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9fccd65df32419e21a65fae91568840f4c7c6b111d2386ffc633e940352d3ad3
4
- data.tar.gz: 613f34451cdb152bf35cfe1f5ae300c6ddf64931cf182aa36dfe486202514f36
3
+ metadata.gz: 68431d222e7798dd3027131ef5d05ea7cfab1f7df54d5e06274f2de19f4e51ea
4
+ data.tar.gz: 6c5273bd18e606f6269279d547e91630574d61dc7a1151bfbbecd55f3f38d371
5
5
  SHA512:
6
- metadata.gz: 0dc8c194c93c515a222f3256f9611ddeb621785776b4c637f63adf586b29d978d373d29dd781eec7b6ae7538dd511ff96c66c5dc885454f6495146a59397ba1e
7
- data.tar.gz: 528cfb7a65d10637edb6a5b149ad9cff2b33851e5de7d1c1c858c201256d679064fcaf73016bf946017a69a26c98cb7851d5cd83c4b4484bc8a9f9b0b47debf1
6
+ metadata.gz: '06387b0c49fe60c29728fdda8a8f3bfe529c9b8db2b87ef795b20dfb2ef157667102768d496a7cb1ccad4425265051075f9886d9e155632bb68c47626480c882'
7
+ data.tar.gz: 4ec51524d66f98be80b779d28ec65d0355b721e2fd794c03f4c61a573371c800e46f6d7c6ee514dd080430763803f7396bcd37c0e4bd7e57d33d886f6ae59980
data/CHANGELOG.md CHANGED
@@ -1,6 +1,25 @@
1
+ # 3.0.0
2
+
3
+ * BREAKING: Implement RFC 141 - remove unsuitable healthchecks and return a 500 on healthcheck failure ([#193](https://github.com/alphagov/govuk_app_config/pull/193))
4
+
5
+ # 2.10.0
6
+ * Allow LUX domain on img-src policy ([#191](https://github.com/alphagov/govuk_app_config/pull/191))
7
+
8
+ # 2.9.1
9
+
10
+ * Fixes bug in GovukI18n introduced in the last version ([#189](https://github.com/alphagov/govuk_app_config/pull/189))
11
+
12
+ # 2.9.0
13
+
14
+ * Add GovukI18n module with custom plural rules ([#187](https://github.com/alphagov/govuk_app_config/pull/187))
15
+
16
+ # 2.8.4
17
+
18
+ * Ensure Redis healthcheck avoids potential race condition ([#185](https://github.com/alphagov/govuk_app_config/pull/185))
19
+
1
20
  # 2.8.3
2
21
 
3
- * Add new Redis healthcheck and relevant tests (https://github.com/alphagov/govuk_app_config/pull/183)
22
+ * Add new Redis healthcheck and relevant tests ([#183](https://github.com/alphagov/govuk_app_config/pull/183))
4
23
 
5
24
  # 2.8.2
6
25
 
data/README.md CHANGED
@@ -162,6 +162,10 @@ app with the following content:
162
162
  GovukContentSecurityPolicy.configure
163
163
  ```
164
164
 
165
+ ## i18n rules
166
+
167
+ Some frontend apps support languages that are not defined in the i18n gem. This provides them with our own custom rules for these languages.
168
+
165
169
  ## License
166
170
 
167
171
  [MIT License](LICENSE.md)
@@ -3,6 +3,7 @@ require "govuk_app_config/govuk_statsd"
3
3
  require "govuk_app_config/govuk_error"
4
4
  require "govuk_app_config/govuk_error/configure"
5
5
  require "govuk_app_config/govuk_healthcheck"
6
+ require "govuk_app_config/govuk_i18n"
6
7
  # This require is deprecated and should be removed on next major version bump
7
8
  # and should be required by applications directly.
8
9
  require "govuk_app_config/govuk_unicorn"
@@ -32,7 +32,10 @@ module GovukContentSecurityPolicy
32
32
  *GOVUK_DOMAINS,
33
33
  *GOOGLE_ANALYTICS_DOMAINS, # Tracking pixels
34
34
  # Some content still links to an old domain we used to use
35
- "assets.digital.cabinet-office.gov.uk"
35
+ "assets.digital.cabinet-office.gov.uk",
36
+ # Allow images to be loaded for Speedcurve's LUX - used for
37
+ # getting real user metrics on GOV.UK
38
+ "lux.speedcurve.com"
36
39
 
37
40
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
38
41
  policy.script_src :self,
@@ -4,19 +4,16 @@ require "govuk_app_config/govuk_healthcheck/mongoid"
4
4
  require "govuk_app_config/govuk_healthcheck/rails_cache"
5
5
  require "govuk_app_config/govuk_healthcheck/redis"
6
6
  require "govuk_app_config/govuk_healthcheck/sidekiq_redis"
7
- require "govuk_app_config/govuk_healthcheck/threshold_check"
8
- require "govuk_app_config/govuk_healthcheck/sidekiq_queue_check"
9
- require "govuk_app_config/govuk_healthcheck/sidekiq_queue_latency_check"
10
- require "govuk_app_config/govuk_healthcheck/sidekiq_retry_size_check"
11
7
  require "json"
12
8
 
13
9
  module GovukHealthcheck
14
10
  def self.rack_response(*checks)
15
11
  proc do
12
+ checkup = healthcheck(checks)
16
13
  [
17
- 200,
14
+ checkup[:status] == :ok ? 200 : 500,
18
15
  { "Content-Type" => "application/json" },
19
- [JSON.dump(healthcheck(checks))],
16
+ [JSON.dump(checkup)],
20
17
  ]
21
18
  end
22
19
  end
@@ -1,15 +1,19 @@
1
+ require "securerandom"
2
+
1
3
  module GovukHealthcheck
2
4
  class Redis
3
5
  def name
4
- :redis
6
+ :redis_connectivity
5
7
  end
6
8
 
7
9
  def status
8
10
  client = ::Redis.new
9
11
 
10
- client.set("healthcheck", "val")
11
- client.get("healthcheck")
12
- client.del("healthcheck")
12
+ key = "healthcheck-#{SecureRandom.hex}"
13
+
14
+ client.set(key, "val")
15
+ client.get(key)
16
+ client.del(key)
13
17
 
14
18
  client.close
15
19
 
@@ -0,0 +1,38 @@
1
+ module GovukI18n
2
+ def self.plurals
3
+ {
4
+ # Dari - this isn't an iso code. Probably should be 'prs' as per ISO 639-3.
5
+ dr: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
6
+ # Latin America and Caribbean Spanish
7
+ "es-419": { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
8
+ # Scottish Gaelic
9
+ gd: { i18n: { plural: { keys: %i[one two few other],
10
+ rule:
11
+ lambda do |n|
12
+ if [1, 11].include?(n)
13
+ :one
14
+ elsif [2, 12].include?(n)
15
+ :two
16
+ elsif [3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19].include?(n)
17
+ :few
18
+ else
19
+ :other
20
+ end
21
+ end } } },
22
+ # Armenian
23
+ hy: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
24
+ # Kazakh
25
+ kk: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
26
+ # Punjabi Shahmukhi
27
+ "pa-pk": { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
28
+ # Sinhalese
29
+ si: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
30
+ # Uzbek
31
+ uz: { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
32
+ # Chinese Hong Kong
33
+ "zh-hk" => { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
34
+ # Chinese Taiwan
35
+ "zh-tw" => { i18n: { plural: { keys: %i[one other], rule: ->(n) { n == 1 ? :one : :other } } } },
36
+ }
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "2.8.3".freeze
2
+ VERSION = "3.0.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.3
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-13 00:00:00.000000000 Z
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstasher
@@ -237,11 +237,8 @@ files:
237
237
  - lib/govuk_app_config/govuk_healthcheck/mongoid.rb
238
238
  - lib/govuk_app_config/govuk_healthcheck/rails_cache.rb
239
239
  - lib/govuk_app_config/govuk_healthcheck/redis.rb
240
- - lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_check.rb
241
- - lib/govuk_app_config/govuk_healthcheck/sidekiq_queue_latency_check.rb
242
240
  - lib/govuk_app_config/govuk_healthcheck/sidekiq_redis.rb
243
- - lib/govuk_app_config/govuk_healthcheck/sidekiq_retry_size_check.rb
244
- - lib/govuk_app_config/govuk_healthcheck/threshold_check.rb
241
+ - lib/govuk_app_config/govuk_i18n.rb
245
242
  - lib/govuk_app_config/govuk_logging.rb
246
243
  - lib/govuk_app_config/govuk_statsd.rb
247
244
  - lib/govuk_app_config/govuk_unicorn.rb
@@ -1,62 +0,0 @@
1
- module GovukHealthcheck
2
- class SidekiqQueueCheck
3
- def status
4
- queues.each do |name, value|
5
- if value >= critical_threshold(queue: name)
6
- return :critical
7
- elsif value >= warning_threshold(queue: name)
8
- return :warning
9
- end
10
- end
11
-
12
- :ok
13
- end
14
-
15
- def message
16
- messages = queues.map do |name, value|
17
- critical = critical_threshold(queue: name)
18
- warning = warning_threshold(queue: name)
19
-
20
- if value >= critical
21
- "#{name} (#{value}) is above the critical threshold (#{critical})"
22
- elsif value >= warning
23
- "#{name} (#{value}) is above the warning threshold (#{warning})"
24
- end
25
- end
26
-
27
- messages = messages.compact
28
-
29
- if messages.empty?
30
- "all queues are below the critical and warning thresholds"
31
- else
32
- messages.join("\n")
33
- end
34
- end
35
-
36
- def details
37
- {
38
- queues: queues.each_with_object({}) do |(name, value), hash|
39
- hash[name] = {
40
- value: value,
41
- thresholds: {
42
- critical: critical_threshold(queue: name),
43
- warning: warning_threshold(queue: name),
44
- }.reject { |_, val| val.to_f.infinite? || val.to_f.nan? },
45
- }
46
- end,
47
- }
48
- end
49
-
50
- def queues
51
- raise "This method must be overriden to be a hash of queue names and data."
52
- end
53
-
54
- def critical_threshold(queue:) # rubocop:disable Lint/UnusedMethodArgument
55
- raise "This method must be overriden to be the critical threshold."
56
- end
57
-
58
- def warning_threshold(queue:) # rubocop:disable Lint/UnusedMethodArgument
59
- raise "This method must be overriden to be the warning threshold."
60
- end
61
- end
62
- end
@@ -1,13 +0,0 @@
1
- module GovukHealthcheck
2
- class SidekiqQueueLatencyCheck < SidekiqQueueCheck
3
- def name
4
- :sidekiq_queue_latency
5
- end
6
-
7
- def queues
8
- @queues ||= Sidekiq::Stats.new.queues.keys.each_with_object({}) do |name, hash|
9
- hash[name] = Sidekiq::Queue.new(name).latency
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- module GovukHealthcheck
2
- class SidekiqRetrySizeCheck < ThresholdCheck
3
- def name
4
- :sidekiq_retry_size
5
- end
6
-
7
- def value
8
- Sidekiq::Stats.new.retry_size
9
- end
10
- end
11
- end
@@ -1,50 +0,0 @@
1
- module GovukHealthcheck
2
- class ThresholdCheck
3
- def status
4
- if value >= critical_threshold
5
- :critical
6
- elsif value >= warning_threshold
7
- :warning
8
- else
9
- :ok
10
- end
11
- end
12
-
13
- def message
14
- if value >= critical_threshold
15
- "#{value} is above the critical threshold (#{critical_threshold})"
16
- elsif value >= warning_threshold
17
- "#{value} is above the warning threshold (#{warning_threshold})"
18
- else
19
- "#{value} is below the critical and warning thresholds"
20
- end
21
- end
22
-
23
- def details
24
- {
25
- value: value,
26
- total: total,
27
- thresholds: {
28
- critical: critical_threshold,
29
- warning: warning_threshold,
30
- },
31
- }
32
- end
33
-
34
- def value
35
- raise "This method must be overridden to be the check value."
36
- end
37
-
38
- def total
39
- nil # This method can be overriden to provide the total for the check.
40
- end
41
-
42
- def critical_threshold
43
- raise "This method must be overriden to be the critical threshold."
44
- end
45
-
46
- def warning_threshold
47
- raise "This method must be overriden to be the warning threshold."
48
- end
49
- end
50
- end