@@ -49,7 +49,16 @@ class Options; end # rubocop:disable Lint/EmptyClass
4949 # @!attribute domain
5050 # @return [String, nil] SNI override. This is only needed for self-hosted servers with certificates that do not
5151 # match the hostname being connected to.
52- class TLSOptions ; end # rubocop:disable Lint/EmptyClass
52+ class TLSOptions
53+ def initialize (
54+ client_cert : nil ,
55+ client_private_key : nil ,
56+ server_root_ca_cert : nil ,
57+ domain : nil
58+ )
59+ super
60+ end
61+ end
5362
5463 RPCRetryOptions = Data . define (
5564 :initial_interval ,
@@ -122,7 +131,9 @@ def initialize(interval: 30.0, timeout: 15.0)
122131 # @return [String, nil] Pass for HTTP basic auth for the proxy, must be combined with {basic_auth_user}.
123132 class HTTPConnectProxyOptions ; end # rubocop:disable Lint/EmptyClass
124133
125- # @return [Options] Frozen options for this client which has the same attributes as {initialize}.
134+ # @return [Options] Frozen options for this client which has the same attributes as {initialize}. Note that if
135+ # {api_key=} or {rpc_metadata=} are updated, the options object is replaced with those changes (it is not
136+ # mutated in place).
126137 attr_reader :options
127138
128139 # @return [WorkflowService] Raw gRPC workflow service.
@@ -183,6 +194,7 @@ def initialize(
183194 lazy_connect :
184195 ) . freeze
185196 # Create core client now if not lazy
197+ @core_client_mutex = Mutex . new
186198 _core_client unless lazy_connect
187199 # Create service instances
188200 @workflow_service = WorkflowService . new ( self )
@@ -206,11 +218,43 @@ def connected?
206218 !@core_client . nil?
207219 end
208220
221+ # @return [String, nil] API key. This is a shortcut for `options.api_key`.
222+ def api_key
223+ @options . api_key
224+ end
225+
226+ # Set the API key for all future calls. This also makes a new object for {options} with the changes.
227+ #
228+ # @param new_key [String, nil] New API key.
229+ def api_key = ( new_key )
230+ # Mutate the client if connected then mutate options
231+ @core_client_mutex . synchronize do
232+ @core_client &.update_api_key ( new_key )
233+ @options = @options . with ( api_key : new_key )
234+ end
235+ end
236+
237+ # @return [Hash<String, String>] RPC metadata (aka HTTP headers). This is a shortcut for `options.rpc_metadata`.
238+ def rpc_metadata
239+ @options . rpc_metadata
240+ end
241+
242+ # Set the RPC metadata (aka HTTP headers) for all future calls. This also makes a new object for {options} with
243+ # the changes.
244+ #
245+ # @param rpc_metadata [Hash<String, String>] New API key.
246+ def rpc_metadata = ( rpc_metadata )
247+ # Mutate the client if connected then mutate options
248+ @core_client_mutex . synchronize do
249+ @core_client &.update_metadata ( rpc_metadata )
250+ @options = @options . with ( rpc_metadata : rpc_metadata )
251+ end
252+ end
253+
209254 # @!visibility private
210255 def _core_client
211256 # If lazy, this needs to be done under mutex
212257 if @options . lazy_connect
213- @core_client_mutex ||= Mutex . new
214258 @core_client_mutex . synchronize do
215259 @core_client ||= new_core_client
216260 end
0 commit comments