notifications-ruby-client 2.5.1 → 2.6.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
  SHA1:
3
- metadata.gz: d53d8e24813e67e7e4b7f6c2c19e8c3c41bfa505
4
- data.tar.gz: e4e49ee5cd4006383706611122b84dc62746ca93
3
+ metadata.gz: 942f912e7dce40facdd4d15a7554c34366efbbfb
4
+ data.tar.gz: 7804cd65bf20d992f480e1f576cd9cab44e6b69c
5
5
  SHA512:
6
- metadata.gz: f57075249e7ea6b1518bde9d4ba7fa7def7521f6fe436a244b40b005bfe08528e248a6d9c9ceea6259e41f3417a4b0de50b6ede642ef05afd7d33720d5d78cf0
7
- data.tar.gz: 68d31589b31fb9dcb2a6fcc6fd3dfe4171387e416abfc8cb558a541efe2a5508053283531726cd9a293b16172e745166d039361cbe63ebcb6935424e2d9e0a42
6
+ metadata.gz: e1a019e8ff6e295d6f781aa956aadffdf89e2e116e1cd51dd7739427955d97949122f5d4252b538f03afb50101ad9b151a914efe3848d25933c4123a0cc20968
7
+ data.tar.gz: a75e8a79f6cda877bda9f6bf4b4d7f783c14e9d7d7a43e3f305718407e4690cb0a9e162adae3124ca0dac3dd711a74115c84a479416ab857c93c5ed678165fd5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 2.6.0
2
+
3
+ ### Changed
4
+ * The client now validates that UUIDs derived from the API key are valid and raises a helpful error message if they are not.
5
+
1
6
  ## 2.5.0
2
7
 
3
8
  ### Changed
@@ -8,6 +8,7 @@ require_relative "client/received_text_collection"
8
8
  require_relative "client/response_template"
9
9
  require_relative "client/template_collection"
10
10
  require_relative "client/template_preview"
11
+ require_relative "client/uuid_validator"
11
12
  require "forwardable"
12
13
 
13
14
  module Notifications
@@ -21,6 +21,8 @@ module Notifications
21
21
  @service_id = secret_token[secret_token.length - 73..secret_token.length - 38]
22
22
  @secret_token = secret_token[secret_token.length - 36..secret_token.length]
23
23
  @base_url = base_url || PRODUCTION_BASE_URL
24
+
25
+ validate_uuids!
24
26
  end
25
27
 
26
28
  ##
@@ -130,6 +132,17 @@ module Notifications
130
132
  }
131
133
  JWT.encode payload, @secret_token, "HS256"
132
134
  end
135
+
136
+ def validate_uuids!
137
+ contextual_message = [
138
+ "This error is probably caused by initializing the Notifications client with an invalid API key.",
139
+ "You can generate a new API key by logging into Notify and visiting the 'API integration' page:",
140
+ "https://www.notifications.service.gov.uk",
141
+ ].join("\n")
142
+
143
+ UuidValidator.validate!(@service_id, contextual_message)
144
+ UuidValidator.validate!(@secret_token, contextual_message)
145
+ end
133
146
  end
134
147
  end
135
148
  end
@@ -0,0 +1,26 @@
1
+ module Notifications
2
+ class UuidValidator
3
+ HEX = /[0-9a-f]/
4
+ REGEX = /^#{HEX}{8}-#{HEX}{4}-#{HEX}{4}-#{HEX}{4}-#{HEX}{12}$/
5
+
6
+ attr_accessor :uuid
7
+
8
+ def initialize(uuid)
9
+ self.uuid = uuid
10
+ end
11
+
12
+ def valid?
13
+ !!(uuid && uuid.match(REGEX))
14
+ end
15
+
16
+ def self.validate!(uuid, contextual_message = nil)
17
+ return if new(uuid).valid?
18
+
19
+ message = "#{uuid.inspect} is not a valid uuid"
20
+ message += "\n#{contextual_message}" if contextual_message
21
+
22
+ raise ArgumentError, message
23
+ end
24
+ end
25
+ end
26
+
@@ -9,6 +9,6 @@
9
9
 
10
10
  module Notifications
11
11
  class Client
12
- VERSION = "2.5.1".freeze
12
+ VERSION = "2.6.0".freeze
13
13
  end
14
14
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifications-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.1
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-04 00:00:00.000000000 Z
11
+ date: 2017-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jwt
@@ -148,6 +148,7 @@ files:
148
148
  - lib/notifications/client/speaker.rb
149
149
  - lib/notifications/client/template_collection.rb
150
150
  - lib/notifications/client/template_preview.rb
151
+ - lib/notifications/client/uuid_validator.rb
151
152
  - lib/notifications/client/version.rb
152
153
  - notifications-ruby-client.gemspec
153
154
  homepage: https://github.com/alphagov/notifications-ruby-client