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 10, 2018
1 parent 4dbf6b0 commit 9d01dbc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
38 changes: 29 additions & 9 deletions app/controllers/api/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ 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,
:branding_info => branding_info
}
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 +75,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 branding_image_path(custom, default)
custom || ActionController::Base.helpers.image_path(default)
rescue Sprockets::FileNotFound # UI isn't loaded, we don't want images
nil
end

def branding_info
{
:brand => branding_image_path(Settings.server.custom_brand, 'layout/brand.svg'),
:logo => branding_image_path(Settings.server.custom_logo, 'layout/login-screen-logo.png'),
:login_logo => Settings.server.custom_login_logo ? Settings.server.custom_login_logo : nil
}.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
19 changes: 19 additions & 0 deletions spec/requests/entrypoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,25 @@
)
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
api_basic_authorize

Expand Down

0 comments on commit 9d01dbc

Please sign in to comment.