gandi_v5 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +44 -0
  3. data/CHANGELOG.md +13 -0
  4. data/README.md +1 -0
  5. data/gandi_v5.gemspec +2 -2
  6. data/lib/gandi_v5/domain.rb +5 -3
  7. data/lib/gandi_v5/live_dns/domain.rb +2 -2
  8. data/lib/gandi_v5/sharing_space.rb +27 -0
  9. data/lib/gandi_v5/simple_hosting.rb +12 -0
  10. data/lib/gandi_v5/simple_hosting/instance.rb +242 -0
  11. data/lib/gandi_v5/simple_hosting/instance/application.rb +44 -0
  12. data/lib/gandi_v5/simple_hosting/instance/database.rb +19 -0
  13. data/lib/gandi_v5/simple_hosting/instance/language.rb +22 -0
  14. data/lib/gandi_v5/simple_hosting/instance/upgrade.rb +21 -0
  15. data/lib/gandi_v5/simple_hosting/instance/virtual_host.rb +187 -0
  16. data/lib/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone.rb +74 -0
  17. data/lib/gandi_v5/version.rb +1 -1
  18. data/spec/.rubocop.yml +50 -3
  19. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/fetch.yml +80 -0
  20. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance/list.yml +38 -0
  21. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/fetch.yml +26 -0
  22. data/spec/fixtures/bodies/GandiV5_SimpleHosting_Instance_VirtualHost/list.yml +18 -0
  23. data/spec/units/gandi_v5/domain_spec.rb +1 -1
  24. data/spec/units/gandi_v5/sharing_space_spec.rb +4 -0
  25. data/spec/units/gandi_v5/simple_hosting/instance/application_spec.rb +37 -0
  26. data/spec/units/gandi_v5/simple_hosting/instance/database_spec.rb +4 -0
  27. data/spec/units/gandi_v5/simple_hosting/instance/language_spec.rb +4 -0
  28. data/spec/units/gandi_v5/simple_hosting/instance/upgrade_spec.rb +4 -0
  29. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host/linked_dns_zone_spec.rb +50 -0
  30. data/spec/units/gandi_v5/simple_hosting/instance/virtual_host_spec.rb +199 -0
  31. data/spec/units/gandi_v5/simple_hosting/instance_spec.rb +182 -0
  32. data/spec/units/gandi_v5/simple_hosting_spec.rb +9 -0
  33. metadata +28 -8
  34. data/lib/gandi_v5/domain/sharing_space.rb +0 -29
  35. data/spec/units/gandi_v5/domain/sharing_space_spec.rb +0 -4
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class SimpleHosting
5
+ class Instance
6
+ # @!attribute [r] name
7
+ # @return [String]
8
+ # @!attribute [r] parameters
9
+ # @return [String]
10
+ # @!attribute [r] status
11
+ # @return [Symbol] :error, :running, :being_created, :cancelled
12
+ class Application
13
+ include GandiV5::Data
14
+
15
+ members :name, :parameters
16
+ member :status, converter: GandiV5::Data::Converter::Symbol
17
+
18
+ # Check if the appliaction is currently being created
19
+ # @return [Boolean]
20
+ def being_created?
21
+ status == :being_created
22
+ end
23
+
24
+ # Check if the appliaction has been cancelled
25
+ # @return [Boolean]
26
+ def cancelled?
27
+ status == :cancelled
28
+ end
29
+
30
+ # Check if the appliaction is running
31
+ # @return [Boolean]
32
+ def running?
33
+ status == :running
34
+ end
35
+
36
+ # Check if the appliaction is in an error condition
37
+ # @return [Boolean]
38
+ def error?
39
+ status == :error
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class SimpleHosting
5
+ class Instance
6
+ # @!attribute [r] name
7
+ # @return [String]
8
+ # @!attribute [r] status
9
+ # @return [String]
10
+ # @!attribute [r] version
11
+ # @return [String]
12
+ class Database
13
+ include GandiV5::Data
14
+
15
+ members :name, :status, :version
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class SimpleHosting
5
+ class Instance
6
+ # Sharing space which contains other billable items.
7
+ # @!attribute [r] name
8
+ # @return [String]
9
+ # @!attribute [r] single_application
10
+ # @return [Boolean]
11
+ # @!attribute [r] status
12
+ # @return [String]
13
+ # @!attribute [r] version
14
+ # @return [String]
15
+ class Language
16
+ include GandiV5::Data
17
+
18
+ members :name, :single_application, :status, :version
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class SimpleHosting
5
+ class Instance
6
+ # @!attribute [r] name
7
+ # @return [String]
8
+ # @!attribute [r] status
9
+ # @return [String]
10
+ # @!attribute [r] type
11
+ # @return [String] "database" or "language"
12
+ # @!attribute [r] version
13
+ # @return [String]
14
+ class Upgrade
15
+ include GandiV5::Data
16
+
17
+ members :name, :status, :type, :version
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,187 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Namespace for classes which access LiveDNS details.
4
+ class GandiV5
5
+ class SimpleHosting
6
+ class Instance
7
+ # A simple hosting virtual host.
8
+ # @see https://api.gandi.net/docs/simplehosting/
9
+ # @!attribute [r] created_at
10
+ # @return [Time]
11
+ # @!attribute [r] fqdn
12
+ # @return [String] fully qualified domain name of the virtual host.
13
+ # @!attribute [r] instance_uuid
14
+ # @return [String] UUID of the simple hosting instance which 'owns' the host.
15
+ # @!attribute [r] is_a_test_virtual_host
16
+ # @return [Boolean]
17
+ # @!attribute [r] status
18
+ # @return [Symbol] :being_created, :running, :being_deleted,
19
+ # :locked, :waiting_ownership, :ownership_validated,
20
+ # :validation_failed
21
+ # @!attribute [r] https_strategy
22
+ # @return [Symbol] :http_only, :allow_http_and_https,
23
+ # :redirect_http_to_https
24
+ # @!attribute [r] Application
25
+ # @return [GandiV5::SimpleHosting::Instance::Application]
26
+ # @!attribute [r] certificates
27
+ # @return [Hash<String => Boolean>] Hash - certificate ID to pendingness
28
+ # @!attribute [r] linked_dns_zone
29
+ # @return [GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone]
30
+ class VirtualHost
31
+ include GandiV5::Data
32
+
33
+ members :created_at, :fqdn, :instance_uuid
34
+
35
+ member :is_a_test_virtual_host, gandi_key: 'is_a_test_vhost'
36
+ member :status, converter: GandiV5::Data::Converter::Symbol
37
+
38
+ member(
39
+ :https_strategy,
40
+ converter: GandiV5::Data::Converter.new(from_gandi: ->(data) { data.downcase.to_sym })
41
+ )
42
+
43
+ member(
44
+ :application,
45
+ converter: GandiV5::SimpleHosting::Instance::Application
46
+ )
47
+
48
+ member(
49
+ :certificates,
50
+ converter: GandiV5::Data::Converter.new(
51
+ from_gandi: ->(array) { Hash[array.map { |h| [h['id'], h['pending']] }] }
52
+ )
53
+ )
54
+
55
+ member(
56
+ :linked_dns_zone,
57
+ converter: GandiV5::SimpleHosting::Instance::VirtualHost::LinkedDnsZone
58
+ )
59
+
60
+ # Requery Gandi fo this hosts's information.
61
+ # @return [GandiV5::SimpleHosting::Instance::VirtualHost]
62
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
63
+ def refresh
64
+ _response, data = GandiV5.get url
65
+ from_gandi data
66
+ end
67
+
68
+ # Check if the virtual host is being created
69
+ # @return [Boolean]
70
+ def being_created?
71
+ status == :being_created
72
+ end
73
+
74
+ # Check if the virtual host is running
75
+ # @return [Boolean]
76
+ def running?
77
+ status == :running
78
+ end
79
+
80
+ # Check if the virtual host is being deleted
81
+ # @return [Boolean]
82
+ def being_deleted?
83
+ status == :being_deleted
84
+ end
85
+
86
+ # Check if the virtual host is locked
87
+ # @return [Boolean]
88
+ def locked?
89
+ status == :locked
90
+ end
91
+
92
+ # Check if the virtual host is waiting for an ownership check
93
+ # @return [Boolean]
94
+ def waiting_ownership?
95
+ status == :waiting_ownership
96
+ end
97
+
98
+ # Check if the virtual host has it's ownership validated
99
+ # @return [Boolean]
100
+ def ownership_validated?
101
+ status == :ownership_validated
102
+ end
103
+
104
+ # Check if the virtual host failed it's ownership check
105
+ # @return [Boolean]
106
+ def validation_failed?
107
+ status == :validation_failed
108
+ end
109
+
110
+ # Check if the virtual host is serving HTTP only
111
+ # @return [Boolean]
112
+ def http_only?
113
+ https_strategy == :http_only
114
+ end
115
+
116
+ # Check if the virtual host is serving HTTP and HTTPS
117
+ # @return [Boolean]
118
+ def http_and_https?
119
+ https_strategy == :http_and_https
120
+ end
121
+
122
+ # Check if the virtual host is serving HTTPS and redirecting HTTP to HTTPS
123
+ # @return [Boolean]
124
+ def redirect_http_to_https?
125
+ https_strategy == :redirect_http_to_https
126
+ end
127
+
128
+ # Check if the virtual host is serving HTTP requests
129
+ # @return [Boolean]
130
+ def http?
131
+ https_strategy == :http_only || https_strategy == :http_and_https
132
+ end
133
+
134
+ # Check if the virtual host is serving HTTPS requests
135
+ # @return [Boolean]
136
+ def https?
137
+ https_strategy == :http_and_https
138
+ end
139
+
140
+ # Get information on a virtual host.
141
+ # @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts-vhost_fqdn
142
+ # @param uuid [String, #to_s] the UUID of the simple hosting instance.
143
+ # @param fqdn [String, #to_s] the fully qualified domain name of the virtual host.
144
+ # @return [GandiV5::SimpleHosting::Instance]
145
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
146
+ def self.fetch(instance_uuid, fqdn)
147
+ _response, data = GandiV5.get url(instance_uuid, fqdn)
148
+ from_gandi data.merge('instance_uuid' => instance_uuid)
149
+ end
150
+
151
+ # List instances.
152
+ # @see https://api.gandi.net/docs/simplehosting#get-v5-simplehosting-instances-instance_id-vhosts
153
+ # @param page [#each<Integer, #to_s>] the page(s) of results to retrieve.
154
+ # If page is not provided keep querying until an empty list is returned.
155
+ # If page responds to .each then iterate until an empty list is returned.
156
+ # @param per_page [Integer, #to_s] (optional default 100) how many results to get per page.
157
+ # @param status [String, #to_s] (optional)
158
+ # filter the list by the virtual host's status.
159
+ # @param fqdn [String, #to_s] (optional)
160
+ # filter the list by the virtual host's domain name, allows * as wildcard.
161
+ # @param sort_by [String, #to_s] (optional default "created_at")
162
+ # how to sort the list, prefix with a minus to reverse sort order.
163
+ # @return [Array<GandiV5::SimpleHosting::Instance::VirtualHost>]
164
+ # @raise [GandiV5::Error::GandiError] if Gandi returns an error.
165
+ def self.list(instance_uuid, page: (1..), per_page: 100, **params)
166
+ instances = []
167
+ GandiV5.paginated_get(url(instance_uuid), page, per_page, params: params) do |data|
168
+ instances += data.map { |item| from_gandi item.merge('instance_uuid' => instance_uuid) }
169
+ end
170
+ instances
171
+ end
172
+
173
+ private
174
+
175
+ def url
176
+ "#{BASE}simplehosting/instances/#{instance_uuid}/vhosts/#{CGI.escape(fqdn)}"
177
+ end
178
+
179
+ def self.url(instance_uuid, fqdn = nil)
180
+ "#{BASE}simplehosting/instances/#{instance_uuid}/vhosts" +
181
+ (fqdn ? "/#{CGI.escape fqdn}" : '')
182
+ end
183
+ private_class_method :url
184
+ end
185
+ end
186
+ end
187
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ class GandiV5
4
+ class SimpleHosting
5
+ class Instance
6
+ class VirtualHost
7
+ # @!attribute [r] allow_zone_alteration
8
+ # @return [Boolean]
9
+ # @!attribute [r] cname
10
+ # @return [String]
11
+ # @!attribute [r] domain
12
+ # @return [String]
13
+ # @!attribute [r] ipv4
14
+ # @return [String]
15
+ # @!attribute [r] ipv6
16
+ # @return [String]
17
+ # @!attribute [r] is_alterable
18
+ # @return [Boolean]
19
+ # @!attribute [r] is_root
20
+ # @return [Boolean]
21
+ # @!attribute [r] key
22
+ # @return [String]
23
+ # @!attribute [r] txt
24
+ # @return [String]
25
+ # @!attribute [r] last_checked_at
26
+ # @return [Time]
27
+ # @!attribute [r] status
28
+ # @return [Symbol] :altered, :livedns_conflict, :livedns_done, :livedns_error, :unknown
29
+ class LinkedDnsZone
30
+ include GandiV5::Data
31
+
32
+ members :allow_alteration, :is_alterable, :last_checked_at,
33
+ :cname, :domain, :is_root, :ipv4, :ipv6, :key, :txt
34
+
35
+ member(
36
+ :status,
37
+ gandi_key: 'last_checked_status',
38
+ converter: GandiV5::Data::Converter::Symbol
39
+ )
40
+
41
+ # Check if the linked zone is currently in an altered state
42
+ # @return [Boolean]
43
+ def altered?
44
+ status == :altered
45
+ end
46
+
47
+ # Check if the linked zone is currently in a conflicted state
48
+ # @return [Boolean]
49
+ def livedns_conflict?
50
+ status == :livedns_conflict
51
+ end
52
+
53
+ # Check if the linked zone has been updated
54
+ # @return [Boolean]
55
+ def livedns_done?
56
+ status == :livedns_done
57
+ end
58
+
59
+ # Check if the linked zone had an error updating
60
+ # @return [Boolean]
61
+ def livedns_error?
62
+ status == :livedns_error
63
+ end
64
+
65
+ # Check if the linked zone is in an unknown state
66
+ # @return [Boolean]
67
+ def unknown?
68
+ status == :unknown
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class GandiV5
4
- VERSION = '0.7.0'
4
+ VERSION = '0.8.0'
5
5
  end
@@ -1,11 +1,58 @@
1
- Metrics/BlockLength:
2
- Max: 750
1
+ require:
2
+ - rubocop-performance
3
+ AllCops:
4
+ TargetRubyVersion: 2.6.0
5
+ Layout/EmptyLinesAroundAttributeAccessor:
6
+ Enabled: true
3
7
  Layout/LineLength:
4
8
  Max: 125
9
+ Layout/SpaceAroundMethodCallOperator:
10
+ Enabled: true
11
+ Lint/DeprecatedOpenSSLConstant:
12
+ Enabled: true
13
+ Lint/MixedRegexpCaptureTypes:
14
+ Enabled: true
15
+ Lint/RaiseException:
16
+ Enabled: true
17
+ Lint/StructNewOverride:
18
+ Enabled: true
19
+ Metrics/BlockLength:
20
+ Max: 750
21
+ Performance/AncestorsInclude:
22
+ Enabled: true
23
+ Performance/BigDecimalWithNumericArgument:
24
+ Enabled: true
25
+ Performance/RedundantSortBlock:
26
+ Enabled: true
27
+ Performance/RedundantStringChars:
28
+ Enabled: true
29
+ Performance/ReverseFirst:
30
+ Enabled: true
31
+ Performance/SortReverse:
32
+ Enabled: true
33
+ Performance/Squeeze:
34
+ Enabled: true
35
+ Performance/StringInclude:
36
+ Enabled: true
37
+ Style/AccessorGrouping:
38
+ Enabled: true
39
+ Style/BisectedAttrAccessor:
40
+ Enabled: true
41
+ Style/ExponentialNotation:
42
+ Enabled: true
5
43
  Style/HashEachMethods:
6
44
  Enabled: true
7
45
  Style/HashTransformKeys:
8
46
  Enabled: true
9
47
  Style/HashTransformValues:
10
48
  Enabled: true
11
-
49
+ Style/RedundantAssignment:
50
+ Enabled: true
51
+ Style/RedundantFetchBlock:
52
+ Enabled: true
53
+ Style/RedundantRegexpCharacterClass:
54
+ Enabled: true
55
+ Style/RedundantRegexpEscape:
56
+ Enabled: true
57
+ Style/SlicingWithRange:
58
+ Enabled: true
@@ -0,0 +1,80 @@
1
+ ---
2
+ access_information:
3
+ admin_url: admin.example.com/
4
+ database:
5
+ admins:
6
+ - type: phpMyAdmin
7
+ url: admin.example.com/phpmyadmin
8
+ username: database admin username
9
+ host: database.example.com
10
+ port: 1234
11
+ socket: /socket/for/database
12
+ deploy:
13
+ - cli:
14
+ init: cli init string
15
+ git:
16
+ deploy: git deploy string
17
+ remote: git remote string
18
+ url: git url string
19
+ sftp:
20
+ directory: sftp directory
21
+ document_root: sftp document root
22
+ server: sftp server
23
+ url: sftp url
24
+ vhost:
25
+ fqdn: example.com
26
+ href: link/to/href/details/virtualhost-uuid
27
+ user: A user
28
+ available_upgrade: false
29
+ console:
30
+ enabled: true
31
+ url: console.example.com/
32
+ created_at: 2020-01-02T12:34:56+00
33
+ database:
34
+ name: database name
35
+ status: database status
36
+ version: database version
37
+ datacenter:
38
+ code: FR-SD5
39
+ name: SD5
40
+ region: FR
41
+ expire_at: 2021-01-02T12:34:56+00
42
+ id: instance-uuid
43
+ is_trial: false
44
+ language:
45
+ name: ruby
46
+ single_application: true
47
+ status: great
48
+ version: "2.7"
49
+ name: instance name
50
+ sharing_space:
51
+ id: sharing-space-uuid
52
+ name: sharing space name
53
+ size: s+
54
+ snapshot_enabled: true
55
+ status: active
56
+ storage:
57
+ additional:
58
+ unit: GB
59
+ value: 10
60
+ base:
61
+ unit: GB
62
+ value: 20
63
+ total:
64
+ unit: GB
65
+ value: 30
66
+ vhosts:
67
+ - fqdn: vhost1.example.com
68
+ href: link/to.vhost/details
69
+ autorenew:
70
+ duration: 1
71
+ duration_type: m
72
+ compatible_applications:
73
+ - name: compatable name
74
+ parameters: {}
75
+ password_updated_at: 2020-06-02T12:34:56+00
76
+ upgrade_to:
77
+ - name: upgrade to name
78
+ status: upgrade to status
79
+ type: database
80
+ version: upgrade to version