This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
/
user_service.go
63 lines (57 loc) · 1.95 KB
/
user_service.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
package controller
import (
"github.com/fabric8-services/fabric8-auth/app"
"github.com/fabric8-services/fabric8-auth/application"
"github.com/fabric8-services/fabric8-auth/authentication/account/tenant"
"github.com/fabric8-services/fabric8-auth/jsonapi"
"github.com/goadesign/goa"
uuid "github.com/satori/go.uuid"
)
// UserServiceController implements the UserService resource.
type UserServiceController struct {
*goa.Controller
app application.Application
}
// NewUserServiceController creates a UserService controller.
func NewUserServiceController(service *goa.Service, app application.Application) *UserServiceController {
return &UserServiceController{Controller: service.NewController("UserServiceController"), app: app}
}
// Show runs the show action.
func (c *UserServiceController) Show(ctx *app.ShowUserServiceContext) error {
t, err := c.app.TenantService().View(ctx)
if err != nil {
return jsonapi.JSONErrorResponse(ctx, err)
}
return ctx.OK(convert(t))
}
func convert(t *tenant.TenantSingle) *app.UserServiceSingle {
var ns []*app.NamespaceAttributes
for _, tn := range t.Data.Attributes.Namespaces {
ns = append(ns, &app.NamespaceAttributes{
CreatedAt: tn.CreatedAt,
UpdatedAt: tn.UpdatedAt,
Name: tn.Name,
State: tn.State,
Version: tn.Version,
Type: tn.Type,
ClusterURL: tn.ClusterURL,
ClusterConsoleURL: tn.ClusterConsoleURL,
ClusterMetricsURL: tn.ClusterMetricsURL,
ClusterLoggingURL: tn.ClusterLoggingURL,
ClusterAppDomain: tn.ClusterAppDomain,
ClusterCapacityExhausted: tn.ClusterCapacityExhausted,
})
}
id := uuid.UUID(*t.Data.ID)
u := app.UserServiceSingle{
Data: &app.UserService{
Attributes: &app.UserServiceAttributes{
CreatedAt: t.Data.Attributes.CreatedAt,
Namespaces: ns,
},
ID: &id,
Type: "userservices",
},
}
return &u
}