~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/juju/idmclient/params/params.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2014 Canonical Ltd.
 
2
// Licensed under the LGPLv3, see LICENCE file for details.
 
3
 
 
4
package params
 
5
 
 
6
import (
 
7
        "bytes"
 
8
        "unicode/utf8"
 
9
 
 
10
        "github.com/juju/httprequest"
 
11
        "github.com/juju/names"
 
12
        "gopkg.in/errgo.v1"
 
13
        "gopkg.in/macaroon-bakery.v1/bakery"
 
14
        "gopkg.in/macaroon.v1"
 
15
)
 
16
 
 
17
// Username represents the name of a user.
 
18
type Username string
 
19
 
 
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")
 
25
        }
 
26
        for _, part := range bytes.Split(b, []byte("@")) {
 
27
                if !names.IsValidUserName(string(part)) {
 
28
                        return errgo.Newf("illegal username %q", b)
 
29
                }
 
30
        }
 
31
        *u = Username(string(b))
 
32
        return nil
 
33
}
 
34
 
 
35
// AgentLogin contains the claimed identity the agent is attempting to
 
36
// use to log in.
 
37
type AgentLogin struct {
 
38
        Username  Username          `json:"username"`
 
39
        PublicKey *bakery.PublicKey `json:"public_key"`
 
40
}
 
41
 
 
42
// AgentLoginResponse contains the response to an agent login attempt.
 
43
type AgentLoginResponse struct {
 
44
        AgentLogin bool `json:"agent_login"`
 
45
}
 
46
 
 
47
// PublicKeyRequest documents the /publickey endpoint. As
 
48
// it contains no request information there is no need to ever create
 
49
// one.
 
50
type PublicKeyRequest struct {
 
51
        httprequest.Route `httprequest:"GET /publickey"`
 
52
}
 
53
 
 
54
// PublicKeyResponse is the response to a PublicKeyRequest.
 
55
type PublicKeyResponse struct {
 
56
        PublicKey *bakery.PublicKey
 
57
}
 
58
 
 
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"`
 
66
 
 
67
        // Interactive is the endpoint to connect to, if the user can
 
68
        // interact with the login process.
 
69
        Interactive string `json:"interactive,omitempty"`
 
70
 
 
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"`
 
75
 
 
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"`
 
81
}
 
82
 
 
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"`
 
87
}
 
88
 
 
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"`
 
93
}
 
94
 
 
95
// User represents a user in the system.
 
96
type User struct {
 
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"`
 
105
}
 
106
 
 
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"`
 
112
}
 
113
 
 
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"`
 
119
}
 
120
 
 
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"`
 
125
        UserGroupsRequest
 
126
}
 
127
 
 
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"`
 
132
}
 
133
 
 
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"`
 
139
}
 
140
 
 
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"`
 
146
}
 
147
 
 
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"`
 
154
}
 
155
 
 
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"`
 
162
}
 
163
 
 
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"`
 
171
}