diff --git a/app/controllers/v3/info_controller.rb b/app/controllers/v3/info_controller.rb index f18e31b3575..87901421a1e 100644 --- a/app/controllers/v3/info_controller.rb +++ b/app/controllers/v3/info_controller.rb @@ -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 @@ -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 diff --git a/app/presenters/v3/info_presenter.rb b/app/presenters/v3/info_presenter.rb index 5c368593e79..aee8884a8f9 100644 --- a/app/presenters/v3/info_presenter.rb +++ b/app/presenters/v3/info_presenter.rb @@ -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 } diff --git a/docs/v3/source/includes/api_resources/_info.erb b/docs/v3/source/includes/api_resources/_info.erb index afa2c02263a..108e54f2216 100644 --- a/docs/v3/source/includes/api_resources/_info.erb +++ b/docs/v3/source/includes/api_resources/_info.erb @@ -11,6 +11,7 @@ "description": "Put your apps here!", "name": "Cloud Foundry", "version": 123, + "osbapi_version": "2.15", "links": { "self": { "href": "http://api.example.com/v3/info" } , "support": { "href": "http://support.example.com" } @@ -29,6 +30,7 @@ "description": "", "name": "", "version": 0, + "osbapi_version": "", "links": { "self": { "href": "http://api.example.com/v3/info" } , "support": { "href": "" } diff --git a/spec/request/info_spec.rb b/spec/request/info_spec.rb index afa0cc00cec..68b46885768 100644 --- a/spec/request/info_spec.rb +++ b/spec/request/info_spec.rb @@ -14,6 +14,7 @@ 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] } @@ -21,6 +22,14 @@ } 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) @@ -38,6 +47,7 @@ description: '', name: '', version: 0, + osbapi_version: '', links: { self: { href: "#{link_prefix}/v3/info" }, support: { href: '' } @@ -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