ruby_isds 0.12.0 → 0.13.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 786df93888ace6114b9f30bd39b48ffcb2dce0f2d8b5c1af94f89ddc2033bff5
4
- data.tar.gz: 9cebb9baf35711920e1c43e3bb03233db93b1211983ccbaa472539a6801e927b
3
+ metadata.gz: 2499d07ffdb8aefc294f1de7201ef0c5fcee34d8b44575647b09db11feae1227
4
+ data.tar.gz: fb64e99eb613497520fb797e2d0896c0639a4caef968dbae09c1668845491e97
5
5
  SHA512:
6
- metadata.gz: 9b3da9d6b2692d0192c88962d23aba6d1017fca12afbe02a62cabf98719ce7a06e99d5b65bd379f1340bdf37a9052c700d7d66d38b157e9f9d50a73312f4beda
7
- data.tar.gz: 8cc6c106c7414a50a851f271e1f8f60a2d846328cfe563d11570547833a904d997cf20f82866b1ebd4f4aae43747ab44b4c4b0dc0273e4f911b7a3569b23f567
6
+ metadata.gz: abedc2bfcf4857ec5ac33936f6597d18ad24a59b1013b7c37ebe05a5fb1c5ba067d6059c8c4af0ef0bde990147622128d92a0c468efc496935720674d3ef0dec
7
+ data.tar.gz: d8dc750bbfbc8f7bf2ad59d10f7d0c7b07757dca0d649c999bac4b3a53f5760eb605ca927b4dd589e2f95c0659f9ba1cf5a5d47a87688f9d2db753a89e0b7a89
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
  .rspec_status
12
12
 
13
13
  bin/debug_console
14
+
15
+ .DS_Store
@@ -41,6 +41,8 @@ PreCommit:
41
41
 
42
42
  TrailingWhitespace:
43
43
  enabled: true
44
+ exclude:
45
+ - 'spec/**/*'
44
46
 
45
47
  BundleAudit:
46
48
  enabled: true
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_isds (0.12.0)
4
+ ruby_isds (0.13.0)
5
5
  activesupport
6
6
  nokogiri
7
7
 
@@ -136,4 +136,4 @@ DEPENDENCIES
136
136
  webmock (~> 3.0)
137
137
 
138
138
  BUNDLED WITH
139
- 1.16.4
139
+ 1.17.3
data/README.md CHANGED
@@ -22,7 +22,10 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- Before usage please add config (for rails initializer) with following:
25
+ Before usage please add config (for rails initializer) with one of supported
26
+ auth strategies:
27
+
28
+ ### Username + password
26
29
 
27
30
  ```ruby
28
31
  RubyIsds.configure do |c|
@@ -32,6 +35,19 @@ RubyIsds.configure do |c|
32
35
  c.env = :development
33
36
  end
34
37
  ```
38
+ ### Server side system certificate
39
+
40
+ ```ruby
41
+ RubyIsds.configure do |c|
42
+ c.data_box = 'data_box_id'
43
+ c.cert_file = 'spec/factories/files/certifikat.pem'
44
+ c.key_file = 'spec/factories/files/test-key.key'
45
+ c.pass_phrase = 'andrej'
46
+ c.env = :development
47
+ end
48
+ ```
49
+ here `data_box_id` if id of databox you will be accessing, you do not really
50
+ need id of databox used as point from where you access
35
51
 
36
52
  you do not have to provide `env` in setup unless you go to production, gem
37
53
  defaults to `:development` anyway...
@@ -220,6 +236,19 @@ TODO
220
236
 
221
237
  If in doubt, or my so called 'README' seems not that helpful, please refer to [ISDS provozni rad](https://www.datoveschranky.info/dulezite-informace/provozni-rad-isds)
222
238
 
239
+ #### Certificates
240
+
241
+ Just some helpfull information when you want to use certificate to access
242
+ databoxes:
243
+
244
+ How to setup and what not in ISDS: [https://www.czebox.cz/static/ISDS/help/page8.html#8_4](https://www.czebox.cz/static/ISDS/help/page8.html#8_4)
245
+
246
+ Working with DER/PEM and what not around the keys: [https://knowledge.digicert.com/solution/SO26449.html](https://knowledge.digicert.com/solution/SO26449.html)
247
+
248
+ How to convert windows pfx file exported from keychain into key you need here: [https://www.markbrilman.nl/2011/08/howto-convert-a-pfx-to-a-seperate-key-crt-file/](https://www.markbrilman.nl/2011/08/howto-convert-a-pfx-to-a-seperate-key-crt-file/)
249
+
250
+ Jus to note here, certificate accepted should be in PEM format and you have to add the private.key with the password to it.
251
+
223
252
  ## Development
224
253
 
225
254
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -41,6 +41,7 @@ require 'ruby_isds/web_services/db_search/p_d_z_info'
41
41
  require 'ruby_isds/web_services/db_search/p_d_z_send_info'
42
42
 
43
43
  require 'ruby_isds/web_services/db_access/change_isds_password'
44
+ require 'ruby_isds/web_services/db_access/get_owner_info_from_login'
44
45
 
45
46
  require 'ruby_isds/web_services/dm_info/request'
46
47
  require 'ruby_isds/web_services/dm_info/response'
@@ -1,6 +1,8 @@
1
1
  module RubyIsds
2
2
  class Configuration
3
- attr_writer :data_box, :username, :password, :env, :api_url
3
+ attr_writer :data_box, :username, :password, :env, :api_url,
4
+ :cert_file, :key_file, :pass_phrase
5
+ attr_reader :pass_phrase
4
6
 
5
7
  ALLOWED_PRODUCTION_SYNTAX = [:production, 'production'].freeze
6
8
 
@@ -9,6 +11,9 @@ module RubyIsds
9
11
  @password = nil
10
12
  @data_box = nil
11
13
  @env = nil
14
+ @cert_file = nil
15
+ @key_file = nil
16
+ @pass_phrase = nil
12
17
  end
13
18
 
14
19
  def data_box
@@ -26,6 +31,25 @@ module RubyIsds
26
31
  @password
27
32
  end
28
33
 
34
+ def cert_file
35
+ if @cert_file && (!@key_file && !@pass_phrase)
36
+ raise ConfigNotSet, 'pass_phrase and key_file'
37
+ end
38
+ return unless @cert_file
39
+ OpenSSL::X509::Certificate.new(File.read(@cert_file))
40
+ end
41
+
42
+ def key_file
43
+ return nil unless @key_file
44
+ File.read(@key_file)
45
+ end
46
+
47
+ def private_key
48
+ raise ConfigNotSet, 'pass_phrase' if @key_file && !@pass_phrase
49
+ raise ConfigNotSet, 'key_file' if !@key_file && @pass_phrase
50
+ OpenSSL::PKey::RSA.new(File.read(@key_file), @pass_phrase)
51
+ end
52
+
29
53
  ##
30
54
  # env values:
31
55
  # :development (default)
@@ -37,8 +61,13 @@ module RubyIsds
37
61
  end
38
62
 
39
63
  def api_domain
40
- return 'https://ws1.mojedatovaschranka.cz' if production?
41
- 'https://ws1.czebox.cz'
64
+ if production?
65
+ return 'https://ws1c.mojedatovaschranka.cz/cert' if @cert_file
66
+ 'https://ws1.mojedatovaschranka.cz'
67
+ else
68
+ return 'https://ws1c.czebox.cz/hspis' if @cert_file
69
+ 'https://ws1.czebox.cz'
70
+ end
42
71
  end
43
72
 
44
73
  def xml_url
@@ -10,6 +10,10 @@ module RubyIsds
10
10
  .call(options)
11
11
  end
12
12
 
13
+ def self.owner_info
14
+ ::RubyIsds::WebServices::DbAccess::GetOwnerInfoFromLogin.call
15
+ end
16
+
13
17
  def self.credit_info(options = {})
14
18
  ::RubyIsds::WebServices::DbSearch::DataBoxCreditInfo
15
19
  .call(options.merge(dbID: ::RubyIsds.configuration.data_box))
@@ -11,20 +11,33 @@ module RubyIsds
11
11
  end
12
12
 
13
13
  # rubocop:disable Metrics/AbcSize
14
+ # rubocop:disable Metrics/MethodLength
14
15
  def call
15
16
  uri = URI(full_url)
16
17
 
17
18
  request = Net::HTTP::Post.new(uri)
18
19
  default_headers.each { |k, v| request[k] = v }
19
20
  request.body = to_xml
20
- request.basic_auth RubyIsds.configuration.username, RubyIsds.configuration.password
21
21
 
22
22
  https = Net::HTTP.new(uri.hostname, uri.port)
23
23
  https.use_ssl = true
24
24
  https.ssl_version = :TLSv1_2_client
25
+ if RubyIsds.configuration.cert_file
26
+ https.verify_mode = OpenSSL::SSL::VERIFY_PEER
27
+ https.cert = RubyIsds.configuration.cert_file
28
+ https.key = RubyIsds.configuration.private_key
29
+ https.verify_depth = 5
30
+ request.basic_auth(RubyIsds.configuration.data_box, '')
31
+ else
32
+ request.basic_auth(
33
+ RubyIsds.configuration.username,
34
+ RubyIsds.configuration.password
35
+ )
36
+ end
25
37
  response = https.request(request)
26
38
  call_reponse_wrapper(response)
27
39
  end
40
+ # rubocop:enable Metrics/MethodLength
28
41
  # rubocop:enable Metrics/AbcSize
29
42
 
30
43
  def call_reponse_wrapper(response)
@@ -7,6 +7,7 @@ module RubyIsds
7
7
  end
8
8
 
9
9
  def parsed_body
10
+ raise HtmlResponseReceived, @response.inspect unless @response['Envelope'].present?
10
11
  @response['Envelope']['Body'][result_key]
11
12
  end
12
13
 
@@ -7,4 +7,12 @@ module RubyIsds
7
7
  super(msg)
8
8
  end
9
9
  end
10
+
11
+ class HtmlResponseReceived < Error
12
+ def initialize(param)
13
+ msg = 'Please check if you set credentials correctly, '\
14
+ "seems like a typo or something:\n #{param}"
15
+ super(msg)
16
+ end
17
+ end
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module RubyIsds
2
- VERSION = '0.12.0'.freeze
2
+ VERSION = '0.13.0'.freeze
3
3
  end
@@ -0,0 +1,19 @@
1
+ module RubyIsds
2
+ module WebServices
3
+ module DbAccess
4
+ class GetOwnerInfoFromLogin < ::RubyIsds::WebServices::DbSearch::Request
5
+ ATTRS = [].freeze
6
+
7
+ attr_accessor(*ATTRS)
8
+
9
+ def body(xml)
10
+ xml[:v20].GetOwnerInfoFromLogin {}
11
+ end
12
+
13
+ def api_url
14
+ '/DS/DsManage'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_isds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrej Antas
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-18 00:00:00.000000000 Z
11
+ date: 2019-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -238,6 +238,7 @@ files:
238
238
  - lib/ruby_isds/version.rb
239
239
  - lib/ruby_isds/web_services/db_access/.gitkeep
240
240
  - lib/ruby_isds/web_services/db_access/change_isds_password.rb
241
+ - lib/ruby_isds/web_services/db_access/get_owner_info_from_login.rb
241
242
  - lib/ruby_isds/web_services/db_search/check_data_box.rb
242
243
  - lib/ruby_isds/web_services/db_search/d_t_info.rb
243
244
  - lib/ruby_isds/web_services/db_search/data_box_credit_info.rb
@@ -295,8 +296,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
296
  - !ruby/object:Gem::Version
296
297
  version: '0'
297
298
  requirements: []
298
- rubyforge_project:
299
- rubygems_version: 2.7.7
299
+ rubygems_version: 3.0.2
300
300
  signing_key:
301
301
  specification_version: 4
302
302
  summary: Ruby client to access ISDS