@@ -15,6 +15,11 @@ class Client < DockerEngineRuby::Internal::Transport::BaseClient
1515 # Default max retry delay in seconds.
1616 DEFAULT_MAX_RETRY_DELAY = 8.0
1717
18+ # rubocop:disable Style/MutableConstant
19+ # @type [Hash{Symbol=>String}]
20+ ENVIRONMENTS = { production : "http://localhost:2375" , production_tls : "https://localhost:2376" }
21+ # rubocop:enable Style/MutableConstant
22+
1823 # @return [DockerEngineRuby::Resources::Auth]
1924 attr_reader :auth
2025
@@ -62,6 +67,13 @@ class Client < DockerEngineRuby::Internal::Transport::BaseClient
6267
6368 # Creates and returns a new client for interacting with the API.
6469 #
70+ # @param environment [:production, :production_tls, nil] Specifies the environment to use for the API.
71+ #
72+ # Each environment maps to a different base URL:
73+ #
74+ # - `production` corresponds to `http://localhost:2375`
75+ # - `production_tls` corresponds to `https://localhost:2376`
76+ #
6577 # @param base_url [String, nil] Override the default base URL for the API, e.g.,
6678 # `"https://api.example.com/v2/"`. Defaults to `ENV["DOCKER_BASE_URL"]`
6779 #
@@ -73,13 +85,17 @@ class Client < DockerEngineRuby::Internal::Transport::BaseClient
7385 #
7486 # @param max_retry_delay [Float]
7587 def initialize (
88+ environment : nil ,
7689 base_url : ENV [ "DOCKER_BASE_URL" ] ,
7790 max_retries : self . class ::DEFAULT_MAX_RETRIES ,
7891 timeout : self . class ::DEFAULT_TIMEOUT_IN_SECONDS ,
7992 initial_retry_delay : self . class ::DEFAULT_INITIAL_RETRY_DELAY ,
8093 max_retry_delay : self . class ::DEFAULT_MAX_RETRY_DELAY
8194 )
82- base_url ||= "http://localhost:2375"
95+ base_url ||= DockerEngineRuby ::Client ::ENVIRONMENTS . fetch ( environment &.to_sym || :production ) do
96+ message = "environment must be one of #{ DockerEngineRuby ::Client ::ENVIRONMENTS . keys } , got #{ environment } "
97+ raise ArgumentError . new ( message )
98+ end
8399
84100 super (
85101 base_url : base_url ,
0 commit comments