gandi_v5 0.4.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -5
  3. data/LICENSE.md +2 -6
  4. data/README.md +65 -17
  5. data/lib/gandi_v5.rb +139 -70
  6. data/lib/gandi_v5/billing/info/prepaid.rb +1 -0
  7. data/lib/gandi_v5/data.rb +1 -0
  8. data/lib/gandi_v5/data/converter.rb +3 -2
  9. data/lib/gandi_v5/data/converter/array_of.rb +3 -2
  10. data/lib/gandi_v5/data/converter/integer.rb +27 -0
  11. data/lib/gandi_v5/data/converter/symbol.rb +3 -2
  12. data/lib/gandi_v5/data/converter/time.rb +3 -2
  13. data/lib/gandi_v5/domain.rb +16 -17
  14. data/lib/gandi_v5/domain/availability/product/period.rb +1 -1
  15. data/lib/gandi_v5/domain/contact.rb +5 -5
  16. data/lib/gandi_v5/domain/tld.rb +2 -2
  17. data/lib/gandi_v5/domain/transfer_in.rb +170 -0
  18. data/lib/gandi_v5/domain/transfer_in/availability.rb +51 -0
  19. data/lib/gandi_v5/email.rb +1 -0
  20. data/lib/gandi_v5/email/forward.rb +2 -8
  21. data/lib/gandi_v5/email/mailbox.rb +3 -9
  22. data/lib/gandi_v5/email/slot.rb +11 -3
  23. data/lib/gandi_v5/error/gandi_error.rb +1 -0
  24. data/lib/gandi_v5/live_dns.rb +2 -12
  25. data/lib/gandi_v5/live_dns/domain.rb +340 -29
  26. data/lib/gandi_v5/live_dns/domain/dnssec_key.rb +120 -0
  27. data/lib/gandi_v5/live_dns/domain/record.rb +81 -0
  28. data/lib/gandi_v5/live_dns/domain/snapshot.rb +111 -0
  29. data/lib/gandi_v5/live_dns/domain/tsig_key.rb +74 -0
  30. data/lib/gandi_v5/sharing_space.rb +27 -0
  31. data/lib/gandi_v5/simple_hosting.rb +13 -0
  32. data/lib/gandi_v5/simple_hosting/instance.rb +245 -0
  33. data/lib/gandi_v5/simple_hosting/instance/application.rb +45 -0
  34. data/lib/gandi_v5/simple_hosting/instance/database.rb +20 -0
  35. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  36. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +22 -0
  37. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
  38. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +75 -0
  39. data/lib/gandi_v5/version.rb +1 -1
  40. data/spec/.rubocop.yml +50 -3
  41. data/spec/features/list_domain_renewals_spec.rb +16 -0
  42. data/spec/features/list_email_addresses_spec.rb +39 -0
  43. data/spec/fixtures/bodies/GandiV5_Domain/fetch.yml +8 -0
  44. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn/fetch.yml +21 -0
  45. data/spec/fixtures/bodies/GandiV5_Domain_TransferIn_Availability/fetch.yml +10 -0
  46. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/fetch.yml +1 -2
  47. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/list_tsig.yml +3 -0
  48. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain/nameservers.yml +3 -0
  49. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/fetch.yml +12 -0
  50. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_DnssecKey/list.yml +9 -0
  51. data/spec/fixtures/bodies/{GandiV5_LiveDNS_Zone_Snapshot → GandiV5_LiveDNS_Domain_Snapshot}/fetch.yml +4 -3
  52. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_Snapshot/list.yml +5 -0
  53. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/fetch.yml +9 -0
  54. data/spec/fixtures/bodies/GandiV5_LiveDNS_Domain_TsigKey/list.yml +4 -0
  55. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  56. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  57. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  58. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  59. data/spec/fixtures/vcr/Examples/List_domain_renewals.yml +54 -0
  60. data/spec/fixtures/vcr/Examples/List_email_addresses.yml +103 -0
  61. data/spec/units/gandi_v5/data/converter/integer_spec.rb +16 -0
  62. data/spec/units/gandi_v5/domain/transfer_in/availability_spec.rb +49 -0
  63. data/spec/units/gandi_v5/domain/transfer_in_spec.rb +143 -0
  64. data/spec/units/gandi_v5/domain_spec.rb +13 -39
  65. data/spec/units/gandi_v5/email/forward_spec.rb +5 -34
  66. data/spec/units/gandi_v5/email/mailbox_spec.rb +4 -34
  67. data/spec/units/gandi_v5/email/slot_spec.rb +10 -2
  68. data/spec/units/gandi_v5/live_dns/domain/dnssec_key_spec.rb +128 -0
  69. data/spec/units/gandi_v5/live_dns/{record_set_spec.rb → domain/record_spec.rb} +1 -1
  70. data/spec/units/gandi_v5/live_dns/domain/snapshot_spec.rb +101 -0
  71. data/spec/units/gandi_v5/live_dns/domain/tsig_key_spec.rb +78 -0
  72. data/spec/units/gandi_v5/live_dns/domain_spec.rb +297 -118
  73. data/spec/units/gandi_v5/live_dns_spec.rb +0 -12
  74. data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
  75. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  76. data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
  77. data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
  78. data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
  79. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  80. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
  81. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
  82. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  83. data/spec/units/gandi_v5_spec.rb +111 -14
  84. metadata +171 -48
  85. data/.gitignore +0 -26
  86. data/.rspec +0 -3
  87. data/.rubocop.yml +0 -30
  88. data/.travis.yml +0 -37
  89. data/FUNDING.yml +0 -10
  90. data/Gemfile +0 -6
  91. data/Guardfile +0 -39
  92. data/Rakefile +0 -3
  93. data/bin/console +0 -13
  94. data/gandi_v5.gemspec +0 -42
  95. data/lib/gandi_v5/domain/sharing_space.rb +0 -21
  96. data/lib/gandi_v5/live_dns/has_zone_records.rb +0 -153
  97. data/lib/gandi_v5/live_dns/record_set.rb +0 -79
  98. data/lib/gandi_v5/live_dns/zone.rb +0 -160
  99. data/lib/gandi_v5/live_dns/zone/snapshot.rb +0 -81
  100. data/spec/features/domain_spec.rb +0 -45
  101. data/spec/features/livedns_domain_spec.rb +0 -8
  102. data/spec/features/livedns_zone_spec.rb +0 -45
  103. data/spec/features/mailbox_spec.rb +0 -18
  104. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/fetch.yml +0 -11
  105. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone/list.yml +0 -11
  106. data/spec/fixtures/bodies/GandiV5_LiveDNS_Zone_Snapshot/list.yml +0 -3
  107. data/spec/fixtures/vcr/Domain_features/List_domains.yml +0 -55
  108. data/spec/fixtures/vcr/Domain_features/Renew_domain.yml +0 -133
  109. data/spec/fixtures/vcr/LiveDNS_Domain_features/List_domains.yml +0 -32
  110. data/spec/fixtures/vcr/LiveDNS_Zone_features/List_zones.yml +0 -42
  111. data/spec/fixtures/vcr/LiveDNS_Zone_features/Make_and_save_snapshot.yml +0 -72
  112. data/spec/fixtures/vcr/LiveDNS_Zone_features/Save_zone_to_file.yml +0 -28
  113. data/spec/fixtures/vcr/Mailbox_features/List_mailboxes.yml +0 -39
  114. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
  115. data/spec/units/gandi_v5/live_dns/zone/snapshot_spec.rb +0 -66
  116. data/spec/units/gandi_v5/live_dns/zone_spec.rb +0 -347
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class LiveDNS
5
+ class Domain
6
+ # A DNSSEC key for a domain's DNS records.
7
+ # @!attribute [r] uuid
8
+ # @return [String]
9
+ # @!attribute [r] status
10
+ # @return [String]
11
+ # @!attribute [r] fqdn
12
+ # @return [String]
13
+ # @!attribute [r] algorithm_id
14
+ # @return [Integer]
15
+ # @!attribute [r] algorithm_name
16
+ # @return [String]
17
+ # @!attribute [r] deleted
18
+ # @return [Boolean]
19
+ # @!attribute [r] ds
20
+ # @return [String]
21
+ # @!attribute [r] flags
22
+ # @return [Integer]
23
+ # @!attribute [r] fingerprint
24
+ # @return [String]
25
+ # @!attribute [r] public_key
26
+ # @return [String]
27
+ # @!attribute [r] tag
28
+ # @return [String]
29
+ class DnssecKey
30
+ include GandiV5::Data
31
+
32
+ members :status, :fqdn, :deleted, :ds, :flags, :fingerprint, :public_key,
33
+ :tag, :algorithm_name
34
+
35
+ member :uuid, gandi_key: 'id'
36
+ member :algorithm_id, gandi_key: 'algorithm'
37
+
38
+ # Delete this key.
39
+ # @see https://api.gandi.net/docs/livedns/#delete-v5-livedns-domains-fqdn-keys-id
40
+ # @return [String] The confirmation message from Gandi.
41
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
42
+ def delete
43
+ _response, data = GandiV5.delete url
44
+ self.deleted = true
45
+ data['message']
46
+ end
47
+
48
+ # Undelete this key.
49
+ # @see https://api.gandi.net/docs/livedns/#patch-v5-livedns-domains-fqdn-keys-id
50
+ # @return [String] The confirmation message from Gandi.
51
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
52
+ def undelete
53
+ _response, data = GandiV5.patch url, { deleted: false }.to_json
54
+ self.deleted = false
55
+ data['message']
56
+ end
57
+
58
+ # Check if this is a zone signing key
59
+ # @return [Boolean]
60
+ def zone_signing_key?
61
+ flags == 256
62
+ end
63
+
64
+ # Check if this is a key signing key
65
+ # @return [Boolean]
66
+ def key_signing_key?
67
+ flags == 257
68
+ end
69
+
70
+ # Create a new DNSSEC key for a zone.
71
+ # @see https://api.gandi.net/docs/livedns/#post-v5-livedns-domains-fqdn-keys
72
+ # @param fqdn [String, #to_s] the fully qualified domain to create the key for.
73
+ # @param flags [Integer, :key_signing_key, :zone_signing_key] the key's flags.
74
+ # @return [GandiV5::LiveDNS::Domain::DnssecKey]
75
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
76
+ def self.create(fqdn, flags)
77
+ flags = 256 if flags == :zone_signing_key
78
+ flags = 257 if flags == :key_signing_key
79
+ fail ArgumentError, 'flags is invalid' unless flags.is_a?(Integer)
80
+
81
+ response, _data = GandiV5.post url(fqdn), { flags: flags }.to_json
82
+ fetch fqdn, response.headers[:location].split('/').last
83
+ end
84
+
85
+ # Get keys for a FQDN from Gandi.
86
+ # @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-keys
87
+ # @param fqdn [String, #to_s] The fully qualified domain name to get the keys for.
88
+ # @return [Array<GandiV5::LiveDNS::Domain::DnssecKey>]
89
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
90
+ def self.list(fqdn)
91
+ _response, data = GandiV5.get url(fqdn)
92
+ data.map { |item| from_gandi item }
93
+ end
94
+
95
+ # Get DNSSEC key from Gandi.
96
+ # @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-keys-id
97
+ # @param fqdn [String, #to_s] The fully qualified domain name the key was made for.
98
+ # @param uuid [String, #to_s] the UUID of the key to fetch.
99
+ # @return [GandiV5::LiveDNS::Domain::DnssecKey]
100
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
101
+ def self.fetch(fqdn, uuid)
102
+ _response, data = GandiV5.get url(fqdn, uuid)
103
+ from_gandi data
104
+ end
105
+
106
+ private
107
+
108
+ def url
109
+ "#{BASE}livedns/domains/#{CGI.escape fqdn}/keys/#{CGI.escape uuid}"
110
+ end
111
+
112
+ def self.url(fqdn, uuid = nil)
113
+ "#{BASE}livedns/domains/#{CGI.escape fqdn}/keys" +
114
+ (uuid ? "/#{CGI.escape uuid}" : '')
115
+ end
116
+ private_class_method :url
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class LiveDNS
5
+ class Domain
6
+ # A record set which comes from either a domain or zone.
7
+ # @!attribute [r] type
8
+ # @return [String]
9
+ # @!attribute [r] ttl
10
+ # @return [Integer]
11
+ # @!attribute [r] name
12
+ # @return [String]
13
+ # @!attribute [r] values
14
+ # @return [Array<String>]
15
+ class Record
16
+ include GandiV5::Data
17
+
18
+ member :type, gandi_key: 'rrset_type'
19
+ member :ttl, gandi_key: 'rrset_ttl', converter: GandiV5::Data::Converter::Integer
20
+ member :name, gandi_key: 'rrset_name'
21
+ member :values, gandi_key: 'rrset_values'
22
+
23
+ # Generate zone file lines for the record.
24
+ # @return [String]
25
+ def to_s
26
+ values.map do |value|
27
+ "#{name}\t#{ttl}\tIN\t#{type}\t#{value}"
28
+ end.join("\n")
29
+ end
30
+
31
+ GandiV5::LiveDNS::RECORD_TYPES.each do |t|
32
+ # Check the record type.
33
+ # @return [Boolean]
34
+ define_method "#{t.downcase}?" do
35
+ type.eql?(t)
36
+ end
37
+ end
38
+
39
+ # Check the TTL's value in seconds.
40
+ # @param number [Integer] the number of second(s) to check against.
41
+ # @return [Boolean]
42
+ def second?(number = 1)
43
+ ttl == number
44
+ end
45
+ alias seconds? second?
46
+
47
+ # Check the TTL's value in minutes.
48
+ # @param number [Integer] the number of minute(s) to check against.
49
+ # @return [Boolean]
50
+ def minute?(number = 1)
51
+ ttl == number * 60
52
+ end
53
+ alias minutes? minute?
54
+
55
+ # Check the TTL's value in hours.
56
+ # @param number [Integer] the number of hour(s) to check against.
57
+ # @return [Boolean]
58
+ def hour?(number = 1)
59
+ ttl == number * 3_600
60
+ end
61
+ alias hours? hour?
62
+
63
+ # Check the TTL's value in days.
64
+ # @param number [Integer] the number of day(s) to check against.
65
+ # @return [Boolean]
66
+ def day?(number = 1)
67
+ ttl == number * 86_400
68
+ end
69
+ alias days? day?
70
+
71
+ # Check the TTL's value in weeks.
72
+ # @param number [Integer] the number of week(s) to check against.
73
+ # @return [Boolean]
74
+ def week?(number = 1)
75
+ ttl == number * 604_800
76
+ end
77
+ alias weeks? day?
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class LiveDNS
5
+ class Domain
6
+ # A snapshot (backup) of a domain's DNS records.
7
+ # @!attribute [r] fqdn
8
+ # @return [String]
9
+ # @!attribute [r] uuid
10
+ # @return [String]
11
+ # @!attribute [r] name
12
+ # @return [String]
13
+ # @!attribute [r] created_at
14
+ # @return [Time]
15
+ # @!attribute [r] automatic
16
+ # @return [Boolean]
17
+ class Snapshot
18
+ include GandiV5::Data
19
+
20
+ members :name, :automatic, :fqdn
21
+ member :created_at, converter: GandiV5::Data::Converter::Time
22
+ member :uuid, gandi_key: 'id'
23
+ member(
24
+ :records,
25
+ gandi_key: 'zone_data',
26
+ converter: GandiV5::LiveDNS::Domain::Record,
27
+ array: true
28
+ )
29
+
30
+ alias snapshot_uuid uuid
31
+
32
+ # Delete this snapshot.
33
+ # @see https://api.gandi.net/docs/livedns/#delete-v5-livedns-domains-fqdn-snapshots-id
34
+ # @return [String] The confirmation message from Gandi.
35
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
36
+ def delete
37
+ _response, data = GandiV5.delete url
38
+ data['message']
39
+ end
40
+
41
+ # Update this snapshot.
42
+ # @see https://api.gandi.net/docs/livedns/#patch-v5-livedns-domains-fqdn-snapshots-id
43
+ # @param name [String, #to_s] new name for the snapshot.
44
+ # @return [String] The confirmation message from Gandi.
45
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
46
+ def update(name:)
47
+ _response, data = GandiV5.patch url, { name: name }.to_json
48
+ self.name = name
49
+ data['message']
50
+ end
51
+
52
+ # Get snapshot details for this FQDN from Gandi.
53
+ # @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-snapshots
54
+ # @param fqdn [String, #to_s] The fully qualified domain name to get the snapshots for.
55
+ # @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
56
+ # If page is not provided keep querying until an empty list is returned.
57
+ # If page responds to .each then iterate until an empty list is returned.
58
+ # @param per_page [Integer, #to_s] (optional default 100) how many results to get per page.
59
+ # @param automatic [nil, Boolean] (optional) filter by automatic or manual snapshot.
60
+ # @return [Array<GandiV5::LiveDNS::Domain::Snapshot>]
61
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
62
+ def self.list(fqdn, page: (1..), per_page: 100, **params)
63
+ params.reject! { |_k, v| v.nil? }
64
+
65
+ snapshots = []
66
+ GandiV5.paginated_get(url(fqdn), page, per_page, params: params) do |data|
67
+ snapshots += data.map { |item| from_gandi item.merge(fqdn: fqdn) }
68
+ end
69
+ snapshots
70
+ end
71
+
72
+ # Get snapshot from Gandi.
73
+ # @see https://api.gandi.net/docs/livedns/#get-v5-livedns-domains-fqdn-snapshots-id
74
+ # @param fqdn [String, #to_s] The fully qualified domain name the snapshot was made for.
75
+ # @param uuid [String, #to_s] the UUID of the snapshot to fetch.
76
+ # @return [GandiV5::LiveDNS::Domain::Snapshot]
77
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
78
+ def self.fetch(fqdn, uuid)
79
+ _response, data = GandiV5.get url(fqdn, uuid)
80
+ from_gandi data.merge(fqdn: fqdn)
81
+ end
82
+
83
+ # Get the records which makeup this snapshot (fetching from Gandi if required).
84
+ # @return [Array<GandiV5::LiveDNS::Domain::Record>]
85
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
86
+ def records
87
+ return @records unless @records.nil?
88
+
89
+ @records = fetch_records
90
+ end
91
+
92
+ private
93
+
94
+ def fetch_records
95
+ _response, data = GandiV5.get url
96
+ data.fetch('zone_data').map { |item| GandiV5::LiveDNS::Domain::Record.from_gandi item }
97
+ end
98
+
99
+ def url
100
+ "#{BASE}livedns/domains/#{CGI.escape fqdn}/snapshots/#{CGI.escape uuid}"
101
+ end
102
+
103
+ def self.url(fqdn, snapshot_uuid = nil)
104
+ "#{BASE}livedns/domains/#{CGI.escape fqdn}/snapshots" +
105
+ (snapshot_uuid ? "/#{CGI.escape snapshot_uuid}" : '')
106
+ end
107
+ private_class_method :url
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class LiveDNS
5
+ class Domain
6
+ # A Tsig key.
7
+ # @!attribute [r] uuid
8
+ # @return [String]
9
+ # @!attribute [r] name
10
+ # @return [String]
11
+ # @!attribute [r] secret
12
+ # @return [String]
13
+ # @!attribute [r] config_examples
14
+ # @return [Hash<Symbol -> String>]
15
+ class TsigKey
16
+ include GandiV5::Data
17
+
18
+ member :secret
19
+ member :uuid, gandi_key: 'id'
20
+ member :name, gandi_key: 'key_name'
21
+ member(
22
+ :config_examples,
23
+ gandi_key: 'config_samples',
24
+ converter: GandiV5::Data::Converter.new(
25
+ from_gandi: ->(value) { value.transform_keys(&:to_sym) },
26
+ to_gandi: ->(_value) { nil }
27
+ )
28
+ )
29
+
30
+ # Create a new DNSSEC key for a zone.
31
+ # @see https://api.gandi.net/docs/livedns/#post-v5-livedns-axfr-tsig
32
+ # @param sharing_id [nil, String, #to_s]
33
+ # @return [GandiV5::LiveDNS::Domain::DnssecKey]
34
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
35
+ def self.create(sharing_id = nil)
36
+ url_ = url
37
+ url_ += "?sharing_id=#{CGI.escape sharing_id}" if sharing_id
38
+
39
+ _response, data = GandiV5.post url_
40
+ fetch data.fetch('id')
41
+ end
42
+
43
+ # Get keys from Gandi.
44
+ # If you need the secret, fingerprint, public_key or tag attributes you'll need
45
+ # to use GandiV5::LiveDNS::Domain::DnssecKey.fetch on each item.
46
+ # @see https://api.gandi.net/docs/livedns/#get-v5-livedns-axfr-tsig
47
+ # @return [Array<GandiV5::LiveDNS::Domain::TsigKey>]
48
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
49
+ def self.list
50
+ _response, data = GandiV5.get url
51
+ data.map { |item| from_gandi item }
52
+ end
53
+
54
+ # Get Tsig key from Gandi.
55
+ # @see https://api.gandi.net/docs/livedns/#get-v5-livedns-axfr-tsig-id
56
+ # @param uuid [String, #to_s] the UUID of the key to fetch.
57
+ # @return [GandiV5::LiveDNS::Domain::TsigKey]
58
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
59
+ def self.fetch(uuid)
60
+ _response, data = GandiV5.get url(uuid)
61
+ from_gandi data
62
+ end
63
+
64
+ private
65
+
66
+ def self.url(uuid = nil)
67
+ "#{BASE}livedns/axfr/tsig" +
68
+ (uuid ? "/#{CGI.escape uuid}" : '')
69
+ end
70
+ private_class_method :url
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ # Sharing space which contains other billable items.
5
+ # @!attribute [r] uuid
6
+ # @return [String]
7
+ # @!attribute [r] name
8
+ # @return [String]
9
+ # @!attribute [r] type
10
+ # @return [String]
11
+ # @!attribute [r] reseller
12
+ # @return [nil, Boolean]
13
+ # @!attribute [r] reseller_details
14
+ # @return [nil, GandiV5::Domain::SharingSpace]
15
+ class SharingSpace
16
+ include GandiV5::Data
17
+
18
+ members :name, :type, :reseller
19
+ member :uuid, gandi_key: 'id'
20
+ member(
21
+ :reseller_details,
22
+ gandi_key: 'sharing_space',
23
+ converter: GandiV5::SharingSpace
24
+ )
25
+ alias sharing_space_uuid uuid
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Namespace for classes which access LiveDNS details.
4
+ class GandiV5
5
+ # Gandi Simple Hosting management API.
6
+ # @see https://api.gandi.net/docs/simplehosting/
7
+ class SimpleHosting
8
+ # @see GandiV5::Simplehosting::Instance.list
9
+ def self.instances
10
+ GandiV5::SimpleHosting::Instance.list
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,245 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Namespace for classes which access LiveDNS details.
4
+ class GandiV5
5
+ class SimpleHosting
6
+ # A simple hosting instance.
7
+ # @see https://api.gandi.net/docs/simplehosting/
8
+ # @!attribute [r] uuid
9
+ # @return [String]
10
+ # @!attribute [r] name
11
+ # @return [String]
12
+ # @!attribute [r] size
13
+ # @return [String] one of: s, s+, m, l, xl, xxl
14
+ # @!attribute [r] password_updated_at
15
+ # @return [Time]
16
+ # @!attribute [r] created_at
17
+ # @return [Time]
18
+ # @!attribute [r] expire_at
19
+ # @return [Time]
20
+ # @!attribute [r] status
21
+ # @return [Symbol] :waiting_bill, :being_created, :active
22
+ # :paused, :locked, :being_deleted
23
+ # @!attribute [r] snapshot_enabled
24
+ # @return [Boolean]
25
+ # @!attribute [r] available_upgrade
26
+ # @return [Boolean]
27
+ # @!attribute [r] is_trial
28
+ # @return [Boolean]
29
+ # @!attribute [r] access_information
30
+ # @return [Hash] as returned by Gandi.
31
+ # @!attribute [r] sharing_space
32
+ # @return [GandiV5::SharingSpace] who pays for this instance.
33
+ # @!attribute [r] data_center
34
+ # @return [String] code of the data center hosting this instance.
35
+ # @!attribute [r] storage
36
+ # @return [Hash<Symbol => "#{number} #{unit}">]
37
+ # storage split by :base, :additional and :total
38
+ # @!attribute [r] auto_renew
39
+ # @return [string] "#{number} #{unit}".
40
+ # @!attribute [r] virtual_hosts
41
+ # @return [Array<GandiV5::SimpleHosting::Instance::VirtualHost>]
42
+ # @!attribute [r] database
43
+ # @return [GandiV5::SimpleHosting::Instance::Database]
44
+ # @!attribute [r] language
45
+ # @return [GandiV5::SimpleHosting::Instance::Language]
46
+ # @!attribute [r] compatible_applications
47
+ # @return [Array<GandiV5::SimpleHosting::Instance::Application>]
48
+ # @!attribute [r] upgrade_to
49
+ # @return [Array<GandiV5::SimpleHosting::Instance::Upgrade>]
50
+ class Instance
51
+ include GandiV5::Data
52
+
53
+ members :name, :size, :password_updated_at, :created_at, :expire_at, :status,
54
+ :snapshot_enabled, :available_upgrade, :is_trial, :access_information
55
+
56
+ member :uuid, gandi_key: 'id'
57
+
58
+ member(
59
+ :sharing_space,
60
+ gandi_key: 'sharing_space',
61
+ converter: GandiV5::SharingSpace
62
+ )
63
+
64
+ member(
65
+ :data_center,
66
+ gandi_key: 'datacenter',
67
+ converter: GandiV5::Data::Converter.new(
68
+ from_gandi: ->(hash) { hash['code'] }
69
+ )
70
+ )
71
+
72
+ member(
73
+ :storage,
74
+ converter: GandiV5::Data::Converter.new(
75
+ from_gandi: lambda do |hash|
76
+ hash.transform_values { |value| "#{value['value']} #{value['unit']}" }
77
+ .transform_keys(&:to_sym)
78
+ end
79
+ )
80
+ )
81
+
82
+ member(
83
+ :auto_renew,
84
+ gandi_key: 'autorenew',
85
+ converter: GandiV5::Data::Converter.new(
86
+ from_gandi: ->(hash) { "#{hash['duration']} #{hash['duration_type']}" }
87
+ )
88
+ )
89
+
90
+ member(
91
+ :virtual_hosts,
92
+ gandi_key: 'vhosts',
93
+ array: true,
94
+ converter: GandiV5::SimpleHosting::Instance::VirtualHost
95
+ )
96
+
97
+ member(
98
+ :database,
99
+ converter: GandiV5::SimpleHosting::Instance::Database
100
+ )
101
+
102
+ member(
103
+ :language,
104
+ converter: GandiV5::SimpleHosting::Instance::Language
105
+ )
106
+
107
+ member(
108
+ :compatible_applications,
109
+ array: true,
110
+ converter: GandiV5::SimpleHosting::Instance::Application
111
+ )
112
+
113
+ member(
114
+ :upgrade_to,
115
+ array: true,
116
+ converter: GandiV5::SimpleHosting::Instance::Upgrade
117
+ )
118
+
119
+ # Instruct Gandi to restart this instance.
120
+ # @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-action
121
+ # @return [String] confirmation message.
122
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
123
+ def restart
124
+ _response, data = GandiV5.post "#{url}/action", { 'action' => 'restart' }.to_json
125
+ data
126
+ end
127
+
128
+ # Instruct Gandi to console this instance.
129
+ # @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-action
130
+ # @return [String] confirmation message.
131
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
132
+ def console
133
+ _response, data = GandiV5.post "#{url}/action", { 'action' => 'console' }.to_json
134
+ data
135
+ end
136
+
137
+ # Instruct Gandi to reset the database password for this instance.
138
+ # @see https://api.gandi.net/docs/simplehosting/#post-v5-simplehosting-instances-instance_id-action
139
+ # @return [String] confirmation message.
140
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
141
+ def reset_database_password
142
+ _response, data = GandiV5.post(
143
+ "#{url}/action",
144
+ { 'action' => 'reset_database_password' }.to_json
145
+ )
146
+ data
147
+ end
148
+
149
+ # Requery Gandi fo this instance's information.
150
+ # @return [GandiV5::SimpleHosting::Instance]
151
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
152
+ def refresh
153
+ _response, data = GandiV5.get url
154
+ from_gandi data
155
+ end
156
+
157
+ # Check if this instance is waiting for a bill
158
+ # @return [Boolean]
159
+ def waiting_bill?
160
+ status == :waiting_bill
161
+ end
162
+
163
+ # Check if this instance is being created
164
+ # @return [Boolean]
165
+ def being_created?
166
+ status == :being_created
167
+ end
168
+
169
+ # Check if this instance is active
170
+ # @return [Boolean]
171
+ def active?
172
+ status == :active
173
+ end
174
+
175
+ # Check if this instance is paused
176
+ # @return [Boolean]
177
+ def paused?
178
+ status == :paused
179
+ end
180
+
181
+ # Check if this instance is locked
182
+ # @return [Boolean]
183
+ def locked?
184
+ status == :locked
185
+ end
186
+
187
+ # Check if this instance is being deleted
188
+ # @return [Boolean]
189
+ def being_deleted?
190
+ status == :being_deleted
191
+ end
192
+
193
+ # Get information on an instance.
194
+ # @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id
195
+ # @param uuid [String, #to_s] the UUID of the instance.
196
+ # @return [GandiV5::SimpleHosting::Instance]
197
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
198
+ def self.fetch(uuid)
199
+ _response, data = GandiV5.get url(uuid)
200
+ from_gandi data
201
+ end
202
+
203
+ # List instances.
204
+ # @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances
205
+ # @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
206
+ # If page is not provided keep querying until an empty list is returned.
207
+ # If page responds to .each then iterate until an empty list is returned.
208
+ # @param per_page [Integer, #to_s] (optional default 100) how many results to get per page.
209
+ # @param sharing_id [String, #to_s] (optional)
210
+ # filter the list by who pays the bill.
211
+ # @param size [String, #to_s] (optional)
212
+ # filter the list by instance size (s, s+, m, i, xl, xxl).
213
+ # @param name [String, #to_s] (optional)
214
+ # filter the list by instance name, allows * as wildcard.
215
+ # @param status [String, #to_s] (optional)
216
+ # filter the list by the instance's status.
217
+ # @param fqdn [String, #to_s] (optional)
218
+ # filter the list by the virtual host's domain name, allows * as wildcard.
219
+ # @param sort_by [String, #to_s] (optional default "created_at")
220
+ # how to sort the list, prefix with a minus to reverse sort order.
221
+ # @return [Array<GandiV5::SimpleHosting::Instance>]
222
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
223
+ def self.list(page: (1..), per_page: 100, **params)
224
+ instances = []
225
+ GandiV5.paginated_get(url, page, per_page, params: params) do |data|
226
+ instances += data.map { |item| from_gandi item }
227
+ end
228
+ instances
229
+ end
230
+
231
+ private
232
+
233
+ def url
234
+ "#{BASE}simplehosting/instances/" +
235
+ CGI.escape(uuid)
236
+ end
237
+
238
+ def self.url(uuid = nil)
239
+ "#{BASE}simplehosting/instances" +
240
+ (uuid ? "/#{CGI.escape uuid}" : '')
241
+ end
242
+ private_class_method :url
243
+ end
244
+ end
245
+ end