kono_epp_client 0.1.1 → 2.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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/Makefile +13 -0
  4. data/README.md +20 -3
  5. data/kono_epp_client.gemspec +4 -1
  6. data/lib/kono_epp_client/VERSION +1 -1
  7. data/lib/kono_epp_client/commands/check_contacts.rb +19 -0
  8. data/lib/{epp/epp_command/kono_epp_check_domains.rb → kono_epp_client/commands/check_domains.rb} +3 -1
  9. data/lib/kono_epp_client/commands/command.rb +15 -0
  10. data/lib/kono_epp_client/commands/create_contact.rb +89 -0
  11. data/lib/kono_epp_client/commands/create_domain.rb +56 -0
  12. data/lib/kono_epp_client/commands/delete_contact.rb +17 -0
  13. data/lib/kono_epp_client/commands/delete_domain.rb +16 -0
  14. data/lib/kono_epp_client/commands/hello.rb +15 -0
  15. data/lib/kono_epp_client/commands/info_contact.rb +17 -0
  16. data/lib/kono_epp_client/commands/info_domain.rb +16 -0
  17. data/lib/kono_epp_client/commands/login.rb +84 -0
  18. data/lib/kono_epp_client/commands/logout.rb +12 -0
  19. data/lib/kono_epp_client/commands/poll.rb +18 -0
  20. data/lib/kono_epp_client/commands/transfer_domain.rb +38 -0
  21. data/lib/kono_epp_client/commands/update_contact.rb +116 -0
  22. data/lib/kono_epp_client/commands/update_domain.rb +117 -0
  23. data/lib/kono_epp_client/dns_sec/add.rb +13 -0
  24. data/lib/kono_epp_client/dns_sec/ds_data.rb +65 -0
  25. data/lib/kono_epp_client/dns_sec/rem.rb +14 -0
  26. data/lib/kono_epp_client/dns_sec/rem_all.rb +10 -0
  27. data/lib/kono_epp_client/exceptions/error_response.rb +19 -0
  28. data/lib/kono_epp_client/exceptions.rb +15 -0
  29. data/lib/kono_epp_client/requires_parameters.rb +16 -0
  30. data/lib/{epp → kono_epp_client}/server.rb +63 -55
  31. data/lib/kono_epp_client.rb +4 -16
  32. data/spec/eager_load_spec.rb +6 -0
  33. data/spec/factories/ds_data.rb +12 -0
  34. data/spec/fixtures/dns_sec/add.xml +14 -0
  35. data/spec/fixtures/dns_sec/ds_data.xml +6 -0
  36. data/spec/fixtures/dns_sec/rem.xml +14 -0
  37. data/spec/fixtures/dns_sec/rem_all.xml +3 -0
  38. data/spec/fixtures/login_response.xml +23 -0
  39. data/spec/fixtures/login_response_for_dnssec.xml +25 -0
  40. data/spec/fixtures/snapshots/kono_epp_client/commands/create_domain/_create_with_ds_data_build_extensions.xml.snap +39 -0
  41. data/spec/fixtures/snapshots/kono_epp_client/commands/login/_login.xml.snap +7 -0
  42. data/spec/fixtures/snapshots/kono_epp_client/commands/login/_tags_extensions_with_value_xml.xml.snap +14 -0
  43. data/spec/fixtures/snapshots/kono_epp_client/commands/login/_tags_lang_with_value_xml.xml.snap +11 -0
  44. data/spec/fixtures/snapshots/kono_epp_client/commands/login/_tags_new_password_with_value_xml.xml.snap +9 -0
  45. data/spec/fixtures/snapshots/kono_epp_client/commands/login/_tags_services_with_value_xml.xml.snap +12 -0
  46. data/spec/fixtures/snapshots/kono_epp_client/commands/login/_tags_version_with_value_xml.xml.snap +11 -0
  47. data/spec/fixtures/snapshots/kono_epp_client/commands/login/_with_id_and_password_login.xml.snap +10 -0
  48. data/spec/fixtures/snapshots/kono_epp_client/commands/update_domain/_update_DnsSec_build_extensions.xml.snap +30 -0
  49. data/spec/{epp/epp_command/kono_epp_check_contacts_spec.rb → lib/commands/check_contacts_spec.rb} +1 -1
  50. data/spec/{epp/epp_command/kono_epp_check_domains_spec.rb → lib/commands/check_domains_spec.rb} +1 -1
  51. data/spec/{epp/kono_epp_command_spec.rb → lib/commands/command_spec.rb} +2 -2
  52. data/spec/lib/commands/create_domain_spec.rb +50 -0
  53. data/spec/lib/commands/login_spec.rb +87 -0
  54. data/spec/{epp/epp_command/kono_epp_transfer_domain_spec.rb → lib/commands/transfer_domain_spec.rb} +1 -1
  55. data/spec/{epp/epp_command/kono_epp_update_domain_spec.rb → lib/commands/update_domain_spec.rb} +20 -4
  56. data/spec/lib/dns_sec/add_spec.rb +14 -0
  57. data/spec/lib/dns_sec/ds_data_spec.rb +43 -0
  58. data/spec/lib/dns_sec/rem_all_spec.rb +11 -0
  59. data/spec/lib/dns_sec/rem_spec.rb +14 -0
  60. data/spec/lib/server_spec.rb +304 -0
  61. data/spec/spec_helper.rb +6 -2
  62. data/spec/support/context.rb +1 -1
  63. data/spec/support/factory_bot.rb +8 -0
  64. data/spec/support/fixtures.rb +16 -0
  65. data/spec/support/matchers.rb +14 -0
  66. data/spec/support/parametric.rb +1 -0
  67. data/spec/support/snapshot.rb +12 -2
  68. metadata +157 -60
  69. data/lib/epp/epp_command/check_contacts.rb +0 -17
  70. data/lib/epp/epp_command/create_contact.rb +0 -87
  71. data/lib/epp/epp_command/create_domain.rb +0 -44
  72. data/lib/epp/epp_command/delete_contact.rb +0 -15
  73. data/lib/epp/epp_command/delete_domain.rb +0 -14
  74. data/lib/epp/epp_command/hello.rb +0 -13
  75. data/lib/epp/epp_command/info_contact.rb +0 -15
  76. data/lib/epp/epp_command/info_domain.rb +0 -14
  77. data/lib/epp/epp_command/login.rb +0 -79
  78. data/lib/epp/epp_command/logout.rb +0 -10
  79. data/lib/epp/epp_command/poll.rb +0 -16
  80. data/lib/epp/epp_command/transfer_domain.rb +0 -36
  81. data/lib/epp/epp_command/update_contact.rb +0 -115
  82. data/lib/epp/epp_command/update_domain.rb +0 -104
  83. data/lib/epp/epp_command.rb +0 -15
  84. data/lib/epp/exceptions.rb +0 -28
  85. data/lib/epp/transport/tcp.rb +0 -93
  86. data/lib/require_parameters.rb +0 -14
  87. data/spec/epp/epp_command/kono_epp_create_domain_spec.rb +0 -37
  88. data/spec/epp/server_spec.rb +0 -69
  89. /data/lib/{epp/transport/http.rb → kono_epp_client/transport/http_transport.rb} +0 -0
  90. /data/lib/{epp → kono_epp_client}/transport.rb +0 -0
  91. /data/spec/fixtures/snapshots/{kono_epp_check_contacts → kono_epp_client/commands/check_contacts}/_construct.xml.snap +0 -0
  92. /data/spec/fixtures/snapshots/{kono_epp_check_domains → kono_epp_client/commands/check_domains}/_construct.xml.snap +0 -0
  93. /data/spec/fixtures/snapshots/{kono_epp_create_domain → kono_epp_client/commands/create_domain}/_create.xml.snap +0 -0
  94. /data/spec/fixtures/snapshots/{kono_epp_transfer_domain → kono_epp_client/commands/transfer_domain}/_con_extension_construct.xml.snap +0 -0
  95. /data/spec/fixtures/snapshots/{kono_epp_transfer_domain → kono_epp_client/commands/transfer_domain}/_construct.xml.snap +0 -0
  96. /data/spec/fixtures/snapshots/{kono_epp_update_domain → kono_epp_client/commands/update_domain}/_restore_esiste_l'estensione_di_restore.xml.snap +0 -0
  97. /data/spec/fixtures/snapshots/{kono_epp_update_domain → kono_epp_client/commands/update_domain}/_update_auth_info_cambia_AUTH_INFO.xml.snap +0 -0
  98. /data/spec/fixtures/snapshots/{kono_epp_update_domain → kono_epp_client/commands/update_domain}/_update_auth_info_con_nuovo_registrant_cambia_REGISTRANT.xml.snap +0 -0
  99. /data/spec/fixtures/snapshots/{kono_epp_update_domain → kono_epp_client/commands/update_domain}/_update_contacts_cambia_ADMIN_TECH.xml.snap +0 -0
  100. /data/spec/fixtures/snapshots/{kono_epp_update_domain → kono_epp_client/commands/update_domain}/_update_nameservers_aggiunge_e_rimuove_ns.xml.snap +0 -0
  101. /data/spec/fixtures/snapshots/{kono_epp_update_domain → kono_epp_client/commands/update_domain}/_update_status_cambia_status.xml.snap +0 -0
@@ -0,0 +1,116 @@
1
+ module KonoEppClient::Commands
2
+ class UpdateContact < Command
3
+
4
+ # TODO: Add and remove fields
5
+ def initialize(options)
6
+ super(nil, nil)
7
+
8
+ command = root.elements['command']
9
+
10
+ update = command.add_element "update"
11
+
12
+ contact_update = update.add_element("contact:update", {"xmlns:contact" => "urn:ietf:params:xml:ns:contact-1.0",
13
+ "xsi:schemaLocation" => "urn:ietf:params:xml:ns:contact-1.0 contact-1.0.xsd"})
14
+
15
+ id = contact_update.add_element "contact:id"
16
+ id.text = options[:id]
17
+
18
+ contact_chg = contact_update.add_element "contact:chg"
19
+
20
+ unless options[:name].blank? \
21
+ and options[:organization].blank? \
22
+ and options[:address].blank? \
23
+ and options[:city].blank? \
24
+ and options[:state].blank? \
25
+ and options[:postal_code].blank? \
26
+ and options[:country].blank?
27
+
28
+ postal_info = contact_chg.add_element "contact:postalInfo", {"type" => "loc"}
29
+
30
+ unless options[:name].blank?
31
+ name = postal_info.add_element "contact:name"
32
+ name.text = options[:name]
33
+ end
34
+
35
+ unless options[:organization].blank?
36
+ organization = postal_info.add_element "contact:org"
37
+ organization.text = options[:organization]
38
+ end
39
+
40
+ # NOTE: city and country are REQUIRED
41
+ unless options[:address].blank? \
42
+ and options[:city].blank? \
43
+ and options[:state].blank? \
44
+ and options[:postal_code].blank? \
45
+ and options[:country].blank?
46
+
47
+ addr = postal_info.add_element "contact:addr"
48
+
49
+ unless options[:address].blank?
50
+ street = addr.add_element "contact:street"
51
+ street.text = options[:address]
52
+ end
53
+
54
+ city = addr.add_element "contact:city"
55
+ city.text = options[:city]
56
+
57
+ unless options[:state].blank?
58
+ state = addr.add_element "contact:sp"
59
+ state.text = options[:state]
60
+ end
61
+
62
+ unless options[:postal_code].blank?
63
+ postal_code = addr.add_element "contact:pc"
64
+ postal_code.text = options[:postal_code]
65
+ end
66
+
67
+ country_code = addr.add_element "contact:cc"
68
+ country_code.text = options[:country]
69
+ end
70
+ end
71
+
72
+ if options[:voice]
73
+ voice = contact_chg.add_element "contact:voice"
74
+ voice.text = options[:voice]
75
+ end
76
+
77
+ if options[:fax]
78
+ fax = contact_chg.add_element "contact:fax"
79
+ fax.text = options[:fax]
80
+ end
81
+
82
+ if options[:email]
83
+ email = contact_chg.add_element "contact:email"
84
+ email.text = options[:email]
85
+ end
86
+
87
+ unless not options.has_key?(:publish) \
88
+ and options[:nationality].blank? \
89
+ and options[:entity_type].blank? \
90
+ and options[:reg_code].blank?
91
+
92
+ # FIXME
93
+ extension = command.add_element "extension"
94
+ extension_update = extension.add_element "extcon:update", {"xmlns:extcon" => 'http://www.nic.it/ITNIC-EPP/extcon-1.0',
95
+ "xsi:schemaLocation" => 'http://www.nic.it/ITNIC-EPP/extcon-1.0 extcon-1.0.xsd'}
96
+ if options.has_key?(:publish)
97
+ publish = extension_update.add_element "extcon:consentForPublishing"
98
+ publish.text = options[:publish]
99
+ end
100
+
101
+ if options[:becomes_registrant]
102
+ extcon_registrant = extension_update.add_element "extcon:registrant"
103
+
104
+ extcon_nationality = extcon_registrant.add_element "extcon:nationalityCode"
105
+ extcon_nationality.text = options[:nationality]
106
+
107
+ extcon_entity = extcon_registrant.add_element "extcon:entityType"
108
+ extcon_entity.text = options[:entity_type]
109
+
110
+ extcon_regcode = extcon_registrant.add_element "extcon:regCode"
111
+ extcon_regcode.text = options[:reg_code]
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,117 @@
1
+ module KonoEppClient::Commands
2
+ class UpdateDomain < Command
3
+ def initialize(options)
4
+ super(nil, nil)
5
+
6
+ command = root.elements['command']
7
+ update = command.add_element("update")
8
+
9
+ domain_update = update.add_element("domain:update", {"xmlns:domain" => "urn:ietf:params:xml:ns:domain-1.0",
10
+ "xsi:schemaLocation" => "urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"})
11
+
12
+ name = domain_update.add_element "domain:name"
13
+ name.text = options[:name]
14
+
15
+ if not options[:add_nameservers].blank? or options[:add_admin] or options[:add_tech] or options[:add_status]
16
+ # <domain:add>
17
+ domain_add = domain_update.add_element "domain:add"
18
+
19
+ unless options[:add_nameservers].blank?
20
+ domain_add_ns = domain_add.add_element "domain:ns"
21
+
22
+ options[:add_nameservers].each do |ns|
23
+ host_attr = domain_add_ns.add_element "domain:hostAttr"
24
+ host_name = host_attr.add_element "domain:hostName"
25
+
26
+ host_name.text = ns[0]
27
+
28
+ # FIXME IPv6
29
+ if ns[1]
30
+ host_addr = host_attr.add_element "domain:hostAddr", {"ip" => "v4"}
31
+ host_addr.text = ns[1]
32
+ end
33
+ end
34
+ end
35
+
36
+ if options[:add_admin]
37
+ domain_contact = domain_add.add_element "domain:contact", {"type" => "admin"}
38
+ domain_contact.text = options[:add_admin]
39
+ end
40
+
41
+ if options[:add_status]
42
+ domain_add.add_element "domain:status", {"s" => options[:add_status]}
43
+ end
44
+
45
+ if options[:add_tech]
46
+ domain_contact = domain_add.add_element "domain:contact", {"type" => "tech"}
47
+ domain_contact.text = options[:add_tech]
48
+ end
49
+ end
50
+
51
+ if not options[:remove_nameservers].blank? or options[:remove_admin] or options[:remove_tech] or options[:remove_status]
52
+ # <domain:rem>
53
+ domain_remove = domain_update.add_element "domain:rem"
54
+
55
+ unless options[:remove_nameservers].blank?
56
+ domain_remove_ns = domain_remove.add_element "domain:ns"
57
+
58
+ options[:remove_nameservers].each do |ns_name|
59
+ host_attr = domain_remove_ns.add_element "domain:hostAttr"
60
+ host_name = host_attr.add_element "domain:hostName"
61
+
62
+ host_name.text = ns_name
63
+ end
64
+ end
65
+
66
+ if options[:remove_admin]
67
+ domain_contact = domain_remove.add_element "domain:contact", {"type" => "admin"}
68
+ domain_contact.text = options[:remove_admin]
69
+ end
70
+
71
+ if options[:remove_status]
72
+ domain_remove.add_element "domain:status", {"s" => options[:remove_status]}
73
+ end
74
+
75
+ if options[:remove_tech]
76
+ domain_contact = domain_remove.add_element "domain:contact", {"type" => "tech"}
77
+ domain_contact.text = options[:remove_tech]
78
+ end
79
+ end
80
+
81
+ # <domain:chg>
82
+ if options[:auth_info]
83
+ domain_change = domain_update.add_element "domain:chg"
84
+
85
+ if options[:registrant]
86
+ domain_registrant = domain_change.add_element "domain:registrant"
87
+ domain_registrant.text = options[:registrant]
88
+ end
89
+
90
+ domain_authinfo = domain_change.add_element "domain:authInfo"
91
+
92
+ domain_pw = domain_authinfo.add_element "domain:pw"
93
+ domain_pw.text = options[:auth_info]
94
+ end
95
+
96
+ if options[:restore]
97
+ command.add_element("extension").tap do |ext|
98
+ ext.add_element("rgp:update", {"xmlns:rgp" => "urn:ietf:params:xml:ns:rgp-1.0",
99
+ "xsi:schemaLocation" => "urn:ietf:params:xml:ns:rgp-1.0 rgp-1.0.xsd"}).
100
+ add_element("rgp:restore", {"op" => "request"})
101
+ end
102
+ end
103
+ # TODO: Registrant
104
+
105
+ if options[:dns_sec_data] and options[:dns_sec_data].any?
106
+ extension = command.elements['extension'] || command.add_element("extension")
107
+
108
+ create_list = extension.add_element("secDNS:update", {"xmlns:secDNS"=> "urn:ietf:params:xml:ns:secDNS-1.1"})
109
+
110
+ options[:dns_sec_data].each do |d|
111
+ create_list.add_element(d)
112
+ end
113
+ end
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KonoEppClient::DnsSec
4
+ class Add < REXML::Element
5
+ def initialize(*ds_datas)
6
+ super("secDNS:add")
7
+
8
+ ds_datas.each do |ds_data|
9
+ self.add_element ds_data
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+ module KonoEppClient::DnsSec
3
+ class DsData < REXML::Element
4
+
5
+ attr_accessor :key_tag, :alg, :digest_type, :digest
6
+
7
+ ALG = {
8
+ :dsa_sha_1 => 3,
9
+ :rsa_sha_1 => 5,
10
+ :dsa_nsec_3_sha_1 => 6,
11
+ :rsasha_1_nsec_3_sha_1 => 7,
12
+ :rsa_sha_256 => 8,
13
+ :rsa_sha_512 => 10,
14
+ :ecc_gost => 12,
15
+ :ecdsap_256_sha_256 => 13,
16
+ :ecdsap_384_sha_384 => 14
17
+ }.freeze
18
+ DIGEST_TYPES = {
19
+ :sha_1 => 1,
20
+ :sha_256 => 2,
21
+ :gost_r_34_11_94 => 3,
22
+ :sha_384 => 4
23
+ }.freeze
24
+
25
+ ##
26
+ # Inizializzazione di un DsData
27
+ #
28
+ # @param [Integer] key_tag 0<=X<=65535
29
+ # @param [Symbol] alg
30
+ # :dsa_sha_1 => 3 (DSA/SHA-1)
31
+ # :rsa_sha_1 => 5 (RSA/SHA-1)
32
+ # :dsa_nsec_3_sha_1 => 6 (DSA-NSEC3-SHA1)
33
+ # :rsasha_1_nsec_3_sha_1 => 7 (RSASHA1-NSEC3-SHA1)
34
+ # :rsa_sha_256 => 8 (RSA/SHA-256)
35
+ # :rsa_sha_512 => 10 (RSA/SHA-512)
36
+ # :ecc_gost => 12 (ECC-GOST)
37
+ # :ecdsap_256_sha_256 => 13 (ECDSAP256SHA256)
38
+ # :ecdsap_384_sha_384 => 14 (ECDSAP384SHA384)
39
+ # @param [Symbol] digest_type
40
+ # :sha_1 => 1 (SHA-1)
41
+ # :sha_256 => 2 (SHA-256)
42
+ # :gost_r_34_11_94 => 3 (GOST R 34.11-94)
43
+ # :sha_384 => 4 (SHA-384)
44
+ # @param [String] digest
45
+ def initialize(key_tag, alg, digest_type, digest)
46
+ key_tag = key_tag.to_i
47
+ @alg = ALG[alg] || raise("Invalid alg #{alg}")
48
+ @digest = digest
49
+ if (0..65535).include?(key_tag)
50
+ @key_tag = key_tag
51
+ else
52
+ raise "Invalid key tag #{key_tag}, should be 0<=key_tag<=65535"
53
+ end
54
+ @digest_type = DIGEST_TYPES[digest_type] || raise("Invalid digest type #{digest_type}")
55
+
56
+ super("secDNS:dsData")
57
+ self.add_element("secDNS:keyTag").text = @key_tag
58
+ self.add_element("secDNS:alg").text = @alg
59
+ self.add_element("secDNS:digestType").text = @digest_type
60
+ self.add_element("secDNS:digest").text = @digest
61
+
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KonoEppClient::DnsSec
4
+ class Rem < REXML::Element
5
+ def initialize(*ds_datas)
6
+ super("secDNS:rem")
7
+
8
+ ds_datas.each do |ds_data|
9
+ self.add_element ds_data
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KonoEppClient::DnsSec
4
+ class RemAll < REXML::Element
5
+ def initialize
6
+ super("secDNS:rem")
7
+ self.add_element("secDNS:all").text="true"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module KonoEppClient::Exceptions
4
+ class ErrorResponse < StandardError #:nodoc:
5
+ attr_accessor :response_xml, :response_code, :reason_code, :message
6
+
7
+ # Generic EPP exception. Accepts a response code and a message
8
+ def initialize(attributes = {})
9
+ @response_xml = attributes[:xml]
10
+ @response_code = attributes[:response_code]
11
+ @reason_code = attributes[:reason_code]
12
+ @message = attributes[:message]
13
+ end
14
+
15
+ def to_s
16
+ "#{@message} (reason: #{@reason_code} code: #{@response_code})"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ module KonoEppClient::Exceptions
2
+ class AuthenticationPasswordExpired < ErrorResponse; end
3
+
4
+ class LoginNeeded < ErrorResponse; end
5
+
6
+ ##
7
+ # Errore NIC:
8
+ # 2304=Object status prohibits operation 9022=Domain has status clientTransferProhibited
9
+ class DomainHasStatusCliTransProhibited < ErrorResponse; end
10
+
11
+ ##
12
+ # Errore NIC:
13
+ # 2304=Object status prohibits operation 9026=Domain has status clientUpdateProhibited
14
+ class DomainHasStatusClientUpdateProhibited < ErrorResponse; end
15
+ end
@@ -0,0 +1,16 @@
1
+ module KonoEppClient
2
+ module RequiresParameters #:nodoc:
3
+ def requires!(hash, *params)
4
+ params.each do |param|
5
+ if param.is_a?(Array)
6
+ raise ArgumentError.new("Missing required parameter: #{param.first}") unless hash.has_key?(param.first)
7
+
8
+ valid_options = param[1..-1]
9
+ raise ArgumentError.new("Parameter: #{param.first} must be one of #{valid_options.to_sentence(:connector => 'or')}") unless valid_options.include?(hash[param.first])
10
+ else
11
+ raise ArgumentError.new("Missing required parameter: #{param}") unless hash.has_key?(param)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -3,12 +3,22 @@ module KonoEppClient #:nodoc:
3
3
  include REXML
4
4
  include RequiresParameters
5
5
 
6
+ ##
7
+ # Se la risposta al login contiene questo tipo di chiave-valore, allora la comunicazione può avvenire con
8
+ # comandi aggiuntivi DNSSEC
9
+ DNS_CHECK_NS_SET = Set.new([["xmlns:secDNS", "urn:ietf:params:xml:ns:secDNS-1.1"],
10
+ ["xmlns:extsecDNS", "http://www.nic.it/ITNIC-EPP/extsecDNS-1.0"]],
11
+ )
12
+
6
13
  require 'nokogiri'
7
14
 
8
15
  attr_accessor :tag, :password, :server, :port, :ssl_version, :old_server,
9
16
  :services, :lang, :extensions, :version, :credit, :timeout,
10
17
  :transport, :transport_options
11
18
 
19
+ attr_reader :dns_sec_enabled
20
+ alias_method :dns_sec_enabled?, :dns_sec_enabled
21
+
12
22
  # ==== Required Attrbiutes
13
23
  #
14
24
  # * <tt>:server</tt> - The EPP server to connect to
@@ -19,16 +29,16 @@ module KonoEppClient #:nodoc:
19
29
  #
20
30
  # * <tt>:port</tt> - The EPP standard port is 700. However, you can choose a different port to use.
21
31
  # * <tt>:clTRID</tt> - The client transaction identifier is an element that EPP specifies MAY be used to uniquely identify the command to the server. You are responsible for maintaining your own transaction identifier space to ensure uniqueness. Defaults to "ABC-12345"
22
- # * <tt>:old_server</tt> - Set to true to read and write frames in a way that is compatible with older EPP servers. Default is false.
23
32
  # * <tt>:lang</tt> - Set custom language attribute. Default is 'en'.
24
33
  # * <tt>:services</tt> - Use custom EPP services in the <login> frame. The defaults use the EPP standard domain, contact and host 1.0 services.
25
34
  # * <tt>:extensions</tt> - URLs to custom extensions to standard EPP. Use these to extend the standard EPP (e.g., Nominet uses extensions). Defaults to none.
26
35
  # * <tt>:version</tt> - Set the EPP version. Defaults to "1.0".
27
- # * <tt>:transport</tt> - Type of connection (http or tcp). Default to "tcp"
36
+ # * <tt>:transport</tt> - Type of connection (http). Default to "html"
28
37
  # * <tt>:transport_options</tt> - Overrides for transport configurations. Default to {}
29
- # * <tt>:timeout</tt> - Timeou for connections in seconds. Default to "30"
38
+ # * <tt>:timeout</tt> - Timeout for connections in seconds. Default to "30"
30
39
  # * <tt>:ssl_version</tt> - Version of the ssl protocol versione. Default to TLSv1
31
40
  # * <tt>:ssl_version</tt> - Version of the ssl protocol versione. Default to TLSv1
41
+ # * <tt>:enable_dns_sec</tt> - Try to enable DNSSEC, the response from login command will say it. default false
32
42
  #
33
43
  def initialize(attributes = {})
34
44
  requires!(attributes, :tag, :password, :server)
@@ -37,17 +47,22 @@ module KonoEppClient #:nodoc:
37
47
  @password = attributes[:password]
38
48
  @server = attributes[:server]
39
49
  @port = attributes[:port] || 700
40
- @old_server = attributes[:old_server] || false
41
50
  @lang = attributes[:lang] || "en"
42
51
  @services = attributes[:services] || ["urn:ietf:params:xml:ns:domain-1.0", "urn:ietf:params:xml:ns:contact-1.0", "urn:ietf:params:xml:ns:host-1.0"]
43
52
  @extensions = attributes[:extensions] || []
44
53
  @version = attributes[:version] || "1.0"
45
- @transport = attributes[:transport] || :tcp
54
+ @transport = attributes[:transport] || :http
46
55
  @transport_options = attributes[:transport_options] || {}
47
56
  @timeout = attributes[:timeout] || 30
48
57
  @ssl_version = attributes[:ssl_version] || :TLSv1
49
58
 
59
+ if attributes[:enable_dns_sec]
60
+ @extensions << "urn:ietf:params:xml:ns:secDNS-1.1"
61
+ @extensions << "http://www.nic.it/ITNIC-EPP/extsecDNS-1.0"
62
+ end
63
+
50
64
  @logged_in = false
65
+ @dns_sec_enabled = false
51
66
  end
52
67
 
53
68
  def connect_and_hello
@@ -61,29 +76,9 @@ module KonoEppClient #:nodoc:
61
76
  @connection.close
62
77
  end
63
78
 
64
- # Sends an XML request to the EPP server, and receives an XML response.
65
- # <tt><login></tt> and <tt><logout></tt> requests are also wrapped
66
- # around the request, so we can close the socket immediately after
67
- # the request is made.
68
- def request(xml)
69
- # open_connection
70
-
71
- # @logged_in = true if login
72
-
73
- begin
74
- @response = send_request(xml)
75
- ensure
76
- if @logged_in && !old_server
77
- @logged_in = false if logout
78
- end
79
- end
80
-
81
- return @response
82
- end
83
-
84
79
  # Sends a standard login request to the EPP server.
85
80
  def login
86
- login = KonoEppLogin.new(tag, password)
81
+ login = Commands::Login.new(tag, password)
87
82
 
88
83
  # FIXME: Order matters
89
84
  login.version = version
@@ -92,11 +87,18 @@ module KonoEppClient #:nodoc:
92
87
  login.services = services
93
88
  login.extensions = extensions
94
89
 
95
- send_command(login)
90
+ response = send_command(login)
91
+
92
+ response_set = Set.new(response.namespaces.to_a)
93
+ if response_set.superset?(DNS_CHECK_NS_SET)
94
+ @dns_sec_enabled = true
95
+ end
96
+
97
+ response
96
98
  end
97
99
 
98
100
  def change_password(new_password)
99
- login = KonoEppLogin.new(tag, password)
101
+ login = Commands::Login.new(tag, password)
100
102
 
101
103
  # FIXME: Order matters
102
104
  login.new_password = new_password
@@ -122,11 +124,11 @@ module KonoEppClient #:nodoc:
122
124
 
123
125
  # FIXME: Remove command wrappers?
124
126
  def hello
125
- send_request(KonoEppHello.new.to_s)
127
+ send_request(Commands::Hello.new.to_s)
126
128
  end
127
129
 
128
130
  def poll(id = nil)
129
- poll = KonoEppPoll.new(id ? :ack : :req)
131
+ poll = Commands::Poll.new(id ? :ack : :req)
130
132
 
131
133
  poll.ack_id = id if id
132
134
 
@@ -134,60 +136,68 @@ module KonoEppClient #:nodoc:
134
136
  end
135
137
 
136
138
  def create_contact(options)
137
- contact = KonoEppCreateContact.new options
139
+ contact = Commands::CreateContact.new options
138
140
  send_command(contact)
139
141
  end
140
142
 
141
143
  def check_contacts(ids)
142
- send_command(KonoEppCheckContacts.new(ids))
144
+ send_command(Commands::CheckContacts.new(ids))
143
145
  end
144
146
 
145
147
  def delete_contact(id)
146
- contact = KonoEppDeleteContact.new id
148
+ contact = Commands::DeleteContact.new id
147
149
  send_command(contact)
148
150
  end
149
151
 
150
152
  def update_contact(options)
151
- contact = KonoEppUpdateContact.new options
153
+ contact = Commands::UpdateContact.new options
152
154
  send_command(contact)
153
155
  end
154
156
 
155
157
  def create_domain(options)
156
- domain = KonoEppCreateDomain.new options
158
+ dns_sec_data = options.delete(:dns_sec_data)||[]
159
+ if dns_sec_enabled?
160
+ options[:dns_sec_data] = dns_sec_data
161
+ end
162
+ domain = Commands::CreateDomain.new options
157
163
  send_command(domain)
158
164
  end
159
165
 
160
166
  def check_domains(*domains)
161
- send_command(KonoEppCheckDomains.new *domains)
167
+ send_command(Commands::CheckDomains.new *domains)
162
168
  end
163
169
 
164
170
  def update_domain(options)
165
- domain = KonoEppUpdateDomain.new options
171
+ dns_sec_data = options.delete(:dns_sec_data)||[]
172
+ if dns_sec_enabled?
173
+ options[:dns_sec_data] = dns_sec_data
174
+ end
175
+ domain = Commands::UpdateDomain.new options
166
176
  send_command(domain)
167
177
  end
168
178
 
169
179
  def delete_domain(name)
170
- domain = KonoEppDeleteDomain.new name
180
+ domain = Commands::DeleteDomain.new name
171
181
  send_command(domain)
172
182
  end
173
183
 
174
184
  def info_contact(id)
175
- contact = KonoEppInfoContact.new id
185
+ contact = Commands::InfoContact.new id
176
186
  send_command(contact)
177
187
  end
178
188
 
179
189
  def info_domain(name)
180
- info = KonoEppInfoDomain.new name
190
+ info = Commands::InfoDomain.new name
181
191
  send_command(info)
182
192
  end
183
193
 
184
194
  def transfer_domain(name, authinfo, op, extension: nil)
185
- send_command(KonoEppTransferDomain.new(name, authinfo, op, extension: extension))
195
+ send_command(Commands::TransferDomain.new(name, authinfo, op, extension: extension))
186
196
  end
187
197
 
188
198
  # Sends a standard logout request to the EPP server.
189
199
  def logout
190
- send_command(KonoEppLogout.new, 1500)
200
+ send_command(Commands::Logout.new, 1500)
191
201
  end
192
202
 
193
203
  # private
@@ -207,16 +217,16 @@ module KonoEppClient #:nodoc:
207
217
  # TODO: multiple <response> RFC 3730 §2.6
208
218
  result = xml.at_xpath("/xmlns:epp/xmlns:response[1]/xmlns:result",
209
219
  namespaces)
210
- raise KonoEppErrorResponse.new(:message => 'Malformed response') if result.nil?
220
+ raise Exceptions::ErrorResponse.new(:message => 'Malformed response') if result.nil?
211
221
 
212
222
  xmlns_code = result.at_xpath("@code")
213
- raise KonoEppErrorResponse.new(:message => 'Malformed response') if xmlns_code.nil?
223
+ raise Exceptions::ErrorResponse.new(:message => 'Malformed response') if xmlns_code.nil?
214
224
 
215
225
  response_code = xmlns_code.value.to_i
216
226
 
217
227
  xmlns_msg = result.xpath("xmlns:msg/text ()",
218
228
  namespaces)
219
- raise KonoEppErrorResponse.new(:message => 'Malformed response') if xmlns_msg.empty?
229
+ raise Exceptions::ErrorResponse.new(:message => 'Malformed response') if xmlns_msg.empty?
220
230
 
221
231
  result_message = xmlns_msg.text.strip
222
232
 
@@ -230,8 +240,7 @@ module KonoEppClient #:nodoc:
230
240
  namespaces)
231
241
  reason_code = xmlns_reason_code.text.strip.to_i unless xmlns_reason_code.empty?
232
242
 
233
- credit_msg = xml.xpath("//extepp:credit/text ()",
234
- namespaces)
243
+ credit_msg = xml.xpath("//extepp:credit/text ()", namespaces)
235
244
  @credit = credit_msg.text.to_f unless credit_msg.empty?
236
245
 
237
246
  if expected_result === response_code
@@ -245,15 +254,15 @@ module KonoEppClient #:nodoc:
245
254
 
246
255
  case [response_code, reason_code]
247
256
  when [2200, 6004]
248
- raise KonoEppAuthenticationPasswordExpired.new(args)
257
+ raise Exceptions::AuthenticationPasswordExpired.new(args)
249
258
  when [2002, 4015]
250
- raise KonoEppLoginNeeded.new(args)
259
+ raise Exceptions::LoginNeeded.new(args)
251
260
  when [2304, 9022]
252
- raise KonoEppDomainHasStatusCliTransProhibited.new(args)
261
+ raise Exceptions::DomainHasStatusCliTransProhibited.new(args)
253
262
  when [2304, 9026]
254
- raise KonoEppDomainHasStatusClientUpdateProhibited.new(args)
263
+ raise Exceptions::DomainHasStatusClientUpdateProhibited.new(args)
255
264
  else
256
- raise KonoEppErrorResponse.new(args)
265
+ raise Exceptions::ErrorResponse.new(args)
257
266
  end
258
267
  end
259
268
 
@@ -267,8 +276,6 @@ module KonoEppClient #:nodoc:
267
276
  # e successivamente viene utilizzato sempre quello?
268
277
  Timeout.timeout @timeout do
269
278
  case @transport
270
- when :tcp
271
- @connection = KonoEppClient::Transport::TcpTransport.new(server, port)
272
279
  when :http
273
280
 
274
281
  options = {
@@ -277,7 +284,8 @@ module KonoEppClient #:nodoc:
277
284
  }.merge(@transport_options)
278
285
 
279
286
  @connection = KonoEppClient::Transport::HttpTransport.new(server, port, **options)
280
-
287
+ else
288
+ raise "Not Implemented #{@transport}"
281
289
  end
282
290
  end
283
291
  end