Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFE] Add the /api/product_info route with product and branding info #438

Merged
merged 1 commit into from
Oct 12, 2018
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this also implying that we already have this endpoint?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should not make PRs when I'm tired 😢 I'll fix this tomorrow 😕 😴

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because the one below is private.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, my bad ... fixed now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fix it though? It seems this break API compatibility because the old product_info doesn't match the new one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right, is it okay if I merge the branding_info into product_info?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with putting the branding info under product_info, but did we somehow have /product_info before?
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's a new thing.

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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the test above be modified or a new test added where this is not stubbed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update the test above!


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