onlyoffice_digitalocean_wrapper 0.7.0 → 0.9.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
  SHA256:
3
- metadata.gz: 722a209dd7c530acc9eca5dc95af3482ce07b031f1d60458f0fd4f60d68d97f1
4
- data.tar.gz: 2176a7c8518150703d75437360e757e2be7e6ed770affb877fb02dfc362f2124
3
+ metadata.gz: 36e4b1f04e6c0aebdbfeb107f577a367bf298c8c4004955734110db26b01b7a6
4
+ data.tar.gz: 375770be15fc82e73619aab137d83ab5e8824a1a6097854064c63e42588471c2
5
5
  SHA512:
6
- metadata.gz: efec409153d5b1d2c94d8ef541ed957f708869b5096c42371224d389adab3d7282d0eccb0e56bb40a30dc6e5a43989eae1c2aeb73830346138f9f20511424e31
7
- data.tar.gz: 5680e5bc73b4fd25f402fa18de9b788008710ef00fac98dff796e958e1e3e45c682563eeeb169a5b2871af8898a7247e975c81b5f1bf91fe793cb5448714bf6e
6
+ metadata.gz: 8eaeba9c86ab045ceb854020ac05f6fb4672e2931b9485ddc5284800afd1d6d7a6e024198032c04be38a17a3d4e4d2bcc4259614f86f15976787c5527c38409d
7
+ data.tar.gz: 300403c3cb2ac438cc7f8c4a57853034ed28d5eb77a3c2109bd1b0a8aeac45ff03e1d0896098a6d412fe2e11d2c4f64a7757618f4f4b3ed6c839a580ffef8e18
@@ -15,7 +15,7 @@ module OnlyofficeDigitaloceanWrapper
15
15
  yield
16
16
  rescue exception => e
17
17
  try += 1
18
- logger.error("Error '#{exception}, #{e}' happened during "\
18
+ logger.error("Error '#{exception}, #{e}' happened during " \
19
19
  "operation. Retrying #{try} of #{retries}")
20
20
  sleep timeout # Time to cooldown error
21
21
  try <= retries ? retry : raise
@@ -93,14 +93,5 @@ module OnlyofficeDigitaloceanWrapper
93
93
  end
94
94
  end
95
95
  end
96
-
97
- # Get public ip of droplet
98
- # @param [DropletKit] droplet to get ip
99
- # @return [String] public ip
100
- def public_ip(droplet)
101
- networks = droplet.networks.to_a.first
102
- public_network = networks.find { |net| net.type == 'public' }
103
- public_network.ip_address
104
- end
105
96
  end
106
97
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeDigitaloceanWrapper
4
+ # Get methods for IP
5
+ module IpGetters
6
+ # Get ip of droplet
7
+ # @param [DropletKit] droplet to get ip
8
+ # @param [String] network_type to get ip
9
+ # @return [String, nil] ip of droplet or `nil` if there is no such network
10
+ def droplet_ip(droplet, network_type = 'public')
11
+ networks = droplet.networks.to_a.first
12
+ specific_network = networks.find { |net| net.type == network_type }
13
+ return nil unless specific_network
14
+
15
+ specific_network.ip_address
16
+ end
17
+
18
+ # Get public ip of droplet
19
+ # @param [DropletKit] droplet to get ip
20
+ # @return [String, nil] public ip or `nil` if there is no such network
21
+ def public_ip(droplet)
22
+ droplet_ip(droplet, 'public')
23
+ end
24
+ end
25
+ end
@@ -20,7 +20,9 @@ module OnlyofficeDigitaloceanWrapper
20
20
  # @return [String] token
21
21
  def read_token(token_file_path: "#{Dir.home}/.do/access_token",
22
22
  force_file_read: false)
23
- return ENV['DO_ACCESS_TOKEN'] if ENV['DO_ACCESS_TOKEN'] && !force_file_read
23
+ # rubocop:disable Style/FetchEnvVar
24
+ return ENV['DO_ACCESS_TOKEN'] if ENV.key?('DO_ACCESS_TOKEN') && !force_file_read
25
+ # rubocop:enable Style/FetchEnvVar
24
26
 
25
27
  File.read(token_file_path).delete("\n")
26
28
  rescue Errno::ENOENT
@@ -4,6 +4,7 @@ require 'droplet_kit'
4
4
  require_relative 'digitalocean_wrapper/digitalocean_exceptions'
5
5
  require_relative 'digitalocean_wrapper/exceptions_retryer'
6
6
  require_relative 'digitalocean_wrapper/getters'
7
+ require_relative 'digitalocean_wrapper/ip_getters'
7
8
  require_relative 'digitalocean_wrapper/logger_wrapper'
8
9
  require_relative 'digitalocean_wrapper/power_actions'
9
10
  require_relative 'digitalocean_wrapper/token_methods'
@@ -13,6 +14,7 @@ module OnlyofficeDigitaloceanWrapper
13
14
  # Class for wrapping DigitalOcean API gem
14
15
  class DigitalOceanWrapper
15
16
  include Getters
17
+ include IpGetters
16
18
  include LoggerWrapper
17
19
  include ExceptionsRetryer
18
20
  include PowerActions
@@ -31,15 +33,18 @@ module OnlyofficeDigitaloceanWrapper
31
33
  # Wait until droplet has status
32
34
  # @param droplet_name [String] name of droplet
33
35
  # @param status [String] status to wait
34
- # @param params [Hash] additiona params
36
+ # @param params [Hash] additional params
37
+ # @option params [Integer] :timeout (300) maximum time to wait in seconds
38
+ # @option params [Integer] :interval (10) interval time between status checks in seconds
35
39
  # @return [Symbol] droplet status after wait over
36
40
  def wait_until_droplet_have_status(droplet_name, status = 'active', params = {})
37
41
  timeout = params.fetch(:timeout, 300)
42
+ interval = params.fetch(:interval, 10)
38
43
  counter = 0
39
44
  while get_droplet_status_by_name(droplet_name) != status && counter < timeout
40
- counter += 10
41
- sleep 10
42
- logger.info("waiting for droplet (#{droplet_name}) to have "\
45
+ counter += interval
46
+ sleep(interval)
47
+ logger.info("waiting for droplet (#{droplet_name}) to have " \
43
48
  "status: #{status} for #{counter} seconds of #{timeout}")
44
49
  end
45
50
  raise DropletOperationTimeout, "#{droplet_name} was not #{status} for #{timeout}s" if counter >= timeout
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OnlyofficeDigitaloceanWrapper
4
+ # Class raised if droplet ssh is not up for defined timeout
5
+ class SshCheckerSshUpTimeout < StandardError
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net-telnet'
4
+
5
+ require_relative 'ssh_checker/ssh_checker_exceptions'
6
+
7
+ module OnlyofficeDigitaloceanWrapper
8
+ # Class for check if ssh can be connected
9
+ class SshChecker
10
+ include LoggerWrapper
11
+ # @return [String] ip of server
12
+ attr_reader :ip
13
+
14
+ # @param ip [String] ip of server to check
15
+ def initialize(ip)
16
+ @ip = ip
17
+ end
18
+
19
+ # Wait until ssh server on server is up and available for connection
20
+ # @param timeout [Integer] how much we should wait for connection
21
+ # @return [void]
22
+ def wait_until_ssh_up(timeout: 60)
23
+ wait_between_tries = 5
24
+ tries = timeout / wait_between_tries
25
+ tries.times do |try|
26
+ if ssh_up?
27
+ logger.info("SSH on `#{@ip}` is up. Waiting finished")
28
+ return true
29
+ end
30
+
31
+ logger.info("SSH on `#{@ip}` is not up. Waited for #{try * wait_between_tries} seconds of #{timeout}")
32
+ sleep wait_between_tries
33
+ end
34
+ raise SshCheckerSshUpTimeout, "SSH on `#{@ip}` is not up for #{timeout} seconds. Could not proceed"
35
+ end
36
+
37
+ # Check is ssh available for connection right now
38
+ # @return [Boolean]
39
+ def ssh_up?
40
+ Net::Telnet.new('Host' => @ip,
41
+ 'Timeout' => 1,
42
+ 'Port' => 22)
43
+ true
44
+ rescue StandardError
45
+ false
46
+ end
47
+ end
48
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module OnlyofficeDigitaloceanWrapper
4
4
  # @return [String] version of gem
5
- VERSION = '0.7.0'
5
+ VERSION = '0.9.0'
6
6
  # @return [String] name of gem
7
7
  NAME = 'onlyoffice_digitalocean_wrapper'
8
8
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'onlyoffice_digitalocean_wrapper/digitalocean_wrapper'
4
+ require_relative 'onlyoffice_digitalocean_wrapper/ssh_checker'
4
5
  require_relative 'onlyoffice_digitalocean_wrapper/version'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onlyoffice_digitalocean_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ONLYOFFICE
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-07-29 00:00:00.000000000 Z
13
+ date: 2024-07-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: droplet_kit
@@ -27,131 +27,19 @@ dependencies:
27
27
  - !ruby/object:Gem::Version
28
28
  version: '3'
29
29
  - !ruby/object:Gem::Dependency
30
- name: codecov
30
+ name: net-telnet
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
35
  version: '0'
36
- type: :development
37
- prerelease: false
38
- version_requirements: !ruby/object:Gem::Requirement
39
- requirements:
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '0'
43
- - !ruby/object:Gem::Dependency
44
- name: overcommit
45
- requirement: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '0'
50
- type: :development
51
- prerelease: false
52
- version_requirements: !ruby/object:Gem::Requirement
53
- requirements:
54
- - - "~>"
55
- - !ruby/object:Gem::Version
56
- version: '0'
57
- - !ruby/object:Gem::Dependency
58
- name: rake
59
- requirement: !ruby/object:Gem::Requirement
60
- requirements:
61
- - - "~>"
62
- - !ruby/object:Gem::Version
63
- version: '13.0'
64
- type: :development
65
- prerelease: false
66
- version_requirements: !ruby/object:Gem::Requirement
67
- requirements:
68
- - - "~>"
69
- - !ruby/object:Gem::Version
70
- version: '13.0'
71
- - !ruby/object:Gem::Dependency
72
- name: rspec
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - "~>"
76
- - !ruby/object:Gem::Version
77
- version: '3'
78
- type: :development
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - "~>"
83
- - !ruby/object:Gem::Version
84
- version: '3'
85
- - !ruby/object:Gem::Dependency
86
- name: rubocop
87
- requirement: !ruby/object:Gem::Requirement
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- version: 0.49.0
92
- type: :development
93
- prerelease: false
94
- version_requirements: !ruby/object:Gem::Requirement
95
- requirements:
96
- - - ">="
97
- - !ruby/object:Gem::Version
98
- version: 0.49.0
99
- - !ruby/object:Gem::Dependency
100
- name: rubocop-performance
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - "~>"
104
- - !ruby/object:Gem::Version
105
- version: '1'
106
- type: :development
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: '1'
113
- - !ruby/object:Gem::Dependency
114
- name: rubocop-rake
115
- requirement: !ruby/object:Gem::Requirement
116
- requirements:
117
- - - "~>"
118
- - !ruby/object:Gem::Version
119
- version: '0'
120
- type: :development
36
+ type: :runtime
121
37
  prerelease: false
122
38
  version_requirements: !ruby/object:Gem::Requirement
123
39
  requirements:
124
40
  - - "~>"
125
41
  - !ruby/object:Gem::Version
126
42
  version: '0'
127
- - !ruby/object:Gem::Dependency
128
- name: rubocop-rspec
129
- requirement: !ruby/object:Gem::Requirement
130
- requirements:
131
- - - "~>"
132
- - !ruby/object:Gem::Version
133
- version: '2'
134
- type: :development
135
- prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- requirements:
138
- - - "~>"
139
- - !ruby/object:Gem::Version
140
- version: '2'
141
- - !ruby/object:Gem::Dependency
142
- name: yard
143
- requirement: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - ">="
146
- - !ruby/object:Gem::Version
147
- version: 0.9.20
148
- type: :development
149
- prerelease: false
150
- version_requirements: !ruby/object:Gem::Requirement
151
- requirements:
152
- - - ">="
153
- - !ruby/object:Gem::Version
154
- version: 0.9.20
155
43
  description: Wrapper gem for DigitalOcean. Use in testing projects
156
44
  email:
157
45
  - shockwavenn@gmail.com
@@ -165,9 +53,12 @@ files:
165
53
  - lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/digitalocean_exceptions.rb
166
54
  - lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/exceptions_retryer.rb
167
55
  - lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/getters.rb
56
+ - lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/ip_getters.rb
168
57
  - lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/logger_wrapper.rb
169
58
  - lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/power_actions.rb
170
59
  - lib/onlyoffice_digitalocean_wrapper/digitalocean_wrapper/token_methods.rb
60
+ - lib/onlyoffice_digitalocean_wrapper/ssh_checker.rb
61
+ - lib/onlyoffice_digitalocean_wrapper/ssh_checker/ssh_checker_exceptions.rb
171
62
  - lib/onlyoffice_digitalocean_wrapper/version.rb
172
63
  homepage: https://github.com/ONLYOFFICE-QA/onlyoffice_digitalocean_wrapper
173
64
  licenses:
@@ -178,6 +69,7 @@ metadata:
178
69
  documentation_uri: https://www.rubydoc.info/gems/onlyoffice_digitalocean_wrapper
179
70
  homepage_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_digitalocean_wrapper
180
71
  source_code_uri: https://github.com/ONLYOFFICE-QA/onlyoffice_digitalocean_wrapper
72
+ rubygems_mfa_required: 'true'
181
73
  post_install_message:
182
74
  rdoc_options: []
183
75
  require_paths:
@@ -186,14 +78,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
78
  requirements:
187
79
  - - ">="
188
80
  - !ruby/object:Gem::Version
189
- version: '2.5'
81
+ version: '3.0'
190
82
  required_rubygems_version: !ruby/object:Gem::Requirement
191
83
  requirements:
192
84
  - - ">="
193
85
  - !ruby/object:Gem::Version
194
86
  version: '0'
195
87
  requirements: []
196
- rubygems_version: 3.2.22
88
+ rubygems_version: 3.5.6
197
89
  signing_key:
198
90
  specification_version: 4
199
91
  summary: Wrapper gem for DigitalOcean