forked from cloudfoundry/stratos
-
Notifications
You must be signed in to change notification settings - Fork 12
/
info.go
93 lines (80 loc) · 2.4 KB
/
info.go
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
package main
import (
"errors"
"net/http"
"github.com/SUSE/stratos-ui/repository/interfaces"
"github.com/labstack/echo"
)
// Endpoint - This represents the CNSI endpoint
type Endpoint struct {
GUID string `json:"guid"`
Name string `json:"name"`
Version string `json:"version"`
User *interfaces.ConnectedUser `json:"user"`
CNSIType string `json:"type"`
}
func (p *portalProxy) info(c echo.Context) error {
s, err := p.getInfo(c)
if err != nil {
return echo.NewHTTPError(http.StatusForbidden, err.Error())
}
return c.JSON(http.StatusOK, s)
}
func (p *portalProxy) getInfo(c echo.Context) (*interfaces.Info, error) {
// get the version
versions, err := p.getVersionsData()
if err != nil {
return nil, errors.New("Could not find database version")
}
// get the user
userGUID, err := p.GetSessionStringValue(c, "user_id")
if err != nil {
return nil, errors.New("Could not find session user_id")
}
uaaUser, err := p.getUAAUser(userGUID)
if err != nil {
return nil, errors.New("Could not load session user data")
}
// create initial info struct
s := &interfaces.Info{
Versions: versions,
User: uaaUser,
Endpoints: make(map[string]map[string]*interfaces.EndpointDetail),
CloudFoundry: p.Config.CloudFoundryInfo,
PluginConfig: p.Config.PluginConfig,
}
// initialize the Endpoints maps
for _, plugin := range p.Plugins {
endpointPlugin, err := plugin.GetEndpointPlugin()
if err != nil {
// Plugin doesn't implement an Endpoint Plugin interface, skip
continue
}
s.Endpoints[endpointPlugin.GetType()] = make(map[string]*interfaces.EndpointDetail)
}
// get the CNSI Endpoints
cnsiList, _ := p.buildCNSIList(c)
for _, cnsi := range cnsiList {
// Extend the CNSI record
endpoint := &interfaces.EndpointDetail{
CNSIRecord: cnsi,
Metadata: make(map[string]string),
}
// try to get the user info for this cnsi for the user
cnsiUser, token, ok := p.GetCNSIUserAndToken(cnsi.GUID, userGUID)
if ok {
endpoint.User = cnsiUser
endpoint.TokenMetadata = token.Metadata
}
cnsiType := cnsi.CNSIType
s.Endpoints[cnsiType][cnsi.GUID] = endpoint
}
// Allow plugin to modify the info data
for _, plugin := range p.Plugins {
endpointPlugin, err := plugin.GetEndpointPlugin()
if err == nil {
endpointPlugin.UpdateMetadata(s, userGUID, c)
}
}
return s, nil
}