forked from gravitational/teleport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_apps.go
119 lines (104 loc) · 3.25 KB
/
handler_apps.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
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
// Teleport
// Copyright (C) 2024 Gravitational, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package handler
import (
"context"
"sort"
"github.com/gravitational/trace"
"github.com/gravitational/teleport/api/types"
api "github.com/gravitational/teleport/gen/proto/go/teleport/lib/teleterm/v1"
"github.com/gravitational/teleport/lib/teleterm/clusters"
)
// GetApps gets apps with filters and returns paginated results
func (s *Handler) GetApps(ctx context.Context, req *api.GetAppsRequest) (*api.GetAppsResponse, error) {
cluster, _, err := s.DaemonService.ResolveCluster(req.ClusterUri)
if err != nil {
return nil, trace.Wrap(err)
}
resp, err := cluster.GetApps(ctx, req)
if err != nil {
return nil, trace.Wrap(err)
}
response := &api.GetAppsResponse{
StartKey: resp.StartKey,
TotalCount: int32(resp.TotalCount),
}
for _, app := range resp.Apps {
var apiApp *api.App
if app.App != nil {
apiApp = newAPIApp(*app.App)
} else if app.SAMLIdPServiceProvider != nil {
apiApp = newSAMLIdPServiceProviderAPIApp(*app.SAMLIdPServiceProvider)
} else {
return nil, trace.Errorf("expected an app server or a SAML IdP provider")
}
response.Agents = append(response.Agents, apiApp)
}
return response, nil
}
func newAPIApp(clusterApp clusters.App) *api.App {
app := clusterApp.App
awsRoles := []*api.AWSRole{}
for _, role := range clusterApp.AWSRoles {
awsRoles = append(awsRoles, &api.AWSRole{
Name: role.Name,
Display: role.Display,
Arn: role.ARN,
})
}
apiLabels := APILabels{}
for name, value := range app.GetAllLabels() {
apiLabels = append(apiLabels, &api.Label{
Name: name,
Value: value,
})
}
sort.Sort(apiLabels)
return &api.App{
Uri: clusterApp.URI.String(),
EndpointUri: app.GetURI(),
Name: app.GetName(),
Desc: app.GetDescription(),
AwsConsole: app.IsAWSConsole(),
PublicAddr: app.GetPublicAddr(),
Fqdn: clusterApp.FQDN,
AwsRoles: awsRoles,
FriendlyName: types.FriendlyName(app),
SamlApp: false,
Labels: apiLabels,
}
}
func newSAMLIdPServiceProviderAPIApp(clusterApp clusters.SAMLIdPServiceProvider) *api.App {
provider := clusterApp.Provider
apiLabels := APILabels{}
for name, value := range provider.GetAllLabels() {
apiLabels = append(apiLabels, &api.Label{
Name: name,
Value: value,
})
}
sort.Sort(apiLabels)
// Keep in sync with lib/web/ui/app.go.
return &api.App{
Uri: clusterApp.URI.String(),
Name: provider.GetName(),
Desc: "SAML Application",
PublicAddr: "",
FriendlyName: types.FriendlyName(provider),
SamlApp: true,
Labels: apiLabels,
}
}