forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.go
64 lines (51 loc) · 1.66 KB
/
helpers.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
package api
import (
"net/http"
templateapi "github.com/openshift/origin/pkg/template/apis/template"
"k8s.io/apiserver/pkg/authentication/user"
)
func NewResponse(code int, body interface{}, err error) *Response {
return &Response{Code: code, Body: body, Err: err}
}
func BadRequest(err error) *Response {
return NewResponse(http.StatusBadRequest, nil, err)
}
func Forbidden(err error) *Response {
return NewResponse(http.StatusForbidden, nil, err)
}
func InternalServerError(err error) *Response {
return NewResponse(http.StatusInternalServerError, nil, err)
}
// ConvertUserToTemplateInstanceRequester copies analogous fields from user.Info to TemplateInstanceRequester
func ConvertUserToTemplateInstanceRequester(u user.Info) templateapi.TemplateInstanceRequester {
templatereq := templateapi.TemplateInstanceRequester{}
if u != nil {
extra := map[string]templateapi.ExtraValue{}
if u.GetExtra() != nil {
for k, v := range u.GetExtra() {
extra[k] = templateapi.ExtraValue(v)
}
}
templatereq.Username = u.GetName()
templatereq.UID = u.GetUID()
templatereq.Groups = u.GetGroups()
templatereq.Extra = extra
}
return templatereq
}
// ConvertTemplateInstanceRequesterToUser copies analogous fields from TemplateInstanceRequester to user.Info
func ConvertTemplateInstanceRequesterToUser(templateReq *templateapi.TemplateInstanceRequester) user.Info {
u := user.DefaultInfo{}
u.Extra = map[string][]string{}
if templateReq != nil {
u.Name = templateReq.Username
u.UID = templateReq.UID
u.Groups = templateReq.Groups
if templateReq.Extra != nil {
for k, v := range templateReq.Extra {
u.Extra[k] = []string(v)
}
}
}
return &u
}