Skip to content

Commit 29ecd74

Browse files
authored
Add custom root links (#4307)
1 parent c66d671 commit 29ecd74

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

app/controllers/runtime/root_controller.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ def read
6060
oauth_client: config.get(:info, :app_ssh_oauth_client)
6161
}
6262
}
63-
6463
}
6564
}
6665

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

68+
response[:links].merge!(custom_links(config.get(:custom_root_links))) if config.get(:custom_root_links)
69+
6970
[200, Oj.dump(response, mode: :compat)]
7071
end
7172

@@ -98,5 +99,14 @@ def cloud_controller_v2(api_url_builder)
9899
}
99100
}
100101
end
102+
103+
def custom_links(links)
104+
result = {}
105+
links.each do |value|
106+
value = ActiveSupport::HashWithIndifferentAccess.new(value)
107+
result[value['name']] = { href: value['href'] }
108+
end
109+
result
110+
end
101111
end
102112
end

lib/cloud_controller/config_schemas/base/api_schema.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class ApiSchema < VCAP::Config
3030
optional(:app_ssh_host_key_fingerprint) => String,
3131
optional(:custom) => Hash
3232
},
33+
optional(:custom_root_links) => Array,
3334

3435
system_domain: String,
3536
optional(:system_domain_organization) => enum(String, NilClass),

spec/unit/controllers/runtime/root_controller_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,27 @@ module VCAP::CloudController
174174
}
175175
)
176176
end
177+
178+
describe 'custom links' do
179+
context 'custom links are configured' do
180+
it 'returns a link' do
181+
TestConfig.override(custom_root_links: [{ name: 'custom_link_1', href: 'custom_link_1.com' }, { name: 'custom_link_2', href: 'custom_link_2.com' }])
182+
get '/'
183+
hash = Oj.load(last_response.body)
184+
expect(hash['links']['custom_link_1']['href']).to eq('custom_link_1.com')
185+
expect(hash['links']['custom_link_2']['href']).to eq('custom_link_2.com')
186+
end
187+
end
188+
189+
context 'custom links overrides an existing link' do
190+
it 'returns the custom link' do
191+
TestConfig.override(custom_root_links: [{ name: 'uaa', href: 'my_new_uaa.com' }])
192+
get '/'
193+
hash = Oj.load(last_response.body)
194+
expect(hash['links']['uaa']['href']).to eq('my_new_uaa.com')
195+
end
196+
end
197+
end
177198
end
178199
end
179200
end

0 commit comments

Comments
 (0)