Skip to content

Commit dbe2753

Browse files
committed
Add X-Org-Id header for IoP requests
1 parent 6ac79f4 commit dbe2753

File tree

6 files changed

+23
-31
lines changed

6 files changed

+23
-31
lines changed

app/services/foreman_rh_cloud/cert_auth.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ def execute_cloud_request(params)
1515
final_params = {
1616
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
1717
ssl_client_key: OpenSSL::PKey.read(certs[:key]),
18-
}.deep_merge(params)
18+
headers: {
19+
'X-Org-Id' => ForemanRhCloud.with_iop_smart_proxy? ? organization&.label : nil,
20+
},
21+
}.compact.deep_merge(params)
1922

2023
super(final_params)
2124
end

app/services/foreman_rh_cloud/gateway_request.rb

Lines changed: 0 additions & 26 deletions
This file was deleted.

app/services/foreman_rh_cloud/insights_api_forwarder.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module ForemanRhCloud
44
class InsightsApiForwarder
5-
include ForemanRhCloud::GatewayRequest
5+
include ForemanRhCloud::CertAuth
66

77
SCOPED_REQUESTS = [
88
{ test: %r{api/vulnerability/v1/vulnerabilities/cves}, tag_name: :tags },
@@ -26,6 +26,8 @@ def forward_request(original_request, path, controller_name, user, organization,
2626

2727
request_opts = prepare_request_opts(original_request, path, forward_payload, forward_params)
2828

29+
request_opts[:organization] = organization
30+
2931
logger.debug("Sending request to: #{request_opts[:url]}")
3032

3133
execute_cloud_request(request_opts)

app/services/foreman_rh_cloud/tags_auth.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module ForemanRhCloud
22
class TagsAuth
3-
include GatewayRequest
3+
include CertAuth
44

55
TAG_NAMESPACE = 'sat_iam'.freeze
66
TAG_SHORT_NAME = 'scope'.freeze
@@ -24,6 +24,7 @@ def update_tag
2424

2525
payload = tags_query_payload
2626
params = {
27+
organization: @org,
2728
method: :post,
2829
url: "#{InsightsCloud.gateway_url}/tags",
2930
headers: {

lib/foreman_inventory_upload/scripts/uploader.sh.erb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ else
2727
AUTH_VAL="\"$RH_USERNAME\":\"$RH_PASSWORD\""
2828
fi
2929

30+
if [ -n "$ORG_ID" ]
31+
then
32+
ORG_HEADER="-H \"X-Org-Id: $ORG_ID\""
33+
fi
34+
3035
# /tmp/a b/x.pem
3136
# curl --cert /tmp/a\ b/x.pem
3237

@@ -36,7 +41,7 @@ mkdir -p $DONE_DIR
3641

3742
for f in $FILES
3843
do
39-
curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL"
44+
curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL" "$ORG_HEADER"
4045
status=$?
4146
if [ $status -eq 0 ]; then
4247
mv $f $DONE_DIR

lib/insights_cloud/async/vmaas_reposcan_sync.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ def plan(repo, *_args)
2323
return
2424
end
2525

26-
plan_self
26+
organization_id = Katello::Repository.find(repo_id).environment.organization_id
27+
28+
plan_self(organization_id: organization_id)
2729
end
2830

2931
def run
3032
url = ::InsightsCloud.vmaas_reposcan_sync_url
3133

3234
response = execute_cloud_request(
35+
organization: organization,
3336
method: :put,
3437
url: url,
3538
headers: { 'Content-Type' => 'application/json' }
@@ -61,6 +64,10 @@ def rescue_strategy_for_self
6164
Dynflow::Action::Rescue::Skip
6265
end
6366

67+
def organization
68+
@organization ||= Organization.find(input[:organization_id])
69+
end
70+
6471
private
6572

6673
def logger

0 commit comments

Comments
 (0)