capistrano-data_plane_api 0.1.4 → 0.2.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 (90) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -2
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +6 -0
  5. data/Gemfile +7 -4
  6. data/Gemfile.lock +108 -69
  7. data/README.md +5 -0
  8. data/capistrano-data_plane_api.gemspec +5 -2
  9. data/exe/cap_data_plane_api +3 -2
  10. data/lib/capistrano/data_plane_api/configuration/backend.rb +2 -0
  11. data/lib/capistrano/data_plane_api/configuration/server.rb +4 -2
  12. data/lib/capistrano/data_plane_api/configuration/symbol.rb +2 -0
  13. data/lib/capistrano/data_plane_api/configuration.rb +3 -3
  14. data/lib/capistrano/data_plane_api/deploy/args.rb +71 -40
  15. data/lib/capistrano/data_plane_api/deploy/deployment_stats.rb +29 -25
  16. data/lib/capistrano/data_plane_api/deploy/group.rb +33 -24
  17. data/lib/capistrano/data_plane_api/deploy/helper.rb +3 -5
  18. data/lib/capistrano/data_plane_api/deploy/server_stats.rb +60 -43
  19. data/lib/capistrano/data_plane_api/deploy.rb +3 -2
  20. data/lib/capistrano/data_plane_api/diggable.rb +5 -2
  21. data/lib/capistrano/data_plane_api/equatable.rb +4 -2
  22. data/lib/capistrano/data_plane_api/helper.rb +31 -27
  23. data/lib/capistrano/data_plane_api/hooks.rb +1 -0
  24. data/lib/capistrano/data_plane_api/show_state.rb +15 -12
  25. data/lib/capistrano/data_plane_api/tasks.rb +26 -2
  26. data/lib/capistrano/data_plane_api/terminal_print_loop.rb +7 -4
  27. data/lib/capistrano/data_plane_api/type.rb +9 -5
  28. data/lib/capistrano/data_plane_api/version.rb +2 -2
  29. data/lib/capistrano/data_plane_api.rb +96 -74
  30. data/lib/capistrano-data_plane_api.rb +4 -0
  31. data/rbi/capistrano-data_plane_api.rbi +283 -0
  32. data/sorbet/config +6 -0
  33. data/sorbet/rbi/annotations/.gitattributes +1 -0
  34. data/sorbet/rbi/annotations/faraday.rbi +17 -0
  35. data/sorbet/rbi/annotations/minitest.rbi +119 -0
  36. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  37. data/sorbet/rbi/annotations/webmock.rbi +9 -0
  38. data/sorbet/rbi/dsl/.gitattributes +1 -0
  39. data/sorbet/rbi/dsl/capistrano/data_plane_api/configuration/backend.rbi +50 -0
  40. data/sorbet/rbi/dsl/capistrano/data_plane_api/configuration/server.rbi +24 -0
  41. data/sorbet/rbi/dsl/capistrano/data_plane_api/configuration.rbi +52 -0
  42. data/sorbet/rbi/dsl/capistrano/data_plane_api/type.rbi +12 -0
  43. data/sorbet/rbi/gems/.gitattributes +1 -0
  44. data/sorbet/rbi/gems/addressable@2.8.7.rbi +1994 -0
  45. data/sorbet/rbi/gems/ast@2.4.3.rbi +585 -0
  46. data/sorbet/rbi/gems/base64@0.2.0.rbi +509 -0
  47. data/sorbet/rbi/gems/bigdecimal@3.1.9.rbi +8 -0
  48. data/sorbet/rbi/gems/booleans@0.1.3.rbi +28 -0
  49. data/sorbet/rbi/gems/byebug@12.0.0.rbi +37 -0
  50. data/sorbet/rbi/gems/crack@1.0.0.rbi +145 -0
  51. data/sorbet/rbi/gems/data_plane_api@0.2.0.rbi +238 -0
  52. data/sorbet/rbi/gems/faraday-net_http@3.4.0.rbi +147 -0
  53. data/sorbet/rbi/gems/faraday@2.13.0.rbi +2974 -0
  54. data/sorbet/rbi/gems/hashdiff@1.1.2.rbi +353 -0
  55. data/sorbet/rbi/gems/json@2.10.2.rbi +2113 -0
  56. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +240 -0
  57. data/sorbet/rbi/gems/logger@1.7.0.rbi +963 -0
  58. data/sorbet/rbi/gems/minitest@5.25.5.rbi +1547 -0
  59. data/sorbet/rbi/gems/net-http@0.6.0.rbi +4247 -0
  60. data/sorbet/rbi/gems/parallel@1.26.3.rbi +291 -0
  61. data/sorbet/rbi/gems/pastel@0.8.0.rbi +733 -0
  62. data/sorbet/rbi/gems/public_suffix@6.0.1.rbi +936 -0
  63. data/sorbet/rbi/gems/racc@1.8.1.rbi +160 -0
  64. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +404 -0
  65. data/sorbet/rbi/gems/rake@13.0.6.rbi +3030 -0
  66. data/sorbet/rbi/gems/rexml@3.4.1.rbi +5346 -0
  67. data/sorbet/rbi/gems/rubocop-espago@1.1.8.rbi +9 -0
  68. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1318 -0
  69. data/sorbet/rbi/gems/shale-builder@0.2.4.rbi +9 -0
  70. data/sorbet/rbi/gems/shale@1.2.2.rbi +2323 -0
  71. data/sorbet/rbi/gems/shoulda-context@2.0.0.rbi +563 -0
  72. data/sorbet/rbi/gems/strings-ansi@0.2.0.rbi +178 -0
  73. data/sorbet/rbi/gems/strings@0.2.1.rbi +830 -0
  74. data/sorbet/rbi/gems/thor@1.2.1.rbi +3957 -0
  75. data/sorbet/rbi/gems/tty-box@0.7.0.rbi +593 -0
  76. data/sorbet/rbi/gems/tty-color@0.6.0.rbi +241 -0
  77. data/sorbet/rbi/gems/tty-cursor@0.7.1.rbi +443 -0
  78. data/sorbet/rbi/gems/unicode-display_width@2.6.0.rbi +66 -0
  79. data/sorbet/rbi/gems/unicode_utils@1.4.0.rbi +184 -0
  80. data/sorbet/rbi/gems/uri@1.0.3.rbi +2349 -0
  81. data/sorbet/rbi/gems/vcr@6.3.1.rbi +3040 -0
  82. data/sorbet/rbi/gems/webmock@3.25.1.rbi +1792 -0
  83. data/sorbet/rbi/shims/gems/faraday.rbi +21 -0
  84. data/sorbet/rbi/shims/gems/shoulda-context@2.0.0.rbi +15 -0
  85. data/sorbet/rbi/todo.rbi +7 -0
  86. data/sorbet/tapioca/config.yml +28 -0
  87. data/sorbet/tapioca/extensions/load_gem.rb +1 -0
  88. data/sorbet/tapioca/require.rb +4 -0
  89. data/templates/bin/deploy.rb +1 -0
  90. metadata +106 -8
@@ -1,5 +1,7 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
4
+ require 'sorbet-runtime'
3
5
  require 'data_plane_api'
4
6
  require 'pastel'
5
7
  require 'pathname'
@@ -25,11 +27,10 @@ module Capistrano
25
27
  class NoSuchBackendError < Error; end
26
28
  class NoBackendForThisStageError < Error; end
27
29
 
28
- # @return [Pastel::Delegator]
29
- COLORS = ::Pastel.new
30
+ COLORS = T.let(::Pastel.new, T.untyped) # rubocop:disable Sorbet/ForbidTUntyped
30
31
 
31
32
  class << self
32
- # @return [Capistrano::DataPlaneApi::Configuration]
33
+ #: -> Configuration
33
34
  def configuration
34
35
  raise NotConfiguredError, <<~ERR unless @configuration
35
36
  `Capistrano::DataPlaneApi` is not configured!
@@ -40,7 +41,7 @@ module Capistrano
40
41
  @configuration
41
42
  end
42
43
 
43
- # @param val [Capistrano::DataPlaneApi::Configuration, Hash{String, Symbol => Object}, String, Pathname]
44
+ #: (Configuration | Hash[String | Symbol, Object] | String | Pathname) -> void
44
45
  def configuration=(val)
45
46
  case val
46
47
  when ::Hash
@@ -54,17 +55,13 @@ module Capistrano
54
55
  @configuration = val
55
56
  when ::String, ::Pathname
56
57
  @configuration = Configuration.from_file(val.to_s)
57
- @configuration.file_path = val
58
- else
59
- raise ::ArgumentError,
60
- "Configuration should be a `#{::Hash}`, `#{Configuration}`, #{::String} or #{::Pathname}" \
61
- ", received: #{val.inspect} (#{val.class.inspect})"
58
+ @configuration.file_path = val.to_s
62
59
  end
63
60
  end
64
61
 
65
62
  # Prints the current configuration in a human readable format.
66
63
  #
67
- # @return [void]
64
+ #: -> void
68
65
  def show_config
69
66
  puts ::JSON.pretty_generate(configuration.to_h)
70
67
  end
@@ -72,7 +69,7 @@ module Capistrano
72
69
  # Prints the current state of all backends and
73
70
  # their servers in a human readable format.
74
71
  #
75
- # @return [void]
72
+ #: -> void
76
73
  def show_state
77
74
  TerminalPrintLoop.call do
78
75
  ShowState.call
@@ -81,32 +78,32 @@ module Capistrano
81
78
 
82
79
  # Set server's admin_state to `drain`.
83
80
  #
84
- # @param deployment_stage [Symbol]
85
- # @param force [Boolean] Change the server's state even when no other server is `up`
86
- # @param config [::DataPlaneApi::Configuration, nil]
87
- # @return [Hash, FalseClass] Server state after the change, or `false`
81
+ # @param force: Change the server's state even when no other server is `up`
82
+ # @return: Server state after the change, or `nil`
88
83
  # when no change happened
89
84
  # @raise [Error] The process failed due to some reason
85
+ #: (String | Symbol, bool, ::DataPlaneApi::Configuration?) -> Hash[String, untyped]?
90
86
  def server_set_drain(deployment_stage, force: false, config: nil)
91
87
  haproxy_server, haproxy_backend = find_server_and_backend(deployment_stage)
92
- return false if haproxy_backend.servers.length < 2 # skip HAProxy if there is only a single server
88
+ servers = T.must haproxy_backend.servers
89
+ return if servers.length < 2 # skip HAProxy if there is only a single server
93
90
 
94
91
  validate_backend_state(haproxy_backend, haproxy_server) unless force
95
92
 
96
93
  conf = ::DataPlaneApi::Configuration.new(
97
- basic_user: haproxy_backend.basic_user || @configuration.basic_user,
94
+ basic_user: haproxy_backend.basic_user || @configuration.basic_user,
98
95
  basic_password: haproxy_backend.basic_password || @configuration.basic_password,
99
- parent: config,
100
- url: configuration.api_url
96
+ parent: config,
97
+ url: configuration.api_url,
101
98
  )
102
99
 
103
100
  # set the target server's state to `drain`
104
101
  response =
105
102
  ::DataPlaneApi::Server.update_transient_settings(
106
- backend: haproxy_backend.name,
107
- name: haproxy_server.name,
103
+ backend: haproxy_backend.name,
104
+ name: haproxy_server.name,
108
105
  settings: { admin_state: :drain },
109
- config: conf
106
+ config: conf,
110
107
  )
111
108
 
112
109
  unless response.status.between?(200, 299) && response.body['admin_state'] == 'drain'
@@ -119,32 +116,31 @@ module Capistrano
119
116
 
120
117
  # Set server's admin_state to `maint`.
121
118
  #
122
- # @param deployment_stage [Symbol]
123
- # @param force [Boolean] Change the server's state even when no other server is `up`
124
- # @param config [::DataPlaneApi::Configuration, nil]
125
- # @return [Hash, FalseClass] Server state after the change, or `false`
126
- # when no change happened
119
+ # @param force: Change the server's state even when no other server is `up`
120
+ # @return: Server state after the change, or `nil` when no change happened
127
121
  # @raise [Error] The process failed due to some reason
122
+ #: (String | Symbol, bool, ::DataPlaneApi::Configuration?) -> Hash[String, untyped]?
128
123
  def server_set_maint(deployment_stage, force: false, config: nil)
129
124
  haproxy_server, haproxy_backend = find_server_and_backend(deployment_stage)
130
- return false if haproxy_backend.servers.length < 2 # skip HAProxy if there is only a single server
125
+ servers = T.must haproxy_backend.servers
126
+ return if servers.length < 2 # skip HAProxy if there is only a single server
131
127
 
132
128
  validate_backend_state(haproxy_backend, haproxy_server) unless force
133
129
 
134
130
  conf = ::DataPlaneApi::Configuration.new(
135
- basic_user: haproxy_backend.basic_user || @configuration.basic_user,
131
+ basic_user: haproxy_backend.basic_user || @configuration.basic_user,
136
132
  basic_password: haproxy_backend.basic_password || @configuration.basic_password,
137
- parent: config,
138
- url: configuration.api_url
133
+ parent: config,
134
+ url: configuration.api_url,
139
135
  )
140
136
 
141
137
  # set the target server's state to `maint`
142
138
  response =
143
139
  ::DataPlaneApi::Server.update_transient_settings(
144
- backend: haproxy_backend.name,
145
- name: haproxy_server.name,
140
+ backend: haproxy_backend.name,
141
+ name: haproxy_server.name,
146
142
  settings: { admin_state: :maint },
147
- config: conf
143
+ config: conf,
148
144
  )
149
145
 
150
146
  unless response.status.between?(200, 299) && response.body['admin_state'] == 'maint'
@@ -157,29 +153,28 @@ module Capistrano
157
153
 
158
154
  # Set server's admin_state to `ready`
159
155
  #
160
- # @param deployment_stage [Symbol]
161
- # @param config [::DataPlaneApi::Configuration, nil]
162
- # @return [Hash, FalseClass] Server state after the change, or `false`
163
- # when no change happened
156
+ # @return: Server state after the change, or `nil` when no change happened
164
157
  # @raise [Error] The process failed due to some reason
158
+ #: (String | Symbol, ::DataPlaneApi::Configuration?) -> Hash[String, untyped]?
165
159
  def server_set_ready(deployment_stage, config: nil)
166
160
  haproxy_server, haproxy_backend = find_server_and_backend(deployment_stage)
167
- return false if haproxy_backend.servers.length < 2 # skip HAProxy if there is only a single server
161
+ servers = T.must haproxy_backend.servers
162
+ return if servers.length < 2 # skip HAProxy if there is only a single server
168
163
 
169
164
  conf = ::DataPlaneApi::Configuration.new(
170
- basic_user: haproxy_backend.basic_user || @configuration.basic_user,
165
+ basic_user: haproxy_backend.basic_user || @configuration.basic_user,
171
166
  basic_password: haproxy_backend.basic_password || @configuration.basic_password,
172
- parent: config,
173
- url: configuration.api_url
167
+ parent: config,
168
+ url: configuration.api_url,
174
169
  )
175
170
 
176
171
  # set the target server's state to `drain`
177
172
  response =
178
173
  ::DataPlaneApi::Server.update_transient_settings(
179
- backend: haproxy_backend.name,
180
- name: haproxy_server.name,
174
+ backend: haproxy_backend.name,
175
+ name: haproxy_server.name,
181
176
  settings: { admin_state: :ready },
182
- config: conf
177
+ config: conf,
183
178
  )
184
179
 
185
180
  unless response.status.between?(200, 299) &&
@@ -193,13 +188,26 @@ module Capistrano
193
188
  response.body
194
189
  end
195
190
 
191
+ # Get the state of the server.
192
+ #
193
+ # @return: Server state
194
+ # @raise [Error] The process failed due to some reason
195
+ #: (String | Symbol, ::DataPlaneApi::Configuration?) -> Hash[String, untyped]?
196
+ def server_get_state(deployment_stage, config: nil)
197
+ haproxy_server, haproxy_backend = find_server_and_backend(deployment_stage)
198
+
199
+ # set the target server's state to `drain`
200
+ response = get_server_settings(T.must(haproxy_backend.name), T.must(haproxy_server.name), config: config)
201
+ response.body
202
+ end
203
+
196
204
  # Find the HAProxy backend config with a particular name.
197
205
  #
198
- # @param backend_name [String]
199
- # @return [Capistrano::DataPlaneApi::Configuration::Backend] HAProxy backend config.
206
+ # @return: HAProxy backend config.
200
207
  # @raise [NoSuchBackendError] There is no backend with this name.
208
+ #: (Symbol | String) -> Configuration::Backend
201
209
  def find_backend(backend_name)
202
- backend = configuration.backends.find { _1.name == backend_name }
210
+ backend = configuration.backends&.find { _1.name == backend_name }
203
211
  if backend.nil?
204
212
  raise NoSuchBackendError,
205
213
  'There is no HAProxy backend with this name! ' \
@@ -212,21 +220,20 @@ module Capistrano
212
220
  # Find the server and backend config for a particular
213
221
  # deployment stage.
214
222
  #
215
- # @param deployment_stage [Symbol, String]
216
- # @return [Capistrano::DataPlaneApi::Configuration::Server, Capistrano::DataPlaneApi::Configuration::Backend]
223
+ # @return:
217
224
  # Two-element Array
218
225
  # where the first element is the HAProxy server config and the second one
219
226
  # is the HAProxy backend config
227
+ #: (Symbol | String) -> [Configuration::Server, Configuration::Backend]
220
228
  def find_server_and_backend(deployment_stage)
221
- # @type [Capistrano::DataPlaneApi::Configuration::Server, nil]
222
- haproxy_server = nil
229
+ haproxy_server = T.let(nil, T.nilable(Configuration::Server))
223
230
  deployment_stage_str = deployment_stage.to_s
231
+
224
232
  # find the HAProxy backend that the
225
233
  # current deployment target is a part of
226
- # @type [Capistrano::DataPlaneApi::Configuration::Backend]
227
234
  haproxy_backend =
228
- configuration.backends.each do |backend|
229
- haproxy_server = backend.servers.find { _1.stage == deployment_stage_str }
235
+ configuration.backends&.each do |backend|
236
+ haproxy_server = backend.servers&.find { _1.stage == deployment_stage_str }
230
237
  break backend if haproxy_server
231
238
  end
232
239
 
@@ -236,21 +243,22 @@ module Capistrano
236
243
  "#{deployment_stage.inspect} `#{configuration.file_path.inspect}`"
237
244
  end
238
245
 
239
- [haproxy_server, haproxy_backend]
246
+ [T.must(haproxy_server), haproxy_backend]
240
247
  end
241
248
 
242
- # @param backend_name [String]
243
- # @param config [::DataPlaneApi::Configuration, nil]
244
- # @return [Faraday::Response]
249
+ #: (Symbol | String, ::DataPlaneApi::Configuration?) -> Faraday::Response
245
250
  def get_backend_servers_settings(backend_name, config: nil)
246
251
  haproxy_backend = find_backend(backend_name)
247
252
  conf = ::DataPlaneApi::Configuration.new(
248
- basic_user: haproxy_backend.basic_user || @configuration.basic_user,
253
+ basic_user: haproxy_backend.basic_user || @configuration.basic_user,
249
254
  basic_password: haproxy_backend.basic_password || @configuration.basic_password,
250
- parent: config,
251
- url: configuration.api_url
255
+ parent: config,
256
+ url: configuration.api_url,
257
+ )
258
+ response = ::DataPlaneApi::Server.get_runtime_settings(
259
+ backend: backend_name.to_s,
260
+ config: conf,
252
261
  )
253
- response = ::DataPlaneApi::Server.get_runtime_settings(backend: backend_name, config: conf)
254
262
  unless response.status.between?(200, 299)
255
263
  raise QueryError,
256
264
  "HAProxy query failed! Couldn't fetch servers' states"
@@ -259,21 +267,35 @@ module Capistrano
259
267
  response
260
268
  end
261
269
 
270
+ #: (Symbol | String, Symbol | String, ::DataPlaneApi::Configuration?) -> Faraday::Response
271
+ def get_server_settings(backend_name, server_name, config: nil)
272
+ haproxy_backend = find_backend(backend_name)
273
+ conf = ::DataPlaneApi::Configuration.new(
274
+ basic_user: haproxy_backend.basic_user || @configuration.basic_user,
275
+ basic_password: haproxy_backend.basic_password || @configuration.basic_password,
276
+ parent: config,
277
+ url: configuration.api_url,
278
+ )
279
+ response = ::DataPlaneApi::Server.get_runtime_settings(
280
+ backend: backend_name.to_s,
281
+ name: server_name.to_s,
282
+ config: conf,
283
+ )
284
+ unless response.status.between?(200, 299)
285
+ raise QueryError,
286
+ "HAProxy query failed! Couldn't fetch server's state"
287
+ end
288
+
289
+ response
290
+ end
291
+
262
292
  private
263
293
 
264
- # @param haproxy_backend [Capistrano::DataPlaneApi::Configuration::Backend]
265
- # @param haproxy_server [Capistrano::DataPlaneApi::Configuration::Server]
266
- # @return [void]
294
+ #: (Configuration::Backend, Configuration::Server) -> void
267
295
  def validate_backend_state(haproxy_backend, haproxy_server)
268
- response = get_backend_servers_settings(haproxy_backend.name)
269
- unless haproxy_backend.servers.length == response.body.length
270
- raise QueryError,
271
- 'HAProxy query failed! Configured servers for this backend' \
272
- "don't match the configuration file! `#{configuration.file_path}`"
273
- end
296
+ response = get_backend_servers_settings(T.must(haproxy_backend.name))
274
297
 
275
- # @type [Array<Hash>]
276
- server_statuses = response.body
298
+ server_statuses = T.let(response.body, T::Array[T::Hash[String, T.untyped]]) # rubocop:disable Sorbet/ForbidTUntyped
277
299
  # check if there are any servers other than this one that are `ready` and `up`
278
300
  other_servers_ready = server_statuses.any? do |server_status|
279
301
  server_status['admin_state'] == 'ready' &&
@@ -0,0 +1,4 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative 'capistrano/data_plane_api'
@@ -0,0 +1,283 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This is an autogenerated file for types exported from the `capistrano-data_plane_api` gem.
5
+ # Please instead update this file by running `spoom srb sigs export`.
6
+
7
+ module Capistrano; end
8
+
9
+ # Main module/namespace of the `capistrano-data_plane_api` gem.
10
+ module Capistrano::DataPlaneApi
11
+ extend ::Capistrano::DataPlaneApi::Helper
12
+
13
+ class << self
14
+ # @raise [NotConfiguredError]
15
+ sig { returns(::Capistrano::DataPlaneApi::Configuration) }
16
+ def configuration; end
17
+
18
+ sig do
19
+ params(
20
+ val: T.any(::Capistrano::DataPlaneApi::Configuration, ::Pathname, ::String, T::Hash[T.any(::String, ::Symbol), ::Object])
21
+ ).void
22
+ end
23
+ def configuration=(val); end
24
+
25
+ # Find the HAProxy backend config with a particular name.
26
+ #
27
+ # @return: HAProxy backend config.
28
+ #
29
+ # @raise [NoSuchBackendError] There is no backend with this name.
30
+ sig { params(backend_name: T.any(::String, ::Symbol)).returns(::Capistrano::DataPlaneApi::Configuration::Backend) }
31
+ def find_backend(backend_name); end
32
+
33
+ # Find the server and backend config for a particular
34
+ # deployment stage.
35
+ #
36
+ # @return:
37
+ # Two-element Array
38
+ # where the first element is the HAProxy server config and the second one
39
+ # is the HAProxy backend config
40
+ sig do
41
+ params(
42
+ deployment_stage: T.any(::String, ::Symbol)
43
+ ).returns([::Capistrano::DataPlaneApi::Configuration::Server, ::Capistrano::DataPlaneApi::Configuration::Backend])
44
+ end
45
+ def find_server_and_backend(deployment_stage); end
46
+
47
+ sig do
48
+ params(
49
+ backend_name: T.any(::String, ::Symbol),
50
+ config: T.nilable(::DataPlaneApi::Configuration)
51
+ ).returns(::Faraday::Response)
52
+ end
53
+ def get_backend_servers_settings(backend_name, config: T.unsafe(nil)); end
54
+
55
+ sig do
56
+ params(
57
+ backend_name: T.any(::String, ::Symbol),
58
+ server_name: T.any(::String, ::Symbol),
59
+ config: T.nilable(::DataPlaneApi::Configuration)
60
+ ).returns(::Faraday::Response)
61
+ end
62
+ def get_server_settings(backend_name, server_name, config: T.unsafe(nil)); end
63
+
64
+ # Get the state of the server.
65
+ #
66
+ # @return: Server state
67
+ #
68
+ # @raise [Error] The process failed due to some reason
69
+ sig do
70
+ params(
71
+ deployment_stage: T.any(::String, ::Symbol),
72
+ config: T.nilable(::DataPlaneApi::Configuration)
73
+ ).returns(T.nilable(T::Hash[::String, T.untyped]))
74
+ end
75
+ def server_get_state(deployment_stage, config: T.unsafe(nil)); end
76
+
77
+ # Set server's admin_state to `drain`.
78
+ #
79
+ # @return: Server state after the change, or `nil`
80
+ # when no change happened
81
+ #
82
+ # @raise [Error] The process failed due to some reason
83
+ sig do
84
+ params(
85
+ deployment_stage: T.any(::String, ::Symbol),
86
+ force: T::Boolean,
87
+ config: T.nilable(::DataPlaneApi::Configuration)
88
+ ).returns(T.nilable(T::Hash[::String, T.untyped]))
89
+ end
90
+ def server_set_drain(deployment_stage, force: T.unsafe(nil), config: T.unsafe(nil)); end
91
+
92
+ # Set server's admin_state to `maint`.
93
+ #
94
+ # @return: Server state after the change, or `nil` when no change happened
95
+ #
96
+ # @raise [Error] The process failed due to some reason
97
+ sig do
98
+ params(
99
+ deployment_stage: T.any(::String, ::Symbol),
100
+ force: T::Boolean,
101
+ config: T.nilable(::DataPlaneApi::Configuration)
102
+ ).returns(T.nilable(T::Hash[::String, T.untyped]))
103
+ end
104
+ def server_set_maint(deployment_stage, force: T.unsafe(nil), config: T.unsafe(nil)); end
105
+
106
+ # Set server's admin_state to `ready`
107
+ #
108
+ # @return: Server state after the change, or `nil` when no change happened
109
+ #
110
+ # @raise [Error] The process failed due to some reason
111
+ sig do
112
+ params(
113
+ deployment_stage: T.any(::String, ::Symbol),
114
+ config: T.nilable(::DataPlaneApi::Configuration)
115
+ ).returns(T.nilable(T::Hash[::String, T.untyped]))
116
+ end
117
+ def server_set_ready(deployment_stage, config: T.unsafe(nil)); end
118
+
119
+ # Prints the current configuration in a human readable format.
120
+ sig { void }
121
+ def show_config; end
122
+
123
+ # Prints the current state of all backends and
124
+ # their servers in a human readable format.
125
+ sig { void }
126
+ def show_state; end
127
+
128
+ private
129
+
130
+ sig do
131
+ params(
132
+ haproxy_backend: ::Capistrano::DataPlaneApi::Configuration::Backend,
133
+ haproxy_server: ::Capistrano::DataPlaneApi::Configuration::Server
134
+ ).void
135
+ end
136
+ def validate_backend_state(haproxy_backend, haproxy_server); end
137
+ end
138
+ end
139
+
140
+ Capistrano::DataPlaneApi::COLORS = T.let(T.unsafe(nil), Pastel::Delegator)
141
+
142
+ # Configuration object of the `capistrano-data_plane_api` gem.
143
+ class Capistrano::DataPlaneApi::Configuration < ::Capistrano::DataPlaneApi::Type
144
+ class << self
145
+ sig { params(path: ::String).returns(T.attached_class) }
146
+ def from_file(path); end
147
+ end
148
+ end
149
+
150
+ # Contains the configuration options of a backend
151
+ class Capistrano::DataPlaneApi::Configuration::Backend < ::Capistrano::DataPlaneApi::Type; end
152
+
153
+ # Contains the configuration options of a server
154
+ class Capistrano::DataPlaneApi::Configuration::Server < ::Capistrano::DataPlaneApi::Type
155
+ sig { returns(T.nilable(::String)) }
156
+ def name; end
157
+
158
+ sig { returns(T.nilable(::String)) }
159
+ def stage; end
160
+ end
161
+
162
+ # A Shale type that represents a ruby `Symbol`
163
+ class Capistrano::DataPlaneApi::Configuration::Symbol < ::Shale::Type::String
164
+ class << self
165
+ def cast(value); end
166
+ end
167
+ end
168
+
169
+ # Include in a class to grant it the `#dig` method.
170
+ # It's implemented so that it calls public methods.
171
+ module Capistrano::DataPlaneApi::Diggable
172
+ include ::Booleans::KernelExtension
173
+ include ::Kernel
174
+
175
+ # Extracts the nested value specified by the sequence of key objects by calling `dig` at each step,
176
+ # returning `nil` if any intermediate step is `nil`.
177
+ #
178
+ # This implementation of `dig` uses `public_send` under the hood.
179
+ #
180
+ # @raise [TypeError] value has no #dig method
181
+ sig { params(args: T.untyped).returns(T.untyped) }
182
+ def dig(*args); end
183
+ end
184
+
185
+ # Include in a class to make its instances capable
186
+ # of comparing themselves with other objects of the same class
187
+ # by calling `==` on their instance variables.
188
+ module Capistrano::DataPlaneApi::Equatable
189
+ include ::Booleans::KernelExtension
190
+ include ::Kernel
191
+
192
+ # @param other [Object]
193
+ # @return [Boolean]
194
+ def ==(*args, **_arg1, &blk); end
195
+
196
+ sig { params(other: ::Object).returns(T::Boolean) }
197
+ def eql?(other); end
198
+ end
199
+
200
+ class Capistrano::DataPlaneApi::Error < ::StandardError; end
201
+
202
+ # Provides helper methods
203
+ module Capistrano::DataPlaneApi::Helper
204
+ sig { returns(T::Boolean) }
205
+ def force_haproxy?; end
206
+
207
+ sig { params(state: T.nilable(T.any(::String, ::Symbol))).returns(T.nilable(::String)) }
208
+ def humanize_admin_state(state); end
209
+
210
+ sig { params(backend: ::Capistrano::DataPlaneApi::Configuration::Backend).returns(::String) }
211
+ def humanize_backend_name(backend); end
212
+
213
+ sig { params(state: T.nilable(T.any(::String, ::Symbol))).returns(T.nilable(::String)) }
214
+ def humanize_operational_state(state); end
215
+
216
+ sig { returns(T::Boolean) }
217
+ def no_haproxy?; end
218
+ end
219
+
220
+ Capistrano::DataPlaneApi::Helper::ADMIN_STATE_COLORS = T.let(T.unsafe(nil), Hash)
221
+ Capistrano::DataPlaneApi::Helper::OPERATIONAL_STATE_COLORS = T.let(T.unsafe(nil), Hash)
222
+ class Capistrano::DataPlaneApi::NoBackendForThisStageError < ::Capistrano::DataPlaneApi::Error; end
223
+ class Capistrano::DataPlaneApi::NoOtherServerReadyError < ::Capistrano::DataPlaneApi::Error; end
224
+ class Capistrano::DataPlaneApi::NoSuchBackendError < ::Capistrano::DataPlaneApi::Error; end
225
+ class Capistrano::DataPlaneApi::NotConfiguredError < ::Capistrano::DataPlaneApi::Error; end
226
+ class Capistrano::DataPlaneApi::QueryError < ::Capistrano::DataPlaneApi::Error; end
227
+
228
+ # Creates a human readable summary of the state of
229
+ # HAProxy backends and servers to stdout.
230
+ module Capistrano::DataPlaneApi::ShowState
231
+ class << self
232
+ sig { returns(::String) }
233
+ def call; end
234
+
235
+ private
236
+
237
+ sig { params(server: T::Hash[::String, T.untyped]).returns(T.nilable(::String)) }
238
+ def admin_state(server); end
239
+
240
+ sig { params(backend: ::Capistrano::DataPlaneApi::Configuration::Backend).returns(::String) }
241
+ def backend_name(backend); end
242
+
243
+ sig { params(server: T::Hash[::String, T.untyped]).returns(T.nilable(::String)) }
244
+ def operational_state(server); end
245
+
246
+ sig { params(server: T::Hash[::String, T.untyped]).returns(T.nilable(::String)) }
247
+ def server_name(server); end
248
+ end
249
+ end
250
+
251
+ # Provides a method that renders
252
+ # strings in a terminal with the given interval.
253
+ module Capistrano::DataPlaneApi::TerminalPrintLoop
254
+ class << self
255
+ # Calls the passed block in an endless loop with a given interval
256
+ # between calls.
257
+ # It prints the `String` returned from the block and clears it
258
+ # before another frame is printed.
259
+ sig { params(interval: ::Integer, _block: T.proc.params(arg0: ::String).returns(::Object)).void }
260
+ def call(interval: T.unsafe(nil), &_block); end
261
+ end
262
+ end
263
+
264
+ # A Base class for all types of the Data Plane API request and response bodies
265
+ #
266
+ # @abstract It cannot be directly instantiated. Subclasses must implement the `abstract` methods below.
267
+ class Capistrano::DataPlaneApi::Type < ::Shale::Mapper
268
+ include ::Capistrano::DataPlaneApi::Diggable
269
+ include ::Capistrano::DataPlaneApi::Equatable
270
+
271
+ abstract!
272
+
273
+ sig { params(key: T.any(::String, ::Symbol)).returns(T.nilable(::Object)) }
274
+ def [](key); end
275
+
276
+ sig { params(key: T.any(::String, ::Symbol), val: ::Object).void }
277
+ def []=(key, val); end
278
+
279
+ def to_h; end
280
+ end
281
+
282
+ class Capistrano::DataPlaneApi::UpdateServerStateError < ::Capistrano::DataPlaneApi::Error; end
283
+ Capistrano::DataPlaneApi::VERSION = T.let(T.unsafe(nil), String)
data/sorbet/config ADDED
@@ -0,0 +1,6 @@
1
+ --dir
2
+ .
3
+ --enable-experimental-rbs-signatures
4
+ --ignore=tmp/
5
+ --ignore=vendor/
6
+ --ignore=rbi/capistrano-data_plane_api.rbi
@@ -0,0 +1 @@
1
+ **/*.rbi linguist-vendored=true
@@ -0,0 +1,17 @@
1
+ # typed: true
2
+
3
+ # DO NOT EDIT MANUALLY
4
+ # This file was pulled from a central RBI files repository.
5
+ # Please run `bin/tapioca annotations` to update it.
6
+
7
+ module Faraday
8
+ class << self
9
+ sig { params(url: T.untyped, options: T::Hash[Symbol, T.untyped], block: T.nilable(T.proc.params(connection: Faraday::Connection).void)).returns(Faraday::Connection) }
10
+ def new(url = nil, options = {}, &block); end
11
+ end
12
+ end
13
+
14
+ class Faraday::Response
15
+ sig { returns(T::Boolean) }
16
+ def success?; end
17
+ end