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.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -2
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -0
- data/Gemfile +6 -3
- data/Gemfile.lock +89 -60
- data/README.md +8 -1
- data/data_plane_api.gemspec +3 -1
- data/lib/data_plane_api/configuration.rb +51 -28
- data/lib/data_plane_api/server.rb +31 -36
- data/lib/data_plane_api/version.rb +1 -2
- data/lib/data_plane_api.rb +3 -3
- data/rbi/data_plane_api.rbi +135 -0
- data/sorbet/config +6 -0
- data/sorbet/rbi/annotations/.gitattributes +1 -0
- data/sorbet/rbi/annotations/faraday.rbi +17 -0
- data/sorbet/rbi/annotations/minitest.rbi +119 -0
- data/sorbet/rbi/annotations/rainbow.rbi +269 -0
- data/sorbet/rbi/annotations/webmock.rbi +9 -0
- data/sorbet/rbi/gems/.gitattributes +1 -0
- data/sorbet/rbi/gems/addressable@2.8.7.rbi +1994 -0
- data/sorbet/rbi/gems/ast@2.4.3.rbi +585 -0
- data/sorbet/rbi/gems/base64@0.2.0.rbi +509 -0
- data/sorbet/rbi/gems/bigdecimal@3.1.9.rbi +8 -0
- data/sorbet/rbi/gems/booleans@0.1.3.rbi +28 -0
- data/sorbet/rbi/gems/byebug@12.0.0.rbi +37 -0
- data/sorbet/rbi/gems/crack@1.0.0.rbi +145 -0
- data/sorbet/rbi/gems/faraday-net_http@3.0.2.rbi +147 -0
- data/sorbet/rbi/gems/faraday@2.7.2.rbi +2519 -0
- data/sorbet/rbi/gems/hashdiff@1.1.2.rbi +353 -0
- data/sorbet/rbi/gems/json@2.10.2.rbi +2112 -0
- data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +86 -0
- data/sorbet/rbi/gems/minitest@5.25.5.rbi +1547 -0
- data/sorbet/rbi/gems/parallel@1.26.3.rbi +291 -0
- data/sorbet/rbi/gems/public_suffix@6.0.1.rbi +936 -0
- data/sorbet/rbi/gems/racc@1.8.1.rbi +160 -0
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +403 -0
- data/sorbet/rbi/gems/rake@13.0.6.rbi +3030 -0
- data/sorbet/rbi/gems/rexml@3.4.1.rbi +5346 -0
- data/sorbet/rbi/gems/rubocop-espago@1.1.8.rbi +9 -0
- data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1318 -0
- data/sorbet/rbi/gems/ruby2_keywords@0.0.5.rbi +9 -0
- data/sorbet/rbi/gems/shoulda-context@2.0.0.rbi +563 -0
- data/sorbet/rbi/gems/unicode-display_width@3.1.4.rbi +132 -0
- data/sorbet/rbi/gems/unicode-emoji@4.0.4.rbi +251 -0
- data/sorbet/rbi/gems/vcr@6.3.1.rbi +3040 -0
- data/sorbet/rbi/gems/webmock@3.25.1.rbi +1792 -0
- data/sorbet/rbi/shims/gems/faraday.rbi +21 -0
- data/sorbet/rbi/shims/gems/shoulda-context@2.0.0.rbi +15 -0
- data/sorbet/tapioca/config.yml +28 -0
- data/sorbet/tapioca/extensions/load_gem.rb +1 -0
- data/sorbet/tapioca/require.rb +6 -0
- metadata +72 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7da2ff7eebc65e3bb292ae067777b6e55437e217a01b60655de59c5056276645
|
4
|
+
data.tar.gz: c5a9c0c7fb385cde8fb92a437c8c4f33d2c306d34b20209f0030633c9e1af574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68e4a6676388face3a521ad62036935b5d374897b153d308d2ef61146812990e80181d2d06661ba04e956bd18590d0d53869e902be76d0b63b579baf1c669143
|
7
|
+
data.tar.gz: '0941b0e0212dd52b012fea661aa7f127cc21babe82249969d70adca38f76704940802625c3fe97c51cbf67ec4afd58ebac92c289e3d0dcd6099e5abe95afaf17'
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.2
|
1
|
+
3.4.2
|
data/CHANGELOG.md
CHANGED
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 '
|
13
|
+
gem 'rubocop-sorbet', '~> 0.10.0' # Rubocop config for sorbet
|
13
14
|
gem 'shoulda-context', '~> 2.0' # Testing utilities
|
14
|
-
gem '
|
15
|
-
gem '
|
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.
|
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.
|
11
|
-
public_suffix (>= 2.0.2, <
|
12
|
-
ast (2.4.
|
13
|
-
|
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
|
-
|
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
|
-
|
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.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
|
39
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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.
|
58
|
+
parser (>= 3.3.0.2)
|
50
59
|
rainbow (>= 2.2.2, < 4.0)
|
51
|
-
regexp_parser (>=
|
52
|
-
|
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 (>=
|
56
|
-
rubocop-ast (1.
|
57
|
-
parser (>= 3.
|
58
|
-
|
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
|
-
|
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
|
-
|
64
|
-
|
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 (>=
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
102
|
-
|
103
|
-
|
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.
|
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
|
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:
|
data/data_plane_api.gemspec
CHANGED
@@ -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.
|
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
|
-
|
11
|
+
#: String | URI::Generic | nil
|
10
12
|
attr_writer :url
|
11
|
-
#
|
13
|
+
# Basic Auth username.
|
14
|
+
#: String?
|
12
15
|
attr_writer :basic_user
|
13
|
-
#
|
16
|
+
# Basic Auth password.
|
17
|
+
#: String?
|
14
18
|
attr_writer :basic_password
|
15
|
-
|
19
|
+
#: Logger?
|
16
20
|
attr_writer :logger
|
17
|
-
|
21
|
+
#: Integer?
|
18
22
|
attr_writer :timeout
|
19
|
-
#
|
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
|
23
|
-
# @param
|
24
|
-
# @param
|
25
|
-
|
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
|
-
|
63
|
+
#: -> Faraday::Connection
|
55
64
|
def connection
|
56
65
|
@connection || build_connection
|
57
66
|
end
|
58
67
|
|
59
|
-
|
68
|
+
#: -> void
|
60
69
|
def freeze
|
61
70
|
@connection = build_connection
|
62
71
|
super
|
63
72
|
end
|
64
73
|
|
65
|
-
|
74
|
+
#: -> (String | URI::Generic | nil)
|
66
75
|
def url
|
67
76
|
return @url if @global || @url
|
68
77
|
|
69
|
-
parent
|
78
|
+
parent&.url
|
70
79
|
end
|
71
80
|
|
72
|
-
#
|
81
|
+
# Basic Auth username.
|
82
|
+
#: -> String?
|
73
83
|
def basic_user
|
74
84
|
return @basic_user if @global || @basic_user
|
75
85
|
|
76
|
-
parent
|
86
|
+
parent&.basic_user
|
77
87
|
end
|
78
88
|
|
79
|
-
#
|
89
|
+
# Basic Auth password.
|
90
|
+
#: -> String?
|
80
91
|
def basic_password
|
81
92
|
return @basic_password if @global || @basic_password
|
82
93
|
|
83
|
-
parent
|
94
|
+
parent&.basic_password
|
84
95
|
end
|
85
96
|
|
86
|
-
|
97
|
+
#: -> Logger?
|
87
98
|
def logger
|
88
99
|
return @logger if @global || @logger
|
89
100
|
|
90
|
-
parent
|
101
|
+
parent&.logger
|
91
102
|
end
|
92
103
|
|
93
|
-
|
104
|
+
#: -> Integer?
|
94
105
|
def timeout
|
95
106
|
return @timeout if @global || @timeout
|
96
107
|
|
97
|
-
parent
|
108
|
+
parent&.timeout
|
98
109
|
end
|
99
110
|
|
100
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
10
|
-
|
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
|
16
|
-
# @param name
|
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
|
-
|
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
|
35
|
-
# @param name
|
36
|
-
|
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
|
-
|
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
|
-
|
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(
|
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
|
-
|
75
|
-
|
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:
|
81
|
-
url:
|
82
|
-
params:
|
75
|
+
method: request.http_method,
|
76
|
+
url: url,
|
77
|
+
params: request.params,
|
83
78
|
headers: request.headers,
|
84
|
-
body:
|
79
|
+
body: request.body,
|
85
80
|
}
|
86
81
|
response_hash = {
|
87
|
-
status:
|
88
|
-
body:
|
89
|
-
headers: response
|
82
|
+
status: response&.status,
|
83
|
+
body: response&.body,
|
84
|
+
headers: response&.headers,
|
90
85
|
}
|
91
86
|
|
92
|
-
logger
|
93
|
-
HAProxy #{request.http_method.to_s.upcase} #{
|
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-----
|
data/lib/data_plane_api.rb
CHANGED
@@ -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
|
-
|
16
|
-
# @return [Configuration]
|
16
|
+
#: { (Configuration) -> void } -> Configuration
|
17
17
|
def configure(&block)
|
18
18
|
block.call(CONFIG)
|
19
19
|
CONFIG
|