-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathroot_controller.rb
More file actions
112 lines (87 loc) · 2.68 KB
/
root_controller.rb
File metadata and controls
112 lines (87 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require 'presenters/api_url_builder'
module VCAP::CloudController
class RootController < RestController::BaseController
allow_unauthenticated_access
get '/', :read
def read
api_url_builder = VCAP::CloudController::Presenters::ApiUrlBuilder
response = {
links: {
self: {
href: api_url_builder.build_url
},
cloud_controller_v3: {
href: api_url_builder.build_url(path: '/v3'),
meta: {
version: VCAP::CloudController::Constants::API_VERSION_V3
}
},
network_policy_v0: {
href: api_url_builder.build_url(path: '/networking/v0/external')
},
network_policy_v1: {
href: api_url_builder.build_url(path: '/networking/v1/external')
},
login: {
href: config.get(:login, :url)
},
uaa: {
href: config.get(:uaa, :url)
},
credhub: credhub_link,
routing: routing_link,
logging: {
href: config.get(:doppler, :url)
},
log_cache: {
href: config.get(:log_cache, :url)
},
log_stream: {
href: config.get(:log_stream, :url)
},
app_ssh: {
href: config.get(:info, :app_ssh_endpoint),
meta: {
host_key_fingerprint: config.get(:info, :app_ssh_host_key_fingerprint),
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
private
def config
VCAP::CloudController::Config.config
end
def credhub_link
return if config.get(:credhub_api, :external_url).blank?
{ href: config.get(:credhub_api, :external_url) }
end
def routing_link
return if config.get(:routing_api).blank?
{ href: config.get(:routing_api, :url) }
end
def cloud_controller_v2(api_url_builder)
{
cloud_controller_v2:
{
href: api_url_builder.build_url(path: '/v2'),
meta: {
version: VCAP::CloudController::Constants::API_VERSION
}
}
}
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