From 264e236d768f453042c9280cf670e2015356b511 Mon Sep 17 00:00:00 2001 From: Mateusz Drewniak Date: Tue, 9 Sep 2025 19:26:59 +0200 Subject: [PATCH] Add support for api_url per HAProxy backend --- .ruby-version | 2 +- CHANGELOG.md | 8 +++-- Gemfile.lock | 3 +- lib/capistrano/data_plane_api.rb | 30 +++++++++---------- .../data_plane_api/configuration/backend.rb | 1 + .../data_plane_api/configuration/backend.rbi | 6 ++++ templates/config/data_plane_api.yml | 1 + 7 files changed, 32 insertions(+), 19 deletions(-) diff --git a/.ruby-version b/.ruby-version index 4d9d11c..4f5e697 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.4.2 +3.4.5 diff --git a/CHANGELOG.md b/CHANGELOG.md index d722dbd..e3a021b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,15 @@ ## [Unreleased] -## [0.2.0] - 2025-04-11 +## [0.3.0] - 09.09.2025 + +- Add `api_url` per HAProxy backend + +## [0.2.0] - 11.04.2025 - Update `data_plane_api` to `>= 0.2.0` - Add the `-C`/`--check` flag to `bin/deploy` - Rewrite YARD to sorbet (with inline RBS) -## [0.1.0] - 2022-12-28 +## [0.1.0] - 28.12.2022 - Initial release diff --git a/Gemfile.lock b/Gemfile.lock index 131c109..034cdbf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -147,6 +147,7 @@ GEM PLATFORMS arm64-darwin-20 arm64-darwin-23 + arm64-darwin-24 x86_64-linux DEPENDENCIES @@ -164,4 +165,4 @@ DEPENDENCIES webmock (~> 3.25.1) BUNDLED WITH - 2.6.7 + 2.7.2 diff --git a/lib/capistrano/data_plane_api.rb b/lib/capistrano/data_plane_api.rb index 44be19e..465c322 100644 --- a/lib/capistrano/data_plane_api.rb +++ b/lib/capistrano/data_plane_api.rb @@ -91,10 +91,10 @@ def server_set_drain(deployment_stage, force: false, config: nil) validate_backend_state(haproxy_backend, haproxy_server) unless force conf = ::DataPlaneApi::Configuration.new( - basic_user: haproxy_backend.basic_user || @configuration.basic_user, - basic_password: haproxy_backend.basic_password || @configuration.basic_password, + basic_user: haproxy_backend.basic_user || configuration.basic_user, + basic_password: haproxy_backend.basic_password || configuration.basic_password, + url: haproxy_backend.api_url || configuration.api_url, parent: config, - url: configuration.api_url, ) # set the target server's state to `drain` @@ -128,10 +128,10 @@ def server_set_maint(deployment_stage, force: false, config: nil) validate_backend_state(haproxy_backend, haproxy_server) unless force conf = ::DataPlaneApi::Configuration.new( - basic_user: haproxy_backend.basic_user || @configuration.basic_user, - basic_password: haproxy_backend.basic_password || @configuration.basic_password, + basic_user: haproxy_backend.basic_user || configuration.basic_user, + basic_password: haproxy_backend.basic_password || configuration.basic_password, + url: haproxy_backend.api_url || configuration.api_url, parent: config, - url: configuration.api_url, ) # set the target server's state to `maint` @@ -162,10 +162,10 @@ def server_set_ready(deployment_stage, config: nil) return if servers.length < 2 # skip HAProxy if there is only a single server conf = ::DataPlaneApi::Configuration.new( - basic_user: haproxy_backend.basic_user || @configuration.basic_user, - basic_password: haproxy_backend.basic_password || @configuration.basic_password, + basic_user: haproxy_backend.basic_user || configuration.basic_user, + basic_password: haproxy_backend.basic_password || configuration.basic_password, + url: haproxy_backend.api_url || configuration.api_url, parent: config, - url: configuration.api_url, ) # set the target server's state to `drain` @@ -250,10 +250,10 @@ def find_server_and_backend(deployment_stage) def get_backend_servers_settings(backend_name, config: nil) haproxy_backend = find_backend(backend_name) conf = ::DataPlaneApi::Configuration.new( - basic_user: haproxy_backend.basic_user || @configuration.basic_user, - basic_password: haproxy_backend.basic_password || @configuration.basic_password, + basic_user: haproxy_backend.basic_user || configuration.basic_user, + basic_password: haproxy_backend.basic_password || configuration.basic_password, + url: haproxy_backend.api_url || configuration.api_url, parent: config, - url: configuration.api_url, ) response = ::DataPlaneApi::Server.get_runtime_settings( backend: backend_name.to_s, @@ -271,10 +271,10 @@ def get_backend_servers_settings(backend_name, config: nil) def get_server_settings(backend_name, server_name, config: nil) haproxy_backend = find_backend(backend_name) conf = ::DataPlaneApi::Configuration.new( - basic_user: haproxy_backend.basic_user || @configuration.basic_user, - basic_password: haproxy_backend.basic_password || @configuration.basic_password, + basic_user: haproxy_backend.basic_user || configuration.basic_user, + basic_password: haproxy_backend.basic_password || configuration.basic_password, + url: haproxy_backend.api_url || configuration.api_url, parent: config, - url: configuration.api_url, ) response = ::DataPlaneApi::Server.get_runtime_settings( backend: backend_name.to_s, diff --git a/lib/capistrano/data_plane_api/configuration/backend.rb b/lib/capistrano/data_plane_api/configuration/backend.rb index e89d29d..413d505 100644 --- a/lib/capistrano/data_plane_api/configuration/backend.rb +++ b/lib/capistrano/data_plane_api/configuration/backend.rb @@ -11,6 +11,7 @@ class Configuration < Type class Backend < Type attribute :name, ::Shale::Type::String attribute :styles, Symbol, collection: true + attribute :api_url, ::Shale::Type::String attribute :basic_user, ::Shale::Type::String attribute :basic_password, ::Shale::Type::String attribute :servers, Server, collection: true diff --git a/sorbet/rbi/dsl/capistrano/data_plane_api/configuration/backend.rbi b/sorbet/rbi/dsl/capistrano/data_plane_api/configuration/backend.rbi index e27c118..b9df24b 100644 --- a/sorbet/rbi/dsl/capistrano/data_plane_api/configuration/backend.rbi +++ b/sorbet/rbi/dsl/capistrano/data_plane_api/configuration/backend.rbi @@ -9,6 +9,12 @@ class Capistrano::DataPlaneApi::Configuration::Backend include ShaleAttributeMethods module ShaleAttributeMethods + sig { returns(T.nilable(String)) } + def api_url; end + + sig { params(value: T.nilable(String)).returns(T.nilable(String)) } + def api_url=(value); end + sig { returns(T.nilable(String)) } def basic_password; end diff --git a/templates/config/data_plane_api.yml b/templates/config/data_plane_api.yml index e83fae6..2a13e2e 100644 --- a/templates/config/data_plane_api.yml +++ b/templates/config/data_plane_api.yml @@ -44,6 +44,7 @@ backends: styles: - :bold - :on_green + api_url: http://example.com/other-haproxy-data-plane-api # You can use ERB to read data from Environment Variables. basic_user: <%= ENV['USER'] %> basic_password: <%= ENV['PASS'] %>