Skip to content

Commit 5d0e8d6

Browse files
committed
Hide unavailable loggregator endpoints from / response
Use a nil-when-blank helper for the logging, log_cache, and log_stream links in the root controller, matching the existing pattern used by credhub_link and routing_link. The link entry becomes nil when the underlying URL is not configured, instead of advertising an empty href.
1 parent ce02452 commit 5d0e8d6

2 files changed

Lines changed: 99 additions & 25 deletions

File tree

app/controllers/runtime/root_controller.rb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,11 @@ def read
4141
credhub: credhub_link,
4242
routing: routing_link,
4343

44-
logging: {
45-
href: config.get(:doppler, :url)
46-
},
44+
logging: logging_link,
4745

48-
log_cache: {
49-
href: config.get(:log_cache, :url)
50-
},
46+
log_cache: log_cache_link,
5147

52-
log_stream: {
53-
href: config.get(:log_stream, :url)
54-
},
48+
log_stream: log_stream_link,
5549

5650
app_ssh: {
5751
href: config.get(:info, :app_ssh_endpoint),
@@ -88,6 +82,24 @@ def routing_link
8882
{ href: config.get(:routing_api, :url) }
8983
end
9084

85+
def logging_link
86+
return if config.get(:doppler, :url).blank?
87+
88+
{ href: config.get(:doppler, :url) }
89+
end
90+
91+
def log_cache_link
92+
return if config.get(:log_cache, :url).blank?
93+
94+
{ href: config.get(:log_cache, :url) }
95+
end
96+
97+
def log_stream_link
98+
return if config.get(:log_stream, :url).blank?
99+
100+
{ href: config.get(:log_stream, :url) }
101+
end
102+
91103
def cloud_controller_v2(api_url_builder)
92104
{
93105
cloud_controller_v2:

spec/unit/controllers/runtime/root_controller_spec.rb

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,91 @@ module VCAP::CloudController
127127
expect(hash['links']['network_policy_v1']['href']).to eq(expected_uri)
128128
end
129129

130-
it 'returns a link to the logging API' do
131-
expected_uri = 'wss://doppler.my-super-cool-cf.com:1234'
132-
TestConfig.override(doppler: { url: expected_uri })
130+
describe 'logging link' do
131+
context 'doppler url is configured' do
132+
it 'returns a link to the logging API' do
133+
expected_uri = 'wss://doppler.my-super-cool-cf.com:1234'
134+
TestConfig.override(doppler: { url: expected_uri })
133135

134-
get '/'
135-
hash = Oj.load(last_response.body)
136-
expect(hash['links']['logging']['href']).to eq(expected_uri)
136+
get '/'
137+
hash = Oj.load(last_response.body)
138+
expect(hash['links']['logging']['href']).to eq(expected_uri)
139+
end
140+
end
141+
142+
context 'doppler url is blank' do
143+
before do
144+
TestConfig.override(doppler: { url: '' })
145+
end
146+
147+
it 'does not return a link' do
148+
get '/'
149+
hash = Oj.load(last_response.body)
150+
expect(hash['links']['logging']).to be_nil
151+
end
152+
end
137153
end
138154

139-
it 'returns a link to the log cache API' do
140-
expected_uri = 'https://log-cache.example.com'
155+
describe 'log_cache link' do
156+
context 'log_cache url is configured' do
157+
it 'returns a link to the log cache API' do
158+
expected_uri = 'https://log-cache.example.com'
141159

142-
get '/'
143-
hash = Oj.load(last_response.body)
144-
expect(hash['links']['log_cache']['href']).to eq(expected_uri)
160+
get '/'
161+
hash = Oj.load(last_response.body)
162+
expect(hash['links']['log_cache']['href']).to eq(expected_uri)
163+
end
164+
end
165+
166+
context 'log_cache url is blank' do
167+
before do
168+
TestConfig.override(log_cache: { url: '' })
169+
end
170+
171+
it 'does not return a link' do
172+
get '/'
173+
hash = Oj.load(last_response.body)
174+
expect(hash['links']['log_cache']).to be_nil
175+
end
176+
end
145177
end
146178

147-
it 'returns a link to the v2 logging API' do
148-
expected_uri = 'https://log-stream.example.com'
179+
describe 'log_stream link' do
180+
context 'log_stream url is configured' do
181+
it 'returns a link to the v2 logging API' do
182+
expected_uri = 'https://log-stream.example.com'
149183

150-
get '/'
151-
hash = Oj.load(last_response.body)
152-
expect(hash['links']['log_stream']['href']).to eq(expected_uri)
184+
get '/'
185+
hash = Oj.load(last_response.body)
186+
expect(hash['links']['log_stream']['href']).to eq(expected_uri)
187+
end
188+
end
189+
190+
context 'log_stream url is blank' do
191+
before do
192+
TestConfig.override(log_stream: { url: '' })
193+
end
194+
195+
it 'does not return a link' do
196+
get '/'
197+
hash = Oj.load(last_response.body)
198+
expect(hash['links']['log_stream']).to be_nil
199+
end
200+
end
201+
end
202+
203+
context 'all loggregator urls are blank' do
204+
before do
205+
TestConfig.override(doppler: { url: '' }, log_cache: { url: '' }, log_stream: { url: '' })
206+
end
207+
208+
it 'returns nil for all three loggregator links' do
209+
get '/'
210+
hash = Oj.load(last_response.body)
211+
expect(hash['links']['logging']).to be_nil
212+
expect(hash['links']['log_cache']).to be_nil
213+
expect(hash['links']['log_stream']).to be_nil
214+
end
153215
end
154216

155217
it 'returns a link for app_ssh with metadata' do

0 commit comments

Comments
 (0)