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

Add OSBAPI version to /v3/info #4163

Merged
merged 3 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion app/controllers/v3/info_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def v3_info
info.version = config.get(:info, :version) || 0
info.support_address = config.get(:info, :support_address) || ''

osbapi_version_file = Rails.root.join('config/osbapi_version').to_s
if File.exist?(osbapi_version_file)
info.osbapi_version = File.read(osbapi_version_file).strip
else
info.osbapi_version = ''
Rails.logger.warn("OSBAPI version file not found at #{osbapi_version_file}")
end

render status: :ok, json: VCAP::CloudController::Presenters::V3::InfoPresenter.new(info)
end

Expand All @@ -29,5 +37,5 @@ def show_usage_summary
end

class Info
attr_accessor :build, :min_cli_version, :min_recommended_cli_version, :custom, :description, :name, :version, :support_address
attr_accessor :build, :min_cli_version, :min_recommended_cli_version, :custom, :description, :name, :version, :support_address, :osbapi_version
end
1 change: 1 addition & 0 deletions app/presenters/v3/info_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def to_hash
description: info.description,
name: info.name,
version: info.version,
osbapi_version: info.osbapi_version,
links: {
self: { href: build_self },
support: { href: info.support_address }
Expand Down
2 changes: 2 additions & 0 deletions docs/v3/source/includes/api_resources/_info.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"description": "Put your apps here!",
"name": "Cloud Foundry",
"version": 123,
"osbapi_version": 456,
WeiQuan0605 marked this conversation as resolved.
Show resolved Hide resolved
"links": {
"self": { "href": "http://api.example.com/v3/info" } ,
"support": { "href": "http://support.example.com" }
Expand All @@ -29,6 +30,7 @@
"description": "",
"name": "",
"version": 0,
"osbapi_version": "",
"links": {
"self": { "href": "http://api.example.com/v3/info" } ,
"support": { "href": "" }
Expand Down
11 changes: 11 additions & 0 deletions spec/request/info_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@
description: TestConfig.config[:info][:description],
name: TestConfig.config[:info][:name],
version: TestConfig.config[:info][:version],
osbapi_version: TestConfig.config[:info][:osbapi_version],
links: {
self: { href: "#{link_prefix}/v3/info" },
support: { href: TestConfig.config[:info][:support_address] }
}
}
end

before do
allow(File).to receive(:exist?).and_call_original
allow(File).to receive(:exist?).with(Rails.root.join('config/osbapi_version').to_s).and_return(true)
allow(File).to receive(:read).with(Rails.root.join('config/osbapi_version').to_s).and_return('1.0.0')

TestConfig.override(info: TestConfig.config[:info].merge(osbapi_version: '1.0.0'))
end

it 'includes data from the config' do
get '/v3/info'
expect(Oj.load(last_response.body)).to match_json_response(return_info_json)
Expand All @@ -38,6 +47,7 @@
description: '',
name: '',
version: 0,
osbapi_version: '',
links: {
self: { href: "#{link_prefix}/v3/info" },
support: { href: '' }
Expand All @@ -47,6 +57,7 @@

before do
TestConfig.override(info: nil)
allow(File).to receive(:exist?).with(Rails.root.join('config/osbapi_version').to_s).and_return(false)
end

it 'includes has proper empty values' do
Expand Down
Loading