Class: BitsService::ResourcePool

Inherits:
Object
  • Object
show all
Includes:
SignatureUtil
Defined in:
lib/bits_service_client/resource_pool.rb

Instance Method Summary collapse

Methods included from SignatureUtil

#seconds_since_the_unix_epoch_with_offset, #sign_signature

Constructor Details

#initialize(bits_service_options:, request_timeout_in_seconds:, vcap_request_id: '') ⇒ ResourcePool

Returns a new instance of ResourcePool.



9
10
11
12
13
14
15
16
17
18
# File 'lib/bits_service_client/resource_pool.rb', line 9

def initialize(bits_service_options:, request_timeout_in_seconds:, vcap_request_id: '')
  @private_endpoint = URI.parse(bits_service_options[:private_endpoint])
  @public_endpoint = URI.parse(bits_service_options[:public_endpoint])
  @request_timeout_in_seconds = request_timeout_in_seconds
  @signed_key_secret = validated(bits_service_options, :signing_key_secret)
  @signed_key_id = validated(bits_service_options, :signing_key_id)
  @vcap_request_id = vcap_request_id
  @logger = Steno.logger('cc.bits_service_client')
  @ca_cert_path = bits_service_options[:ca_cert_path]
end

Instance Method Details

#bundles(resources_json, entries_path) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/bits_service_client/resource_pool.rb', line 30

def bundles(resources_json, entries_path)
  if entries_path.to_s == ''
    post('/app_stash/bundles', resources_json, @vcap_request_id).tap do |response|
      validate_response_code!(200, response)
    end
  else
    validate_file! entries_path
    body = {
      resources: UploadIO.new(StringIO.new(resources_json), 'application/json', 'resources.json'),
      application: UploadIO.new(entries_path, 'application/octet-stream', 'entries.zip')
    }
    multipart_post('/app_stash/bundles', body, @vcap_request_id).tap do |response|
      validate_response_code!(200, response)
    end
  end
end

#matches(resources_json) ⇒ Object



20
21
22
23
24
# File 'lib/bits_service_client/resource_pool.rb', line 20

def matches(resources_json)
  post('/app_stash/matches', resources_json, @vcap_request_id).tap do |response|
    validate_response_code!(200, response)
  end
end

#signed_matches_urlObject



26
27
28
# File 'lib/bits_service_client/resource_pool.rb', line 26

def signed_matches_url
  "#{@public_endpoint}#{self.sign_signature('POST','/app_stash/matches', @signed_key_secret, @signed_key_id)}"
end