This repository has been archived by the owner on Jan 25, 2022. It is now read-only.
/
default_controller.rb
129 lines (112 loc) · 3.61 KB
/
default_controller.rb
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
class DefaultController < ApplicationController
def info
info = {
:name => 'vcap',
:build => 2222,
:support => AppConfig[:support_address],
:version => CloudController.version,
:description => AppConfig[:description],
:allow_debug => AppConfig[:allow_debug],
:frameworks => frameworks_info,
}
if uaa_enabled?
info[:authorization_endpoint] = (AppConfig[:login] && AppConfig[:login][:url]) ? AppConfig[:login][:url] : AppConfig[:uaa][:url]
end
# If there is a logged in user, give out additional information
if user
info[:user] = user.email
info[:limits] = user.account_capacity
info[:usage] = user.account_usage
end
render :json => info
end
def runtime_info
render :json => runtimes_info
end
def service_info
svcs = Service.active_services.select { |svc| svc.visible_to_user?(user) }
CloudController.logger.debug("Global service listing found #{svcs.length} services.")
ret = {}
svc_count = Hash.new(0)
svcs.each do |svc|
svc_count[svc.name] = svc_count[svc.name] + 1
end
svcs.each do |svc|
# Just return core services or the service with only one provider
if svc.provider.nil? || svc.provider == "core" || svc_count[svc.name] == 1
svc_type = svc.synthesize_service_type
ret[svc_type] ||= {}
ret[svc_type][svc.name] ||= {}
versions = svc.supported_versions
versions.each do |version|
version_alias = svc.version_to_alias(version)
next if (versions.size > 1 && version_alias != "current")
svc_desc = svc.as_legacy(user)
svc_desc[:version] = version
svc_desc[:alias] = version_alias if version_alias
ret[svc_type][svc.name][version] = svc_desc
end
end
end
render :json => ret
end
def index
if AppConfig[:index_page]
redirect_to AppConfig[:index_page]
else
render :text => "Welcome to VMware's Cloud Application Platform\n"
end
end
def not_implemented
$stderr.puts "\nNOT IMPLEMENTED: #{request.fullpath} #{request.body.read}"
render :json => {"error" => "Not yet implemented"}
end
# be fairly quiet on bad routes
def route_not_found
render :nothing => true, :status => :not_found
end
private
def frameworks_info
@frameworks_info ||= generate_frameworks_info
end
def runtimes_info
@runtime_info ||= generate_runtimes_info
end
def generate_frameworks_info
frameworks_info = {}
Framework.all.each do |framework|
runtimes = []
framework.runtimes.each do |runtime|
runtime.each_pair do |runtime_name, runtime_info|
runtime_info = Runtime.find(runtime_name)
if runtime_info
runtimes << {
:name => runtime_name,
:version => runtime_info.version,
:description => runtime_info.description}
else
CloudController.logger.warn("Manifest for #{framework.name} lists a runtime not present in " +
"runtimes.yml: #{runtime_name}. Runtime will be skipped.")
end
end
end
f = {
:name => framework.name,
:runtimes => runtimes,
:detection => framework.detection
}
frameworks_info[framework.name] = f
end
frameworks_info
end
def generate_runtimes_info
runtime_info = {}
Runtime.all.each do |runtime|
runtime_info[runtime.name] = {
:version => runtime.version,
:description => runtime.description,
:debug_modes=> runtime.debug_modes }
end
runtime_info
end
end