From aaf5206fbc6ca73ba2fc30feb2f2518f3976d594 Mon Sep 17 00:00:00 2001 From: Wei Quan Date: Tue, 7 Jan 2025 15:23:58 +0100 Subject: [PATCH 1/3] Add OSBAPI version to /v3/info --- app/controllers/v3/info_controller.rb | 10 +++++++++- app/presenters/v3/info_presenter.rb | 1 + spec/request/info_spec.rb | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) 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/spec/request/info_spec.rb b/spec/request/info_spec.rb index afa0cc00cec..04a2b3bd6f1 100644 --- a/spec/request/info_spec.rb +++ b/spec/request/info_spec.rb @@ -38,6 +38,7 @@ description: '', name: '', version: 0, + osbapi_version: 0, links: { self: { href: "#{link_prefix}/v3/info" }, support: { href: '' } From d579482a22aad24aa25e44eca485cd8925c56b61 Mon Sep 17 00:00:00 2001 From: Wei Quan Date: Wed, 8 Jan 2025 15:32:16 +0100 Subject: [PATCH 2/3] Adapt unittest --- docs/v3/source/includes/api_resources/_info.erb | 2 ++ spec/request/info_spec.rb | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/v3/source/includes/api_resources/_info.erb b/docs/v3/source/includes/api_resources/_info.erb index afa2c02263a..d6968ce4a34 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": 456, "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 04a2b3bd6f1..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,7 +47,7 @@ description: '', name: '', version: 0, - osbapi_version: 0, + osbapi_version: '', links: { self: { href: "#{link_prefix}/v3/info" }, support: { href: '' } @@ -48,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 From 29344dd303ddf611e3d7a01d106aef9b465a7cff Mon Sep 17 00:00:00 2001 From: Wei Quan <64415962+WeiQuan0605@users.noreply.github.com> Date: Thu, 9 Jan 2025 08:55:55 +0100 Subject: [PATCH 3/3] Update docs/v3/source/includes/api_resources/_info.erb Co-authored-by: Sam Gunaratne <385176+Samze@users.noreply.github.com> --- docs/v3/source/includes/api_resources/_info.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/v3/source/includes/api_resources/_info.erb b/docs/v3/source/includes/api_resources/_info.erb index d6968ce4a34..108e54f2216 100644 --- a/docs/v3/source/includes/api_resources/_info.erb +++ b/docs/v3/source/includes/api_resources/_info.erb @@ -11,7 +11,7 @@ "description": "Put your apps here!", "name": "Cloud Foundry", "version": 123, - "osbapi_version": 456, + "osbapi_version": "2.15", "links": { "self": { "href": "http://api.example.com/v3/info" } , "support": { "href": "http://support.example.com" }