Skip to content
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
12 changes: 11 additions & 1 deletion app/controllers/runtime/root_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ def read
oauth_client: config.get(:info, :app_ssh_oauth_client)
}
}

}
}

response[:links].merge!(cloud_controller_v2(api_url_builder)) if config.get(:temporary_enable_v2)

response[:links].merge!(custom_links(config.get(:custom_root_links))) if config.get(:custom_root_links)

[200, Oj.dump(response, mode: :compat)]
end

Expand Down Expand Up @@ -98,5 +99,14 @@ def cloud_controller_v2(api_url_builder)
}
}
end

def custom_links(links)
result = {}
links.each do |value|
value = ActiveSupport::HashWithIndifferentAccess.new(value)
result[value['name']] = { href: value['href'] }
end
result
end
end
end
1 change: 1 addition & 0 deletions lib/cloud_controller/config_schemas/base/api_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class ApiSchema < VCAP::Config
optional(:app_ssh_host_key_fingerprint) => String,
optional(:custom) => Hash
},
optional(:custom_root_links) => Array,

system_domain: String,
optional(:system_domain_organization) => enum(String, NilClass),
Expand Down
21 changes: 21 additions & 0 deletions spec/unit/controllers/runtime/root_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,27 @@ module VCAP::CloudController
}
)
end

describe 'custom links' do
context 'custom links are configured' do
it 'returns a link' do
TestConfig.override(custom_root_links: [{ name: 'custom_link_1', href: 'custom_link_1.com' }, { name: 'custom_link_2', href: 'custom_link_2.com' }])
get '/'
hash = Oj.load(last_response.body)
expect(hash['links']['custom_link_1']['href']).to eq('custom_link_1.com')
expect(hash['links']['custom_link_2']['href']).to eq('custom_link_2.com')
end
end

context 'custom links overrides an existing link' do
it 'returns the custom link' do
TestConfig.override(custom_root_links: [{ name: 'uaa', href: 'my_new_uaa.com' }])
get '/'
hash = Oj.load(last_response.body)
expect(hash['links']['uaa']['href']).to eq('my_new_uaa.com')
end
end
end
end
end
end