1
// Copyright 2014 Canonical Ltd.
2
// Licensed under the LGPLv3, see LICENCE file for details.
10
"github.com/juju/httprequest"
11
"github.com/juju/names"
13
"gopkg.in/macaroon-bakery.v1/bakery"
14
"gopkg.in/macaroon.v1"
17
// Username represents the name of a user.
20
// UnmarshalText unmarshals a Username checking it is valid. It
21
// implements "encoding".TextUnmarshaler.
22
func (u *Username) UnmarshalText(b []byte) error {
23
if utf8.RuneCount(b) > 256 {
24
return errgo.New("username longer than 256 characters")
26
for _, part := range bytes.Split(b, []byte("@")) {
27
if !names.IsValidUserName(string(part)) {
28
return errgo.Newf("illegal username %q", b)
31
*u = Username(string(b))
35
// AgentLogin contains the claimed identity the agent is attempting to
37
type AgentLogin struct {
38
Username Username `json:"username"`
39
PublicKey *bakery.PublicKey `json:"public_key"`
42
// AgentLoginResponse contains the response to an agent login attempt.
43
type AgentLoginResponse struct {
44
AgentLogin bool `json:"agent_login"`
47
// PublicKeyRequest documents the /publickey endpoint. As
48
// it contains no request information there is no need to ever create
50
type PublicKeyRequest struct {
51
httprequest.Route `httprequest:"GET /publickey"`
54
// PublicKeyResponse is the response to a PublicKeyRequest.
55
type PublicKeyResponse struct {
56
PublicKey *bakery.PublicKey
59
// LoginMethods holds the response from the /v1/login endpoint
60
// when called with "Accept: application/json". This enumerates
61
// the available methods for the client to log in.
62
type LoginMethods struct {
63
// Agent is the endpoint to connect to, if the client wishes to
64
// authenticate as an agent.
65
Agent string `json:"agent,omitempty"`
67
// Interactive is the endpoint to connect to, if the user can
68
// interact with the login process.
69
Interactive string `json:"interactive,omitempty"`
71
// UbuntuSSO OAuth is the endpoint to send a request, signed with
72
// UbuntuSSO OAuth credentials, to if the client wishes to use
73
// oauth to log in to Identity Manager. Ubuntu SSO uses oauth 1.0.
74
UbuntuSSOOAuth string `json:"usso_oauth,omitempty"`
76
// Form is the endpoint to GET a schema for a login form which
77
// can be presented to the user in an interactive manner. The
78
// schema will be returned as an environschema.Fields object. The
79
// completed form should be POSTed back to the same endpoint.
80
Form string `json:"form,omitempty"`
83
// QueryUsersRequest is a request to query the users in the system.
84
type QueryUsersRequest struct {
85
httprequest.Route `httprequest:"GET /v1/u" bson:",omitempty"`
86
ExternalID string `httprequest:"external_id,form" bson:"external_id,omitempty"`
89
// UserRequest is a request for the user details of the named user.
90
type UserRequest struct {
91
httprequest.Route `httprequest:"GET /v1/u/:username"`
92
Username Username `httprequest:"username,path"`
95
// User represents a user in the system.
97
Username Username `json:"username,omitempty"`
98
ExternalID string `json:"external_id"`
99
FullName string `json:"fullname"`
100
Email string `json:"email"`
101
GravatarID string `json:"gravatar_id"`
102
IDPGroups []string `json:"idpgroups"`
103
Owner Username `json:"owner,omitempty"`
104
PublicKeys []*bakery.PublicKey `json:"public_keys"`
107
// SetUserRequest is request to set the details of a user.
108
type SetUserRequest struct {
109
httprequest.Route `httprequest:"PUT /v1/u/:username"`
110
Username Username `httprequest:"username,path"`
111
User `httprequest:",body"`
114
// UserGroupsRequest is a request for the list of groups associated
115
// with the specified user.
116
type UserGroupsRequest struct {
117
httprequest.Route `httprequest:"GET /v1/u/:username/groups"`
118
Username Username `httprequest:"username,path"`
121
// UserIDPGroupsRequest defines the deprecated path for
122
// UserGroupsRequest. It should no longer be used.
123
type UserIDPGroupsRequest struct {
124
httprequest.Route `httprequest:"GET /v1/u/:username/idpgroups"`
128
// UserTokenRequest is a request for a new token to represent the user.
129
type UserTokenRequest struct {
130
httprequest.Route `httprequest:"GET /v1/u/:username/macaroon"`
131
Username Username `httprequest:"username,path"`
134
// VerifyTokenRequest is a request to verify that the provided
135
// macaroon.Slice is valid and represents a user from identity.
136
type VerifyTokenRequest struct {
137
httprequest.Route `httprequest:"POST /v1/verify"`
138
Macaroons macaroon.Slice `httprequest:",body"`
141
// UserExtraInfoRequest is a request for the arbitrary extra information
142
// stored about the user.
143
type UserExtraInfoRequest struct {
144
httprequest.Route `httprequest:"GET /v1/u/:username/extra-info"`
145
Username Username `httprequest:"username,path"`
148
// SetUserExtraInfoRequest is a request to updated the arbitrary extra
149
// information stored about the user.
150
type SetUserExtraInfoRequest struct {
151
httprequest.Route `httprequest:"PUT /v1/u/:username/extra-info"`
152
Username Username `httprequest:"username,path"`
153
ExtraInfo map[string]interface{} `httprequest:",body"`
156
// UserExtraInfoItemRequest is a request for a single element of the
157
// arbitrary extra information stored about the user.
158
type UserExtraInfoItemRequest struct {
159
httprequest.Route `httprequest:"GET /v1/u/:username/extra-info/:item"`
160
Username Username `httprequest:"username,path"`
161
Item string `httprequest:"item,path"`
164
// SetUserExtraInfoItemRequest is a request to update a single element of
165
// the arbitrary extra information stored about the user.
166
type SetUserExtraInfoItemRequest struct {
167
httprequest.Route `httprequest:"PUT /v1/u/:username/extra-info/:item"`
168
Username Username `httprequest:"username,path"`
169
Item string `httprequest:"item,path"`
170
Data interface{} `httprequest:",body"`