Class: IbmAppconfigurationRubySdk::UrlBuilder
- Inherits:
-
Object
- Object
- IbmAppconfigurationRubySdk::UrlBuilder
- Includes:
- Singleton
- Defined in:
- lib/ibm_appconfiguration_ruby_sdk/url_builder.rb
Constant Summary collapse
- HTTPS_PROTOCOL =
Constants for URL construction
"https://"- WEBSOCKET_PROTOCOL =
"wss://"- BASE_URL =
".apprapp.cloud.ibm.com"- WEBSOCKET_PATH =
"/wsfeature"- SERVICE_PATH =
"/apprapp"- PRIVATE_ENDPOINT_PREFIX =
"private."- IAM_TEST_URL =
IAM URLs
"iam.test.cloud.ibm.com/identity/token"- IAM_PROD_URL =
"iam.cloud.ibm.com/identity/token"
Instance Attribute Summary collapse
-
#apikey ⇒ String
Get the API key.
-
#region ⇒ String
Get the region value.
-
#use_private_endpoint ⇒ Boolean
writeonly
Enable or disable private endpoint usage.
Instance Method Summary collapse
-
#base_service_url ⇒ String
Get the base URL for the App Configuration service instance.
-
#base_service_url=(value) ⇒ String
Set the overridden base service URL.
-
#guid ⇒ String
Get the service instance GUID.
-
#guid=(value) ⇒ String
Set the service instance GUID.
-
#iam_url ⇒ String
Get the IAM (Identity and Access Management) URL for authentication.
-
#initialize ⇒ UrlBuilder
constructor
Initialize the UrlBuilder with default values.
-
#inspect ⇒ String
Returns a developer-friendly string that masks the API key to prevent accidental credential exposure in logs and test output.
-
#override_websocket_url=(value) ⇒ Object
Override the WebSocket URL directly.
-
#set_base_service_url(value) ⇒ Object
Alias for base_service_url= to match AppConfiguration usage.
-
#set_override_websocket_url(value) ⇒ Object
Alias for override_websocket_url=.
-
#set_websocket_url(collection_id, environment_id) ⇒ String
Set the WebSocket URL with collection and environment IDs.
-
#use_private_endpoint? ⇒ Boolean
Check if private endpoint is enabled.
-
#websocket_url ⇒ String?
Get the WebSocket URL.
Constructor Details
#initialize ⇒ UrlBuilder
Initialize the UrlBuilder with default values
49 50 51 52 53 54 55 56 57 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 49 def initialize @region = "" @instance_guid = nil @apikey = nil @override_service_url = nil @override_websocket_url = nil @use_private_endpoint = false @websocket_full_url = nil end |
Instance Attribute Details
#apikey ⇒ String
Get the API key
98 99 100 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 98 def apikey @apikey end |
#region ⇒ String
Get the region value
69 70 71 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 69 def region @region end |
#use_private_endpoint=(value) ⇒ Boolean (writeonly)
Enable or disable private endpoint usage. When enabled, all URLs will use IBM Cloud private network routing.
243 244 245 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 243 def use_private_endpoint=(value) @use_private_endpoint = value end |
Instance Method Details
#base_service_url ⇒ String
Get the base URL for the App Configuration service instance. Returns the appropriate URL based on environment and endpoint type.
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 147 def base_service_url # For dev & stage environments if @override_service_url return add_private_prefix_to_url(@override_service_url) if @use_private_endpoint return @override_service_url end # For production return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{@region}#{BASE_URL}" if @use_private_endpoint "#{HTTPS_PROTOCOL}#{@region}#{BASE_URL}" end |
#base_service_url=(value) ⇒ String
Set the overridden base service URL. Used for testing, development, or staging environments.
106 107 108 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 106 def base_service_url=(value) @override_service_url = value end |
#guid ⇒ String
Get the service instance GUID
84 85 86 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 84 def guid @instance_guid end |
#guid=(value) ⇒ String
Set the service instance GUID
76 77 78 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 76 def guid=(value) @instance_guid = value end |
#iam_url ⇒ String
Get the IAM (Identity and Access Management) URL for authentication.
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 175 def iam_url # For dev & stage environments if @override_service_url return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{IAM_TEST_URL}" if @use_private_endpoint return "#{HTTPS_PROTOCOL}#{IAM_TEST_URL}" end # For production return "#{HTTPS_PROTOCOL}#{PRIVATE_ENDPOINT_PREFIX}#{IAM_PROD_URL}" if @use_private_endpoint "#{HTTPS_PROTOCOL}#{IAM_PROD_URL}" end |
#inspect ⇒ String
Returns a developer-friendly string that masks the API key to prevent accidental credential exposure in logs and test output.
258 259 260 261 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 258 def inspect masked = @apikey ? "#{@apikey[0..3]}#{'*' * [@apikey.length - 4, 0].max}" : "nil" "#<#{self.class} region=#{@region.inspect} apikey=#{masked}>" end |
#override_websocket_url=(value) ⇒ Object
Override the WebSocket URL directly. Used for local dev/testing when the WebSocket server runs on a different port or host than the HTTP service URL (e.g. ws://127.0.0.1:5000).
122 123 124 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 122 def override_websocket_url=(value) @override_websocket_url = value end |
#set_base_service_url(value) ⇒ Object
Alias for base_service_url= to match AppConfiguration usage
112 113 114 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 112 def set_base_service_url(value) self.base_service_url = value end |
#set_override_websocket_url(value) ⇒ Object
Alias for override_websocket_url=
128 129 130 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 128 def set_override_websocket_url(value) self.override_websocket_url = value end |
#set_websocket_url(collection_id, environment_id) ⇒ String
Set the WebSocket URL with collection and environment IDs. Constructs the complete WebSocket URL with query parameters.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 201 def set_websocket_url(collection_id, environment_id) if @override_service_url # For dev & stage environments — mirror http->ws, https->wss ws_scheme = @override_service_url.start_with?("https") ? "wss://" : "ws://" temp = @override_service_url.gsub(%r{https?://}, "") ws = ws_scheme.dup ws += PRIVATE_ENDPOINT_PREFIX if @use_private_endpoint ws += temp else # For production — always wss:// ws = WEBSOCKET_PROTOCOL.dup ws += PRIVATE_ENDPOINT_PREFIX if @use_private_endpoint ws += @region ws += BASE_URL end @websocket_full_url = "#{ws}#{SERVICE_PATH}#{WEBSOCKET_PATH}?" \ "instance_id=#{@instance_guid}&" \ "collection_id=#{collection_id}&" \ "environment_id=#{environment_id}" end |
#use_private_endpoint? ⇒ Boolean
Check if private endpoint is enabled
249 250 251 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 249 def use_private_endpoint? @use_private_endpoint end |
#websocket_url ⇒ String?
Get the WebSocket URL. Returns the manually overridden URL if set, otherwise the constructed one.
228 229 230 |
# File 'lib/ibm_appconfiguration_ruby_sdk/url_builder.rb', line 228 def websocket_url @override_websocket_url || @websocket_full_url end |