data_plane_api 0.1.2 → 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 (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -2
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +6 -0
  5. data/Gemfile +6 -3
  6. data/Gemfile.lock +89 -60
  7. data/README.md +8 -1
  8. data/data_plane_api.gemspec +3 -1
  9. data/lib/data_plane_api/configuration.rb +51 -28
  10. data/lib/data_plane_api/server.rb +31 -36
  11. data/lib/data_plane_api/version.rb +1 -2
  12. data/lib/data_plane_api.rb +3 -3
  13. data/rbi/data_plane_api.rbi +135 -0
  14. data/sorbet/config +6 -0
  15. data/sorbet/rbi/annotations/.gitattributes +1 -0
  16. data/sorbet/rbi/annotations/faraday.rbi +17 -0
  17. data/sorbet/rbi/annotations/minitest.rbi +119 -0
  18. data/sorbet/rbi/annotations/rainbow.rbi +269 -0
  19. data/sorbet/rbi/annotations/webmock.rbi +9 -0
  20. data/sorbet/rbi/gems/.gitattributes +1 -0
  21. data/sorbet/rbi/gems/addressable@2.8.7.rbi +1994 -0
  22. data/sorbet/rbi/gems/ast@2.4.3.rbi +585 -0
  23. data/sorbet/rbi/gems/base64@0.2.0.rbi +509 -0
  24. data/sorbet/rbi/gems/bigdecimal@3.1.9.rbi +8 -0
  25. data/sorbet/rbi/gems/booleans@0.1.3.rbi +28 -0
  26. data/sorbet/rbi/gems/byebug@12.0.0.rbi +37 -0
  27. data/sorbet/rbi/gems/crack@1.0.0.rbi +145 -0
  28. data/sorbet/rbi/gems/faraday-net_http@3.0.2.rbi +147 -0
  29. data/sorbet/rbi/gems/faraday@2.7.2.rbi +2519 -0
  30. data/sorbet/rbi/gems/hashdiff@1.1.2.rbi +353 -0
  31. data/sorbet/rbi/gems/json@2.10.2.rbi +2112 -0
  32. data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +86 -0
  33. data/sorbet/rbi/gems/minitest@5.25.5.rbi +1547 -0
  34. data/sorbet/rbi/gems/parallel@1.26.3.rbi +291 -0
  35. data/sorbet/rbi/gems/public_suffix@6.0.1.rbi +936 -0
  36. data/sorbet/rbi/gems/racc@1.8.1.rbi +160 -0
  37. data/sorbet/rbi/gems/rainbow@3.1.1.rbi +403 -0
  38. data/sorbet/rbi/gems/rake@13.0.6.rbi +3030 -0
  39. data/sorbet/rbi/gems/rexml@3.4.1.rbi +5346 -0
  40. data/sorbet/rbi/gems/rubocop-espago@1.1.8.rbi +9 -0
  41. data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1318 -0
  42. data/sorbet/rbi/gems/ruby2_keywords@0.0.5.rbi +9 -0
  43. data/sorbet/rbi/gems/shoulda-context@2.0.0.rbi +563 -0
  44. data/sorbet/rbi/gems/unicode-display_width@3.1.4.rbi +132 -0
  45. data/sorbet/rbi/gems/unicode-emoji@4.0.4.rbi +251 -0
  46. data/sorbet/rbi/gems/vcr@6.3.1.rbi +3040 -0
  47. data/sorbet/rbi/gems/webmock@3.25.1.rbi +1792 -0
  48. data/sorbet/rbi/shims/gems/faraday.rbi +21 -0
  49. data/sorbet/rbi/shims/gems/shoulda-context@2.0.0.rbi +15 -0
  50. data/sorbet/tapioca/config.yml +28 -0
  51. data/sorbet/tapioca/extensions/load_gem.rb +1 -0
  52. data/sorbet/tapioca/require.rb +6 -0
  53. metadata +72 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d93eeb2af8e44546e13b5e38c3265a7f8d93a953ad495a941adbf4016988e50b
4
- data.tar.gz: 03ee9087558116db2daad2cda2614fdc680c345298abc38bedbf0f3969770022
3
+ metadata.gz: 7da2ff7eebc65e3bb292ae067777b6e55437e217a01b60655de59c5056276645
4
+ data.tar.gz: c5a9c0c7fb385cde8fb92a437c8c4f33d2c306d34b20209f0030633c9e1af574
5
5
  SHA512:
6
- metadata.gz: 18a2aaefd1a9ab73a275e4f9f6b7f99de59153ba2ac4f1645bccf336117e7ca09a2c0db5c7be1b549e2a54552f5e3062d915f948e34627703b878f20cc4c333c
7
- data.tar.gz: 164860275acf0d67adf6e1216ac39c6f096757c517ea079e9922b42ddfda2f83e01b20f3514735747257848f6deb519dccbbeb8762ed74680cbb0616434f39a9
6
+ metadata.gz: 68e4a6676388face3a521ad62036935b5d374897b153d308d2ef61146812990e80181d2d06661ba04e956bd18590d0d53869e902be76d0b63b579baf1c669143
7
+ data.tar.gz: '0941b0e0212dd52b012fea661aa7f127cc21babe82249969d70adca38f76704940802625c3fe97c51cbf67ec4afd58ebac92c289e3d0dcd6099e5abe95afaf17'
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  inherit_gem:
2
- rubocop-espago: rubocop.yml
2
+ rubocop-espago: sorbet.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.7
5
+ TargetRubyVersion: 3.2
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.4.2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.0] - 2025-04-10
4
+
5
+ ### Added
6
+ - Rewrite type annotations from YARD to sorbet (inline RBS)
7
+ - Add mock mode `DataPlaneApi::Configuration#mock`
8
+
3
9
  ## [0.1.0] - 2022-12-26
4
10
 
5
11
  - Initial release
data/Gemfile CHANGED
@@ -5,11 +5,14 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in data_plane_api.gemspec
6
6
  gemspec
7
7
 
8
+ gem 'byebug', '~> 12.0' # debugger
8
9
  gem 'minitest', '~> 5.0' # Tests framework
9
10
  gem 'rake', '~> 13.0' # Ruby automation tasks
10
11
  gem 'rubocop', '~> 1.21' # Ruby linter
11
12
  gem 'rubocop-espago', '~> 1.0' # Custom Ruby linter config
12
- gem 'solargraph' # Ruby language server
13
+ gem 'rubocop-sorbet', '~> 0.10.0' # Rubocop config for sorbet
13
14
  gem 'shoulda-context', '~> 2.0' # Testing utilities
14
- gem 'vcr' # Save HTTP interactions to files during tests
15
- gem 'webmock' # Mock network interactions
15
+ gem 'sorbet', '~> 0.5' # static typechecker
16
+ gem 'tapioca', '~> 0.16.11', require: false # RBI generator
17
+ gem 'vcr', '~> 6.3.1' # Save HTTP interactions to files during tests
18
+ gem 'webmock', '~> 3.25.1' # Mock network interactions
data/Gemfile.lock CHANGED
@@ -1,106 +1,135 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- data_plane_api (0.1.2)
4
+ data_plane_api (0.2.0)
5
+ booleans (~> 0.1.3)
5
6
  faraday (> 1, < 3)
7
+ sorbet-runtime (~> 0.5)
6
8
 
7
9
  GEM
8
10
  remote: https://rubygems.org/
9
11
  specs:
10
- addressable (2.8.1)
11
- public_suffix (>= 2.0.2, < 6.0)
12
- ast (2.4.2)
13
- backport (1.2.0)
12
+ addressable (2.8.7)
13
+ public_suffix (>= 2.0.2, < 7.0)
14
+ ast (2.4.3)
15
+ base64 (0.2.0)
14
16
  benchmark (0.2.1)
15
- crack (0.4.5)
17
+ bigdecimal (3.1.9)
18
+ booleans (0.1.3)
19
+ sorbet-runtime (>= 0.5)
20
+ byebug (12.0.0)
21
+ crack (1.0.0)
22
+ bigdecimal
16
23
  rexml
17
- diff-lcs (1.5.0)
18
- e2mmap (0.1.0)
24
+ erubi (1.13.1)
19
25
  faraday (2.7.2)
20
26
  faraday-net_http (>= 2.0, < 3.1)
21
27
  ruby2_keywords (>= 0.0.4)
22
28
  faraday-net_http (3.0.2)
23
- hashdiff (1.0.1)
24
- jaro_winkler (1.5.4)
25
- json (2.6.3)
26
- kramdown (2.4.0)
27
- rexml
28
- kramdown-parser-gfm (1.1.0)
29
- kramdown (~> 2.0)
30
- mini_portile2 (2.8.1)
31
- minitest (5.16.3)
32
- nokogiri (1.13.10)
33
- mini_portile2 (~> 2.8.0)
34
- racc (~> 1.4)
35
- parallel (1.22.1)
36
- parser (3.1.3.0)
29
+ hashdiff (1.1.2)
30
+ json (2.10.2)
31
+ language_server-protocol (3.17.0.4)
32
+ lint_roller (1.1.0)
33
+ logger (1.7.0)
34
+ minitest (5.25.5)
35
+ netrc (0.11.0)
36
+ parallel (1.26.3)
37
+ parser (3.3.7.4)
37
38
  ast (~> 2.4.1)
38
- public_suffix (5.0.1)
39
- racc (1.6.1)
39
+ racc
40
+ prism (1.4.0)
41
+ public_suffix (6.0.1)
42
+ racc (1.8.1)
40
43
  rainbow (3.1.1)
41
44
  rake (13.0.6)
42
- regexp_parser (2.6.1)
43
- reverse_markdown (2.1.1)
44
- nokogiri
45
- rexml (3.2.5)
46
- rubocop (1.41.1)
45
+ rbi (0.3.1)
46
+ prism (~> 1.0)
47
+ rbs (>= 3.4.4)
48
+ sorbet-runtime (>= 0.5.9204)
49
+ rbs (3.9.2)
50
+ logger
51
+ regexp_parser (2.10.0)
52
+ rexml (3.4.1)
53
+ rubocop (1.75.2)
47
54
  json (~> 2.3)
55
+ language_server-protocol (~> 3.17.0.2)
56
+ lint_roller (~> 1.1.0)
48
57
  parallel (~> 1.10)
49
- parser (>= 3.1.2.1)
58
+ parser (>= 3.3.0.2)
50
59
  rainbow (>= 2.2.2, < 4.0)
51
- regexp_parser (>= 1.8, < 3.0)
52
- rexml (>= 3.2.5, < 4.0)
53
- rubocop-ast (>= 1.23.0, < 2.0)
60
+ regexp_parser (>= 2.9.3, < 3.0)
61
+ rubocop-ast (>= 1.44.0, < 2.0)
54
62
  ruby-progressbar (~> 1.7)
55
- unicode-display_width (>= 1.4.0, < 3.0)
56
- rubocop-ast (1.24.0)
57
- parser (>= 3.1.1.0)
58
- rubocop-espago (1.0.2)
63
+ unicode-display_width (>= 2.4.0, < 4.0)
64
+ rubocop-ast (1.44.0)
65
+ parser (>= 3.3.7.2)
66
+ prism (~> 1.4)
67
+ rubocop-espago (1.1.8)
59
68
  rubocop
60
- ruby-progressbar (1.11.0)
69
+ rubocop-sorbet (0.10.0)
70
+ rubocop (>= 1)
71
+ ruby-progressbar (1.13.0)
61
72
  ruby2_keywords (0.0.5)
62
73
  shoulda-context (2.0.0)
63
- solargraph (0.48.0)
64
- backport (~> 1.2)
74
+ sorbet (0.5.12003)
75
+ sorbet-static (= 0.5.12003)
76
+ sorbet-runtime (0.5.12003)
77
+ sorbet-static (0.5.12003-universal-darwin)
78
+ sorbet-static (0.5.12003-x86_64-linux)
79
+ sorbet-static-and-runtime (0.5.12003)
80
+ sorbet (= 0.5.12003)
81
+ sorbet-runtime (= 0.5.12003)
82
+ spoom (1.6.1)
83
+ erubi (>= 1.10.0)
84
+ prism (>= 0.28.0)
85
+ rbi (>= 0.2.3)
86
+ sorbet-static-and-runtime (>= 0.5.10187)
87
+ thor (>= 0.19.2)
88
+ tapioca (0.16.11)
65
89
  benchmark
66
- bundler (>= 1.17.2)
67
- diff-lcs (~> 1.4)
68
- e2mmap
69
- jaro_winkler (~> 1.5)
70
- kramdown (~> 2.3)
71
- kramdown-parser-gfm (~> 1.1)
72
- parser (~> 3.0)
73
- reverse_markdown (>= 1.0.5, < 3)
74
- rubocop (>= 0.52)
75
- thor (~> 1.0)
76
- tilt (~> 2.0)
77
- yard (~> 0.9, >= 0.9.24)
90
+ bundler (>= 2.2.25)
91
+ netrc (>= 0.11.0)
92
+ parallel (>= 1.21.0)
93
+ rbi (~> 0.2)
94
+ sorbet-static-and-runtime (>= 0.5.11087)
95
+ spoom (>= 1.2.0)
96
+ thor (>= 1.2.0)
97
+ yard-sorbet
78
98
  thor (1.2.1)
79
- tilt (2.0.11)
80
- unicode-display_width (2.3.0)
81
- vcr (6.1.0)
82
- webmock (3.18.1)
99
+ unicode-display_width (3.1.4)
100
+ unicode-emoji (~> 4.0, >= 4.0.4)
101
+ unicode-emoji (4.0.4)
102
+ vcr (6.3.1)
103
+ base64
104
+ webmock (3.25.1)
83
105
  addressable (>= 2.8.0)
84
106
  crack (>= 0.3.2)
85
107
  hashdiff (>= 0.4.0, < 2.0.0)
86
108
  webrick (1.7.0)
87
109
  yard (0.9.28)
88
110
  webrick (~> 1.7.0)
111
+ yard-sorbet (0.9.0)
112
+ sorbet-runtime
113
+ yard
89
114
 
90
115
  PLATFORMS
91
116
  arm64-darwin-20
117
+ arm64-darwin-23
92
118
  x86_64-linux
93
119
 
94
120
  DEPENDENCIES
121
+ byebug (~> 12.0)
95
122
  data_plane_api!
96
123
  minitest (~> 5.0)
97
124
  rake (~> 13.0)
98
125
  rubocop (~> 1.21)
99
126
  rubocop-espago (~> 1.0)
127
+ rubocop-sorbet (~> 0.10.0)
100
128
  shoulda-context (~> 2.0)
101
- solargraph
102
- vcr
103
- webmock
129
+ sorbet (~> 0.5)
130
+ tapioca (~> 0.16.11)
131
+ vcr (~> 6.3.1)
132
+ webmock (~> 3.25.1)
104
133
 
105
134
  BUNDLED WITH
106
- 2.4.1
135
+ 2.6.7
data/README.md CHANGED
@@ -1,11 +1,18 @@
1
1
  # DataPlaneApi Ruby
2
2
 
3
- This gem provides a simple interface for the Community Edition of the HAProxy DataPlane API.
3
+ This gem provides a simple interface for the Community Edition of
4
+ the HAProxy Data Plane API.
5
+
4
6
  Currently, it only supports a handful of requests that we needed.
5
7
  More may be added in the future.
6
8
 
7
9
  We encourage you to make Pull Requests with more API endpoints.
8
10
 
11
+ [HAProxy](https://www.haproxy.com/) is a load balancer.
12
+ The [Data Plane API](https://www.haproxy.com/documentation/dataplaneapi/community/)
13
+ can be used to manage your HAProxy config,
14
+ backends and servers.
15
+
9
16
  ## Installation
10
17
 
11
18
  Install the gem and add to the application's Gemfile by executing:
@@ -12,7 +12,7 @@ require_relative 'lib/data_plane_api/version'
12
12
  spec.description = 'Ruby gem which covers a limited subset of the HAProxy Data Plane API.'
13
13
  spec.homepage = 'https://github.com/espago/data_plane_api_ruby'
14
14
  spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 2.7.0'
15
+ spec.required_ruby_version = '>= 3.2.0'
16
16
 
17
17
  spec.metadata['homepage_uri'] = spec.homepage
18
18
  spec.metadata['source_code_uri'] = 'https://github.com/espago/data_plane_api_ruby'
@@ -30,7 +30,9 @@ require_relative 'lib/data_plane_api/version'
30
30
  spec.require_paths = ['lib']
31
31
 
32
32
  # Uncomment to register a new dependency of your gem
33
+ spec.add_dependency 'booleans', '~> 0.1.3'
33
34
  spec.add_dependency 'faraday', '> 1', '< 3'
35
+ spec.add_dependency 'sorbet-runtime', '~> 0.5'
34
36
 
35
37
  # For more information and examples about making a new gem, check out our
36
38
  # guide at: https://bundler.io/guides/creating_gem.html
@@ -1,34 +1,42 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
4
+ require 'booleans/kernel_extension'
3
5
  require 'faraday'
4
6
  require 'logger'
5
7
 
6
8
  module DataPlaneApi
7
9
  # Stores configuration options for the HAProxy Data Plane API.
8
10
  class Configuration
9
- # @return [String, URI::Generic, nil]
11
+ #: String | URI::Generic | nil
10
12
  attr_writer :url
11
- # @return [String, nil] Basic Auth username.
13
+ # Basic Auth username.
14
+ #: String?
12
15
  attr_writer :basic_user
13
- # @return [String, nil] Basic Auth password.
16
+ # Basic Auth password.
17
+ #: String?
14
18
  attr_writer :basic_password
15
- # @return [Logger, nil]
19
+ #: Logger?
16
20
  attr_writer :logger
17
- # @return [Integer, nil]
21
+ #: Integer?
18
22
  attr_writer :timeout
19
- # @return [Boolean] whether this object is used as a global store of settings
23
+ # Do not make HTTP requests, just log them
24
+ #
25
+ #: bool
26
+ attr_writer :mock
27
+ # Whether this object is used as a global store of settings
28
+ #
29
+ #: bool
20
30
  attr_reader :global
21
31
 
22
- # @param url [String, nil]
23
- # @param global [Boolean] whether this object is used as a global store of settings
24
- # @param basic_user [String, nil] Basic Auth username.
25
- # @param basic_password [String, nil] Basic Auth password.
26
- # @param logger [Logger, nil]
27
- # @param timeout [Integer, nil]
28
- # @param parent [self, nil]
32
+ # @param global: whether this object is used as a global store of settings
33
+ # @param basic_user: Basic Auth username.
34
+ # @param basic_password: Basic Auth password.
35
+ #: (String | URI::Generic | nil, bool, bool, String?, String?, Logger?, Integer?, Configuration?) -> void
29
36
  def initialize(
30
37
  url: nil,
31
38
  global: false,
39
+ mock: false,
32
40
  basic_user: nil,
33
41
  basic_password: nil,
34
42
  logger: nil,
@@ -37,6 +45,7 @@ module DataPlaneApi
37
45
  )
38
46
 
39
47
  @global = global
48
+ @mock = mock
40
49
  @url = url
41
50
  @basic_user = basic_user
42
51
  @basic_password = basic_password
@@ -51,53 +60,67 @@ module DataPlaneApi
51
60
  @timeout ||= 10
52
61
  end
53
62
 
54
- # @return [Faraday::Connection]
63
+ #: -> Faraday::Connection
55
64
  def connection
56
65
  @connection || build_connection
57
66
  end
58
67
 
59
- # @return [void]
68
+ #: -> void
60
69
  def freeze
61
70
  @connection = build_connection
62
71
  super
63
72
  end
64
73
 
65
- # @return [String, URI::Generic, nil]
74
+ #: -> (String | URI::Generic | nil)
66
75
  def url
67
76
  return @url if @global || @url
68
77
 
69
- parent.url
78
+ parent&.url
70
79
  end
71
80
 
72
- # @return [String, nil] Basic Auth username.
81
+ # Basic Auth username.
82
+ #: -> String?
73
83
  def basic_user
74
84
  return @basic_user if @global || @basic_user
75
85
 
76
- parent.basic_user
86
+ parent&.basic_user
77
87
  end
78
88
 
79
- # @return [String, nil] Basic Auth password.
89
+ # Basic Auth password.
90
+ #: -> String?
80
91
  def basic_password
81
92
  return @basic_password if @global || @basic_password
82
93
 
83
- parent.basic_password
94
+ parent&.basic_password
84
95
  end
85
96
 
86
- # @return [Logger, nil]
97
+ #: -> Logger?
87
98
  def logger
88
99
  return @logger if @global || @logger
89
100
 
90
- parent.logger
101
+ parent&.logger
91
102
  end
92
103
 
93
- # @return [Integer, nil]
104
+ #: -> Integer?
94
105
  def timeout
95
106
  return @timeout if @global || @timeout
96
107
 
97
- parent.timeout
108
+ parent&.timeout
98
109
  end
99
110
 
100
- # @return [self, nil]
111
+ #: -> bool?
112
+ def mock
113
+ return @mock if @global || @mock
114
+
115
+ parent&.mock
116
+ end
117
+
118
+ #: -> bool
119
+ def mock?
120
+ Boolean(mock)
121
+ end
122
+
123
+ #: -> Configuration?
101
124
  def parent
102
125
  return if @global
103
126
 
@@ -107,7 +130,7 @@ module DataPlaneApi
107
130
  private
108
131
 
109
132
  if ::Faraday::VERSION > '2'
110
- # @return [Faraday::Connection]
133
+ #: -> Faraday::Connection
111
134
  def build_connection
112
135
  headers = { 'Content-Type' => 'application/json' }
113
136
 
@@ -120,7 +143,7 @@ module DataPlaneApi
120
143
  else
121
144
  # Faraday 1.x compatibility
122
145
 
123
- # @return [Faraday::Connection]
146
+ #: -> Faraday::Connection
124
147
  def build_connection
125
148
  headers = { 'Content-Type' => 'application/json' }
126
149
 
@@ -1,23 +1,20 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
3
4
  require 'json'
4
- require 'set'
5
5
 
6
6
  module DataPlaneApi
7
7
  # Wraps endpoints regarding HAProxy servers.
8
8
  module Server
9
- # @return [Set<Symbol>]
10
- ADMIN_STATES = ::Set[:ready, :maint, :drain]
11
- # @return [Set<Symbol>]
12
- OPERATIONAL_STATES = ::Set[:up, :down, :stopping]
9
+ ADMIN_STATES = T.let(::Set[:ready, :maint, :drain], T::Set[Symbol])
10
+ OPERATIONAL_STATES = T.let(::Set[:up, :down, :stopping], T::Set[Symbol])
13
11
 
14
12
  class << self
15
- # @param backend [String] Name of the backend
16
- # @param name [String, nil] Name of the server whose settings will be returned.
13
+ # @param backend: Name of the backend
14
+ # @param name: Name of the server whose settings will be returned.
17
15
  # If `nil` then an array of settings of all servers under the passed `backend`
18
16
  # will be returned.
19
- # @param config [HaProxy::DataPlaneApi::Configuration, nil]
20
- # @return [Faraday::Response]
17
+ #: (String?, String?, Configuration?) -> Faraday::Response?
21
18
  def get_runtime_settings(backend:, name: nil, config: nil)
22
19
  config ||= CONFIG
23
20
  if backend.nil? || backend.empty?
@@ -31,11 +28,9 @@ module DataPlaneApi
31
28
  end
32
29
  end
33
30
 
34
- # @param backend [String] Name of the backend
35
- # @param name [String, nil] Name of the server whose transient settings should be updated.
36
- # @param settings [Hash]
37
- # @param config [HaProxy::DataPlaneApi::Configuration, nil]
38
- # @return [Faraday::Response]
31
+ # @param backend: Name of the backend
32
+ # @param name: Name of the server whose transient settings should be updated.
33
+ #: (String?, String?, Hash[top, top], Configuration?) -> Faraday::Response?
39
34
  def update_transient_settings(backend:, name:, settings:, config: nil)
40
35
  config ||= CONFIG
41
36
  if backend.nil? || backend.empty?
@@ -53,44 +48,44 @@ module DataPlaneApi
53
48
 
54
49
  private
55
50
 
56
- # @param method [Symbol]
57
- # @param path [String, Pathname]
58
- # @param config [HaProxy::DataPlaneApi::Configuration]
59
- # @yieldparam request [Faraday::Request]
60
- # @return [Faraday::Response]
51
+ #: (Symbol, String | Pathname, Configuration) { (Faraday::Request) -> void } -> Faraday::Response?
61
52
  def send_request(method:, path:, config:, &block)
62
- request = nil
63
- response = config.connection.public_send(method, path) do |req|
53
+ request = T.let(nil, T.nilable(Faraday::Request))
54
+ conn = config.connection
55
+ response = conn.public_send(method, path) do |req|
64
56
  block.call(req)
65
57
  req.options.timeout = config.timeout
66
58
  request = req
59
+ break if config.mock?
67
60
  end
68
61
 
69
- log_communication(request, response, logger: config.logger)
62
+ log_communication(
63
+ conn.build_url(path),
64
+ T.must(request),
65
+ response,
66
+ logger: config.logger,
67
+ )
70
68
 
71
69
  response
72
70
  end
73
71
 
74
- # @param request [Faraday::Request]
75
- # @param response [Faraday::Response]
76
- # @param logger [Logger]
77
- # @return [void]
78
- def log_communication(request, response, logger:)
72
+ #: (String, Faraday::Request, Faraday::Response?, Logger?) -> void
73
+ def log_communication(url, request, response, logger:)
79
74
  request_hash = {
80
- method: request.http_method,
81
- url: response.env.url,
82
- params: request.params,
75
+ method: request.http_method,
76
+ url: url,
77
+ params: request.params,
83
78
  headers: request.headers,
84
- body: request.body
79
+ body: request.body,
85
80
  }
86
81
  response_hash = {
87
- status: response.status,
88
- body: response.body,
89
- headers: response.headers
82
+ status: response&.status,
83
+ body: response&.body,
84
+ headers: response&.headers,
90
85
  }
91
86
 
92
- logger.debug <<~REQ
93
- HAProxy #{request.http_method.to_s.upcase} #{response.env.url}
87
+ logger&.debug <<~REQ
88
+ HAProxy #{request.http_method.to_s.upcase} #{url}
94
89
  -----REQUEST-----
95
90
  #{::JSON.pretty_generate request_hash}
96
91
  -----RESPONSE-----
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DataPlaneApi
4
- # @return [String]
5
- VERSION = '0.1.2'
4
+ VERSION = '0.2.0'
6
5
  end
@@ -1,5 +1,7 @@
1
+ # typed: true
1
2
  # frozen_string_literal: true
2
3
 
4
+ require 'sorbet-runtime'
3
5
  require_relative 'data_plane_api/version'
4
6
  require_relative 'data_plane_api/configuration'
5
7
 
@@ -8,12 +10,10 @@ require_relative 'data_plane_api/configuration'
8
10
  module DataPlaneApi
9
11
  class Error < ::StandardError; end
10
12
 
11
- # @return [DataPlaneAPI]
12
13
  CONFIG = Configuration.new(global: true)
13
14
 
14
15
  class << self
15
- # @yieldparam config [Configuration]
16
- # @return [Configuration]
16
+ #: { (Configuration) -> void } -> Configuration
17
17
  def configure(&block)
18
18
  block.call(CONFIG)
19
19
  CONFIG