Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions app/services/foreman_rh_cloud/cert_auth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,21 @@ def cert_auth_available?(organization)

def execute_cloud_request(params)
organization = params.delete(:organization)
certs = ForemanRhCloud.with_iop_smart_proxy? ? foreman_certificate : candlepin_id_cert(organization)
final_params = {
# Cache the value of with_iop_smart_proxy? to avoid multiple calls to the database
with_iop_smart_proxy = ForemanRhCloud.with_iop_smart_proxy?
certs = with_iop_smart_proxy ? foreman_certificate : candlepin_id_cert(organization)
default_params = {
ssl_client_cert: OpenSSL::X509::Certificate.new(certs[:cert]),
ssl_client_key: OpenSSL::PKey.read(certs[:key]),
}.deep_merge(params)
}

if with_iop_smart_proxy && organization&.label
default_params[:headers] = {
'X-Org-Id' => organization&.label,
}
end

final_params = default_params.deep_merge(params)

super(final_params)
end
Expand Down
26 changes: 0 additions & 26 deletions app/services/foreman_rh_cloud/gateway_request.rb

This file was deleted.

4 changes: 3 additions & 1 deletion app/services/foreman_rh_cloud/insights_api_forwarder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module ForemanRhCloud
class InsightsApiForwarder
include ForemanRhCloud::GatewayRequest
include ForemanRhCloud::CertAuth

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

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

request_opts[:organization] = organization

logger.debug("Sending request to: #{request_opts[:url]}")

execute_cloud_request(request_opts)
Expand Down
3 changes: 2 additions & 1 deletion app/services/foreman_rh_cloud/tags_auth.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ForemanRhCloud
class TagsAuth
include GatewayRequest
include CertAuth

TAG_NAMESPACE = 'sat_iam'.freeze
TAG_SHORT_NAME = 'scope'.freeze
Expand All @@ -24,6 +24,7 @@ def update_tag

payload = tags_query_payload
params = {
organization: @org,
method: :post,
url: "#{InsightsCloud.gateway_url}/tags",
headers: {
Expand Down
3 changes: 2 additions & 1 deletion lib/foreman_inventory_upload/async/upload_report_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def command
def env
env_vars = super.merge(
'FILES' => filename,
'CER_PATH' => @cer_path
'CER_PATH' => @cer_path,
'ORG_ID' => organization.label
)

http_proxy_string = ForemanRhCloud.http_proxy_string
Expand Down
8 changes: 7 additions & 1 deletion lib/foreman_inventory_upload/scripts/uploader.sh.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ else
AUTH_VAL="\"$RH_USERNAME\":\"$RH_PASSWORD\""
fi

ORG_HEADER=()
if [ -n "$ORG_ID" ]
then
+ ORG_HEADER=("-H" "X-Org-Id: $ORG_ID")
fi

# /tmp/a b/x.pem
# curl --cert /tmp/a\ b/x.pem

Expand All @@ -36,7 +42,7 @@ mkdir -p $DONE_DIR

for f in $FILES
do
curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL"
curl -k -vvv -# --fail -F "file=@$f;type=application/vnd.redhat.qpc.tar+tgz" $DEST "$AUTH_KEY" "$AUTH_VAL" "${ORG_HEADER[@]}"
status=$?
if [ $status -eq 0 ]; then
mv $f $DONE_DIR
Expand Down
9 changes: 8 additions & 1 deletion lib/insights_cloud/async/vmaas_reposcan_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ def plan(repo, *_args)
return
end

plan_self
organization_id = Katello::Repository.find(repo_id).organization_id

plan_self(organization_id: organization_id)
end

def run
url = ::InsightsCloud.vmaas_reposcan_sync_url

response = execute_cloud_request(
organization: organization,
method: :put,
url: url,
headers: { 'Content-Type' => 'application/json' }
Expand Down Expand Up @@ -61,6 +64,10 @@ def rescue_strategy_for_self
Dynflow::Action::Rescue::Skip
end

def organization
@organization ||= Organization.find(input[:organization_id])
end

private

def logger
Expand Down
14 changes: 12 additions & 2 deletions test/unit/lib/insights_cloud/async/vmaas_reposcan_sync_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
include ForemanTasks::TestHelpers::WithInThreadExecutor

setup do
@repo_payload = { id: 123 }
@root = FactoryBot.build(:katello_root_repository, :fedora_17_x86_64_dev_root)
@root.save(validate: false)
@repo = FactoryBot.create(
:katello_repository,
:with_product,
distribution_family: 'Red Hat',
distribution_version: '7.5',
root: @root
)
@repo_payload = { id: @repo.id }
@expected_url = 'https://example.com/api/v1/vmaas/reposcan/sync'
InsightsCloud.stubs(:vmaas_reposcan_sync_url).returns(@expected_url)
ForemanRhCloud.stubs(:with_iop_smart_proxy?).returns(true)
Expand Down Expand Up @@ -68,7 +77,8 @@ class VmaasReposcanSyncTest < ActiveSupport::TestCase
params[:method] == :put &&
params[:url] == @expected_url &&
params[:headers].is_a?(Hash) &&
params[:headers]['Content-Type'] == 'application/json'
params[:headers]['Content-Type'] == 'application/json' &&
params[:organization] == @repo.organization
end
.returns(mock_response)

Expand Down