data_plane_api 0.1.1 → 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 +95 -38
- data/README.md +8 -1
- data/data_plane_api.gemspec +3 -1
- data/lib/data_plane_api/configuration.rb +52 -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.
|
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 '
|
8
|
+
gem 'byebug', '~> 12.0' # debugger
|
9
9
|
gem 'minitest', '~> 5.0' # Tests framework
|
10
10
|
gem 'rake', '~> 13.0' # Ruby automation tasks
|
11
11
|
gem 'rubocop', '~> 1.21' # Ruby linter
|
12
12
|
gem 'rubocop-espago', '~> 1.0' # Custom Ruby linter config
|
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,78 +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)
|
16
|
+
benchmark (0.2.1)
|
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
|
14
23
|
rexml
|
15
|
-
|
16
|
-
irb (>= 1.5.0)
|
17
|
-
reline (>= 0.3.1)
|
24
|
+
erubi (1.13.1)
|
18
25
|
faraday (2.7.2)
|
19
26
|
faraday-net_http (>= 2.0, < 3.1)
|
20
27
|
ruby2_keywords (>= 0.0.4)
|
21
28
|
faraday-net_http (3.0.2)
|
22
|
-
hashdiff (1.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
minitest (5.
|
28
|
-
|
29
|
-
|
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)
|
30
38
|
ast (~> 2.4.1)
|
31
|
-
|
39
|
+
racc
|
40
|
+
prism (1.4.0)
|
41
|
+
public_suffix (6.0.1)
|
42
|
+
racc (1.8.1)
|
32
43
|
rainbow (3.1.1)
|
33
44
|
rake (13.0.6)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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)
|
39
54
|
json (~> 2.3)
|
55
|
+
language_server-protocol (~> 3.17.0.2)
|
56
|
+
lint_roller (~> 1.1.0)
|
40
57
|
parallel (~> 1.10)
|
41
|
-
parser (>= 3.
|
58
|
+
parser (>= 3.3.0.2)
|
42
59
|
rainbow (>= 2.2.2, < 4.0)
|
43
|
-
regexp_parser (>=
|
44
|
-
|
45
|
-
rubocop-ast (>= 1.23.0, < 2.0)
|
60
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
61
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
46
62
|
ruby-progressbar (~> 1.7)
|
47
|
-
unicode-display_width (>=
|
48
|
-
rubocop-ast (1.
|
49
|
-
parser (>= 3.
|
50
|
-
|
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)
|
51
68
|
rubocop
|
52
|
-
|
69
|
+
rubocop-sorbet (0.10.0)
|
70
|
+
rubocop (>= 1)
|
71
|
+
ruby-progressbar (1.13.0)
|
53
72
|
ruby2_keywords (0.0.5)
|
54
73
|
shoulda-context (2.0.0)
|
55
|
-
|
56
|
-
|
57
|
-
|
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)
|
89
|
+
benchmark
|
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
|
98
|
+
thor (1.2.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)
|
58
105
|
addressable (>= 2.8.0)
|
59
106
|
crack (>= 0.3.2)
|
60
107
|
hashdiff (>= 0.4.0, < 2.0.0)
|
108
|
+
webrick (1.7.0)
|
109
|
+
yard (0.9.28)
|
110
|
+
webrick (~> 1.7.0)
|
111
|
+
yard-sorbet (0.9.0)
|
112
|
+
sorbet-runtime
|
113
|
+
yard
|
61
114
|
|
62
115
|
PLATFORMS
|
63
116
|
arm64-darwin-20
|
117
|
+
arm64-darwin-23
|
64
118
|
x86_64-linux
|
65
119
|
|
66
120
|
DEPENDENCIES
|
121
|
+
byebug (~> 12.0)
|
67
122
|
data_plane_api!
|
68
|
-
debug
|
69
123
|
minitest (~> 5.0)
|
70
124
|
rake (~> 13.0)
|
71
125
|
rubocop (~> 1.21)
|
72
126
|
rubocop-espago (~> 1.0)
|
127
|
+
rubocop-sorbet (~> 0.10.0)
|
73
128
|
shoulda-context (~> 2.0)
|
74
|
-
|
75
|
-
|
129
|
+
sorbet (~> 0.5)
|
130
|
+
tapioca (~> 0.16.11)
|
131
|
+
vcr (~> 6.3.1)
|
132
|
+
webmock (~> 3.25.1)
|
76
133
|
|
77
134
|
BUNDLED WITH
|
78
|
-
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,12 +45,14 @@ 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
|
43
52
|
@logger = logger
|
44
53
|
@timeout = timeout
|
45
54
|
@parent = parent
|
55
|
+
@connection = nil
|
46
56
|
|
47
57
|
return unless global
|
48
58
|
|
@@ -50,53 +60,67 @@ module DataPlaneApi
|
|
50
60
|
@timeout ||= 10
|
51
61
|
end
|
52
62
|
|
53
|
-
|
63
|
+
#: -> Faraday::Connection
|
54
64
|
def connection
|
55
65
|
@connection || build_connection
|
56
66
|
end
|
57
67
|
|
58
|
-
|
68
|
+
#: -> void
|
59
69
|
def freeze
|
60
70
|
@connection = build_connection
|
61
71
|
super
|
62
72
|
end
|
63
73
|
|
64
|
-
|
74
|
+
#: -> (String | URI::Generic | nil)
|
65
75
|
def url
|
66
76
|
return @url if @global || @url
|
67
77
|
|
68
|
-
parent
|
78
|
+
parent&.url
|
69
79
|
end
|
70
80
|
|
71
|
-
#
|
81
|
+
# Basic Auth username.
|
82
|
+
#: -> String?
|
72
83
|
def basic_user
|
73
84
|
return @basic_user if @global || @basic_user
|
74
85
|
|
75
|
-
parent
|
86
|
+
parent&.basic_user
|
76
87
|
end
|
77
88
|
|
78
|
-
#
|
89
|
+
# Basic Auth password.
|
90
|
+
#: -> String?
|
79
91
|
def basic_password
|
80
92
|
return @basic_password if @global || @basic_password
|
81
93
|
|
82
|
-
parent
|
94
|
+
parent&.basic_password
|
83
95
|
end
|
84
96
|
|
85
|
-
|
97
|
+
#: -> Logger?
|
86
98
|
def logger
|
87
99
|
return @logger if @global || @logger
|
88
100
|
|
89
|
-
parent
|
101
|
+
parent&.logger
|
90
102
|
end
|
91
103
|
|
92
|
-
|
104
|
+
#: -> Integer?
|
93
105
|
def timeout
|
94
106
|
return @timeout if @global || @timeout
|
95
107
|
|
96
|
-
parent
|
108
|
+
parent&.timeout
|
97
109
|
end
|
98
110
|
|
99
|
-
|
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?
|
100
124
|
def parent
|
101
125
|
return if @global
|
102
126
|
|
@@ -106,7 +130,7 @@ module DataPlaneApi
|
|
106
130
|
private
|
107
131
|
|
108
132
|
if ::Faraday::VERSION > '2'
|
109
|
-
|
133
|
+
#: -> Faraday::Connection
|
110
134
|
def build_connection
|
111
135
|
headers = { 'Content-Type' => 'application/json' }
|
112
136
|
|
@@ -119,7 +143,7 @@ module DataPlaneApi
|
|
119
143
|
else
|
120
144
|
# Faraday 1.x compatibility
|
121
145
|
|
122
|
-
|
146
|
+
#: -> Faraday::Connection
|
123
147
|
def build_connection
|
124
148
|
headers = { 'Content-Type' => 'application/json' }
|
125
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
|