Skip to content

Commit

Permalink
Fixes #15818 - Show which capsule a host is registered through
Browse files Browse the repository at this point in the history
This displays the system that a host is registered through in a
'registered_through' field that is searchable and displayed in the
content host details page. If the host is registered to the main
katello server, the field will display that.
  • Loading branch information
John Mitsch committed Aug 5, 2016
1 parent 407d3ae commit 8597c85
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
16 changes: 16 additions & 0 deletions app/controllers/katello/api/rhsm/candlepin_proxies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def consumer_create
sync_task(::Actions::Katello::Host::Register, host, System.new, rhsm_params, content_view_environment)
host.reload

update_host_registered_through(host, request.headers)

render :json => Resources::Candlepin::Consumer.get(host.subscription_facet.uuid)
end

Expand Down Expand Up @@ -226,6 +228,8 @@ def consumer_activate
activation_keys.first.organization, rhsm_params)

sync_task(::Actions::Katello::Host::Register, host, System.new, rhsm_params, nil, activation_keys)

update_host_registered_through(host, request.headers)
host.reload

render :json => Resources::Candlepin::Consumer.get(host.subscription_facet.uuid)
Expand All @@ -249,6 +253,7 @@ def facts
User.as_anonymous_admin do
sync_task(::Actions::Katello::Host::Update, @host, rhsm_params)
Katello::Host::SubscriptionFacet.update_facts(@host, rhsm_params[:facts]) unless rhsm_params[:facts].nil?
update_host_registered_through(@host, request.headers)
end
render :json => {:content => _("Facts successfully updated.")}, :status => 200
end
Expand All @@ -259,6 +264,12 @@ def serials
render :json => Katello::Resources::Candlepin::Consumer.serials(@host.subscription_facet.uuid)
end

def get_parent_host(headers)
hostnames = headers["HTTP_X_FORWARDED_SERVER"]
host = hostnames.split(",")[0] if hostnames
host || Facter.value(:fqdn) || SETTINGS[:fqdn]
end

private

def disable_strong_params
Expand Down Expand Up @@ -436,6 +447,11 @@ def client_authorized?
authorized
end

def update_host_registered_through(host, headers)
parent_host = get_parent_host(headers)
host.subscription_facet.update_attribute(:registered_through, parent_host)
end

# rubocop:disable MethodLength
def authorize_proxy_routes
deny_access unless (authenticate || authenticate_client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module SubscriptionFacetHostExtensions
scoped_search :on => :autoheal, :in => :subscription_facet, :complete_value => true
scoped_search :on => :service_level, :in => :subscription_facet, :complete_value => true
scoped_search :on => :last_checkin, :in => :subscription_facet, :complete_value => true
scoped_search :on => :registered_through, :in => :subscription_facet, :complete_value => true
scoped_search :on => :registered_at, :in => :subscription_facet, :rename => :registered_at
scoped_search :on => :uuid, :in => :subscription_facet, :rename => :subscription_uuid
scoped_search :in => :activation_keys, :on => :name, :rename => :activation_key, :complete_value => true, :ext_method => :find_by_activation_key
Expand Down
2 changes: 1 addition & 1 deletion app/views/katello/api/v2/subscription_facet/base.json.rabl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
attributes :id, :uuid, :last_checkin, :service_level, :release_version, :autoheal, :registered_at
attributes :id, :uuid, :last_checkin, :service_level, :release_version, :autoheal, :registered_at, :registered_through
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddRegisteredThroughToKatelloSubscriptionFacets < ActiveRecord::Migration
def change
add_column :katello_subscription_facets, :registered_through, :string
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ <h4 translate>Basic Information</h4>
</div>
</div>

<div class="detail">
<span class="info-label" translate>Registered Through</span>
<span class="info-value">{{ host.subscription_facet_attributes.registered_through || "Unknown"}}</span>
</div>

<div ng-show="host.subscription_facet_attributes.virtual_host" class="detail">
<span class="info-label" translate>Virtual Host</span>
<div class="info-value">
Expand Down
14 changes: 14 additions & 0 deletions test/controllers/api/rhsm/candlepin_proxies_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,19 @@ def test_regenerate_indentity_certificates
refute_nil @host.subscription_facet.reload.last_checkin
end
end

describe "get parent host" do
it "can get parent host" do
capsule = "foocapsule.example.com"

host_and_capsule = {"HTTP_X_FORWARDED_SERVER" => "#{capsule}, foo.example.com"}
just_capsule = {"HTTP_X_FORWARDED_SERVER" => "#{capsule}"}
nil_host = {}

assert_equal @controller.get_parent_host(host_and_capsule), "#{capsule}"
assert_equal @controller.get_parent_host(just_capsule), "#{capsule}"
assert_includes [Facter.value(:fqdn), SETTINGS[:fqdn]], @controller.get_parent_host(nil_host)
end
end
end
end

0 comments on commit 8597c85

Please sign in to comment.