Skip to content

Commit

Permalink
Add the /api/product_info route with product and branding info
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Oct 12, 2018
1 parent 4dbf6b0 commit 4ff21f4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
37 changes: 28 additions & 9 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,24 @@ def options

def index
res = {
:name => ApiConfig.base.name,
:description => ApiConfig.base.description,
:version => ManageIQ::Api::VERSION,
:versions => entrypoint_versions,
:settings => user_settings,
:identity => auth_identity,
:server_info => server_info,
:product_info => product_info
:name => ApiConfig.base.name,
:description => ApiConfig.base.description,
:version => ManageIQ::Api::VERSION,
:versions => entrypoint_versions,
:settings => user_settings,
:identity => auth_identity,
:server_info => server_info,
:product_info => product_info_data
}
res[:authorization] = auth_authorization if attribute_selection.include?("authorization")
res[:collections] = entrypoint_collections
render_resource :entrypoint, res
end

def product_info
render_resource :product_info, product_info_data
end

private

def entrypoint_versions
Expand Down Expand Up @@ -70,16 +74,31 @@ def server_info
}
end

def product_info
def product_info_data
{
:name => Vmdb::Appliance.PRODUCT_NAME,
:name_full => I18n.t("product.name_full"),
:copyright => I18n.t("product.copyright"),
:support_website => I18n.t("product.support_website"),
:support_website_text => I18n.t("product.support_website_text"),
:branding_info => branding_info
}
end

def image_path(image)
ActionController::Base.helpers.image_path(image)
rescue Sprockets::FileNotFound # UI isn't loaded, we don't want images
nil
end

def branding_info
{
:brand => Settings.server.custom_brand || image_path('layout/brand.svg'),
:logo => Settings.server.custom_logo || image_path('layout/login-screen-logo.png'),
:login_logo => Settings.server.custom_login_logo.presence
}.compact
end

def plugin_info
Vmdb::Plugins.versions.each_with_object({}) do |(engine, version), hash|
hash[engine.to_s] = {
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class BaseController < ActionController::API
include ActionController::HttpAuthentication::Basic::ControllerMethods

before_action :log_request_initiated
before_action :require_api_user_or_token, :except => [:options]
before_action :set_gettext_locale, :set_access_control_headers, :parse_api_request, :log_api_request,
:validate_api_request
before_action :validate_api_action, :except => [:options]
before_action :require_api_user_or_token, :except => [:options, :product_info]
before_action :set_gettext_locale, :set_access_control_headers, :parse_api_request, :log_api_request
before_action :validate_api_request, :except => [:product_info]
before_action :validate_api_action, :except => [:options, :product_info]
before_action :validate_response_format, :except => [:destroy]
before_action :ensure_pagination, :only => :index
after_action :log_api_response
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
match "/", :to => "api#options", :via => :options

get "/ping" => "ping#index"
get "/product_info" => "api#product_info"

Api::ApiConfig.collections.each do |collection_name, collection|
# OPTIONS action for each collection
Expand Down
24 changes: 23 additions & 1 deletion spec/requests/entrypoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,31 @@
"name_full" => I18n.t("product.name_full"),
"copyright" => I18n.t("product.copyright"),
"support_website" => I18n.t("product.support_website"),
"support_website_text" => I18n.t("product.support_website_text"),
"support_website_text" => I18n.t("product.support_website_text")
)
)

# This test will fail if you have the UI checked out and built with yarn
expect(response.parsed_body['product_info']['branding_info']).to eq({})
end

context 'UI is available' do
it 'product_info contains branding_info' do
api_basic_authorize

expect(ActionController::Base.helpers).to receive(:image_path).at_least(2).times.and_return("foo")

get api_entrypoint_url

expect(response.parsed_body).to include(
"product_info" => a_hash_including(
"branding_info" => a_hash_including(
"brand" => "foo",
"logo" => "foo"
)
)
)
end
end

it "will squeeze consecutive slashes in the path portion of the URI" do
Expand Down

0 comments on commit 4ff21f4

Please sign in to comment.