chalk_ruby 0.2.2 → 0.2.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 341f9bbb82ba439be2de0671adc74c8e901a96c3f63d3fb5a7c2e1880a983342
4
- data.tar.gz: 3743783f522eb70c6cefba1158682aaae89f45049a61078eb7b72f19ebf0cc8d
3
+ metadata.gz: cfe57e2b3d1f09eaa9dece4b777788941b347319bca50b3242c52070287aa86f
4
+ data.tar.gz: '039220d201af61aff4e19fc73ea242a797b8681f87dc449e13187996eae653e6'
5
5
  SHA512:
6
- metadata.gz: 76715dafed5ffcd9564c7e5fcce4a568bd77603236fffca6a4f3002d2ea1c3d0f9840840b126503341ac8d7ea19cd6152a68182574fd7cf4425869019b5ec950
7
- data.tar.gz: dd0cf075a2985efa6550a948d0240dfe039920b6fe5e76d054e3f3756a339fc55e24acbbcea5f1a27ff59df4b602609411af4491fee784c1001377f710815080
6
+ metadata.gz: cc1d7cbfcdb2175ee61773918800270f963b136fea24573b06b97a8b22225f5488c9fed440755d964f32577822d61021122469c75c65b7e5271b19cccec03489
7
+ data.tar.gz: 79b8d14bbf904286f5589542dc85a0ff471b7e79ad675860893bd3e7fdaf9ceb3736a57773ed8bc78da9709a41df34dc6d4badcedad6d0c427a851dfb029aad0
@@ -16,6 +16,7 @@ module ChalkRuby
16
16
  :query_timeout,
17
17
  :api_timeout,
18
18
  :connect_timeout,
19
+ :query_service_root_ca_path,
19
20
  :additional_headers
20
21
 
21
22
  # Creates a new ChalkRuby::Config object for use with ChalkRuby::Client.
@@ -45,18 +46,22 @@ module ChalkRuby
45
46
  # @option options [Float?] :connect_timeout
46
47
  # The timeout for connect operations (in seconds).
47
48
  #
49
+ # @option options [String?] :query_service_root_ca_path
50
+ # The root ca to use for trusting SSL verifying connections to the query server in grpc.
51
+ #
48
52
  # @option options [Hash<String, String>?] :additional_headers
49
53
  # Additional headers to be sent with every request. Typically not required.
50
54
  #
51
55
  def initialize(opts = {})
52
- @client_id = opts[:client_id] || ENV['CHALK_CLIENT_ID']
53
- @client_secret = opts[:client_secret] || ENV['CHALK_CLIENT_SECRET']
54
- @environment = opts[:environment] || ENV['CHALK_ACTIVE_ENVIRONMENT']
55
- @query_server = opts[:query_server] || ENV['CHALK_QUERY_SERVER'] || Defaults::QUERY_SERVER
56
- @api_server = opts[:api_server] || ENV['CHALK_API_SERVER'] || Defaults::API_SERVER
57
- @query_timeout = opts[:query_timeout] || Defaults::QUERY_TIMEOUT
58
- @api_timeout = opts[:api_timeout] || Defaults::API_TIMEOUT
59
- @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
56
+ @client_id = opts[:client_id] || ENV['CHALK_CLIENT_ID']
57
+ @client_secret = opts[:client_secret] || ENV['CHALK_CLIENT_SECRET']
58
+ @environment = opts[:environment] || ENV['CHALK_ACTIVE_ENVIRONMENT']
59
+ @query_server = opts[:query_server] || ENV['CHALK_QUERY_SERVER'] || Defaults::QUERY_SERVER
60
+ @api_server = opts[:api_server] || ENV['CHALK_API_SERVER'] || Defaults::API_SERVER
61
+ @query_timeout = opts[:query_timeout] || Defaults::QUERY_TIMEOUT
62
+ @api_timeout = opts[:api_timeout] || Defaults::API_TIMEOUT
63
+ @connect_timeout = opts[:connect_timeout] || Defaults::CONNECT_TIMEOUT
64
+ @query_service_root_ca_path = opts[:query_service_root_ca_path] || Defaults::ROOT_CA_PATH
60
65
  @additional_headers = opts[:additional_headers] || {}
61
66
 
62
67
  raise ChalkError, 'No Client ID provided, please set :client_id' if @client_id.nil?
@@ -32,6 +32,10 @@ module ChalkRuby
32
32
  API_TIMEOUT = 300
33
33
  QUERY_TIMEOUT = 1200
34
34
 
35
+ # GRPC
36
+ # ----------------------------------------
37
+ ROOT_CA_PATH = nil
38
+
35
39
  WAIT_TASK_DEFAULT_TIME_BEFORE_RETRY = 100
36
40
  end
37
41
  end
@@ -1,5 +1,13 @@
1
1
  require 'chalk_ruby/config'
2
2
  require 'grpc'
3
+ require 'google/protobuf/struct_pb'
4
+ require 'chalk_ruby/protos/chalk/server/v1/auth_pb'
5
+ require 'chalk_ruby/protos/chalk/server/v1/auth_services_pb'
6
+ require 'chalk_ruby/protos/chalk/engine/v1/query_server_services_pb'
7
+ require 'date'
8
+ require 'chalk_ruby/grpc/auth_interceptor'
9
+ require 'chalk_ruby/error'
10
+
3
11
 
4
12
  module ChalkRuby
5
13
 
@@ -175,18 +183,14 @@ module ChalkRuby
175
183
  end
176
184
 
177
185
  def get_token
178
- Token.new(
179
- api_server_request(
180
- method: :post,
181
- path: '/v1/oauth/token',
182
- body: {
183
- client_id: @config.client_id,
184
- client_secret: @config.client_secret,
185
- grant_type: 'client_credentials'
186
- },
187
- headers: get_unauthenticated_headers
186
+ response = @auth_stub.get_token(
187
+ Chalk::Server::V1::GetTokenRequest.new(
188
+ client_id: @config.client_id,
189
+ client_secret: @config.client_secret
188
190
  )
189
191
  )
192
+
193
+ response.access_token
190
194
  end
191
195
 
192
196
  def get_unauthenticated_headers
@@ -272,7 +276,14 @@ module ChalkRuby
272
276
 
273
277
  def query_service
274
278
  if @query_service.nil?
275
- @query_service = Chalk::Engine::V1::QueryService::Stub.new(query_server_host, GRPC::Core::ChannelCredentials.new(), interceptors: [engine_interceptor])
279
+ channel_creds =
280
+ if @config.query_service_root_ca_path.nil?
281
+ GRPC::Core::ChannelCredentials.new
282
+ else
283
+ GRPC::Core::ChannelCredentials.new(File.read(@config.query_service_root_ca_path))
284
+ end
285
+
286
+ @query_service = Chalk::Engine::V1::QueryService::Stub.new(query_server_host, channel_creds, interceptors: [engine_interceptor])
276
287
  end
277
288
 
278
289
  @query_service
@@ -317,21 +328,21 @@ module ChalkRuby
317
328
  def convert_to_protobuf_value(value)
318
329
  case value
319
330
  when NilClass
320
- Google::Protobuf::Value.new(null_value: :NULL_VALUE)
331
+ ::Google::Protobuf::Value.new(null_value: :NULL_VALUE)
321
332
  when Float
322
- Google::Protobuf::Value.new(number_value: value)
333
+ ::Google::Protobuf::Value.new(number_value: value)
323
334
  when Integer
324
- Google::Protobuf::Value.new(number_value: value)
335
+ ::Google::Protobuf::Value.new(number_value: value)
325
336
  when String
326
- Google::Protobuf::Value.new(string_value: value)
337
+ ::Google::Protobuf::Value.new(string_value: value)
327
338
  when TrueClass, FalseClass
328
- Google::Protobuf::Value.new(bool_value: value)
339
+ ::Google::Protobuf::Value.new(bool_value: value)
329
340
  when Hash
330
341
  struct_value = Google::Protobuf::Struct.new(fields: value.transform_values { |v| convert_to_protobuf_value(v) })
331
- Google::Protobuf::Value.new(struct_value: struct_value)
342
+ ::Google::Protobuf::Value.new(struct_value: struct_value)
332
343
  when Array
333
344
  list_value = Google::Protobuf::ListValue.new(values: value.map { |v| convert_to_protobuf_value(v) })
334
- Google::Protobuf::Value.new(list_value: list_value)
345
+ ::Google::Protobuf::Value.new(list_value: list_value)
335
346
  else
336
347
  raise "Unsupported type: #{value.class}"
337
348
  end
@@ -2,6 +2,7 @@ require 'faraday'
2
2
  # Default adapter needs to be required to be registered
3
3
  require 'faraday/net_http_persistent' unless Faraday::VERSION < '1'
4
4
  require 'chalk_ruby/error'
5
+ require 'chalk_ruby/helpers'
5
6
 
6
7
  module ChalkRuby
7
8
  module Http
@@ -1,3 +1,3 @@
1
1
  module ChalkRuby
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.4'.freeze
3
3
  end
@@ -3,6 +3,7 @@ require 'rspec/autorun'
3
3
  require 'chalk_ruby/client'
4
4
  require 'chalk_ruby/error'
5
5
 
6
+
6
7
  CLIENT_ID = ''
7
8
  CLIENT_SECRET = ''
8
9
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chalk_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chalk AI, Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-21 00:00:00.000000000 Z
11
+ date: 2025-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler