Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Add header with user guid to service broker calls
Browse files Browse the repository at this point in the history
* Send the user's guid if available else omit the header

openservicebrokerapi/servicebroker#222

[#149216559]

Signed-off-by: Sam Gunaratne <sgunaratne@pivotal.io>
  • Loading branch information
Albertoimpl authored and Samze committed Aug 16, 2017
1 parent 09b38ea commit fc7c38d
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 165 deletions.
4 changes: 4 additions & 0 deletions lib/cloud_controller/security_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def self.current_user
Thread.current[:vcap_user]
end

def self.current_user_guid
current_user.guid if current_user
end

def self.admin?
roles.admin?
end
Expand Down
7 changes: 7 additions & 0 deletions lib/services/service_brokers/v2/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def make_request(method, uri, body, content_type)

client.default_header = default_headers
opts[:header]['Content-Type'] = content_type if content_type

user_guid = VCAP::CloudController::SecurityContext.current_user_guid
opts[:header][VCAP::Request::HEADER_BROKER_API_ORIGINATING_IDENTITY] = originating_identity(user_guid) if user_guid
headers = default_headers.merge(opts[:header])

logger.debug "Sending #{method} to #{uri}, BODY: #{body.inspect}, HEADERS: #{headers}"
Expand Down Expand Up @@ -159,6 +162,10 @@ def default_headers
}
end

def originating_identity(user_guid)
"cloudfoundry #{Base64.strict_encode64({ user_id: user_guid }.to_json)}"
end

def verify_certs?
!VCAP::CloudController::Config.config[:skip_cert_verify]
end
Expand Down
1 change: 1 addition & 0 deletions lib/vcap/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Request
HEADER_NAME = 'X-VCAP-Request-ID'.freeze
HEADER_BROKER_API_VERSION = 'X-Broker-Api-Version'.freeze
HEADER_API_INFO_LOCATION = 'X-Api-Info-Location'.freeze
HEADER_BROKER_API_ORIGINATING_IDENTITY = 'X-Broker-Api-Originating-Identity'.freeze

class << self
def current_id=(request_id)
Expand Down
Loading

0 comments on commit fc7c38d

Please sign in to comment.