mirror of
https://github.com/fleetdm/fleet
synced 2026-05-23 00:49:03 +00:00
Move API responses under top-level keys (#292)
This commit is contained in:
parent
58c3733524
commit
5d0cac882a
17 changed files with 143 additions and 369 deletions
|
|
@ -61,7 +61,8 @@ class Kolide extends Base {
|
|||
const { USERS } = endpoints;
|
||||
const updateUserEndpoint = `${this.baseURL}${USERS}/${user.id}`;
|
||||
|
||||
return this.authenticatedPatch(updateUserEndpoint, JSON.stringify(formData));
|
||||
return this.authenticatedPatch(updateUserEndpoint, JSON.stringify(formData))
|
||||
.then(response => { return response.user; });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,8 @@ export const fetchCurrentUser = () => {
|
|||
return (dispatch) => {
|
||||
dispatch(loginRequest);
|
||||
return Kolide.me()
|
||||
.then(user => {
|
||||
.then(response => {
|
||||
const { user } = response;
|
||||
const { email } = user;
|
||||
const emailHash = md5(email.toLowerCase());
|
||||
|
||||
|
|
@ -52,12 +53,13 @@ export const loginUser = (formData) => {
|
|||
return new Promise((resolve, reject) => {
|
||||
dispatch(loginRequest);
|
||||
return Kolide.loginUser(formData)
|
||||
.then(user => {
|
||||
.then(response => {
|
||||
const { user } = response;
|
||||
const { email } = user;
|
||||
const emailHash = md5(email.toLowerCase());
|
||||
|
||||
user.gravatarURL = `https://www.gravatar.com/avatar/${emailHash}`;
|
||||
dispatch(loginSuccess(user));
|
||||
dispatch(loginSuccess(response));
|
||||
return resolve(user);
|
||||
})
|
||||
.catch(response => {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ export const initialState = {
|
|||
loading: false,
|
||||
error: null,
|
||||
user: null,
|
||||
token: null,
|
||||
};
|
||||
|
||||
const reducer = (state = initialState, action) => {
|
||||
|
|
@ -31,7 +32,8 @@ const reducer = (state = initialState, action) => {
|
|||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
user: action.payload.data,
|
||||
user: action.payload.data.user,
|
||||
token: action.payload.data.token,
|
||||
};
|
||||
case LOGIN_FAILURE:
|
||||
return {
|
||||
|
|
@ -44,6 +46,7 @@ const reducer = (state = initialState, action) => {
|
|||
...state,
|
||||
loading: false,
|
||||
user: null,
|
||||
token: null,
|
||||
};
|
||||
case LOGOUT_FAILURE:
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -23,27 +23,19 @@ type HostService interface {
|
|||
DeleteHost(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
type HostPayload struct {
|
||||
NodeKey *string
|
||||
HostName *string
|
||||
UUID *string
|
||||
IPAddress *string
|
||||
Platform *string
|
||||
}
|
||||
|
||||
type Host struct {
|
||||
ID uint `gorm:"primary_key" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
ID uint `json:"id" gorm:"primary_key"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DetailUpdateTime time.Time `json:"detail_updated_at"` // Time that the host details were last updated
|
||||
NodeKey string `gorm:"unique_index:idx_host_unique_nodekey" json:"-"`
|
||||
NodeKey string `json:"-" gorm:"unique_index:idx_host_unique_nodekey"`
|
||||
HostName string `json:"hostname"`
|
||||
UUID string `gorm:"unique_index:idx_host_unique_uuid" json:"uuid"`
|
||||
UUID string `json:"uuid" gorm:"unique_index:idx_host_unique_uuid"`
|
||||
Platform string `json:"platform"`
|
||||
OsqueryVersion string `json:"osquery_version"`
|
||||
OSVersion string `json:"os_version"`
|
||||
Uptime time.Duration `json:"uptime"`
|
||||
PhysicalMemory int `sql:"type:bigint" json:"memory"`
|
||||
PhysicalMemory int `json:"memory" sql:"type:bigint"`
|
||||
PrimaryMAC string `json:"mac"`
|
||||
PrimaryIP string `json:"ip"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,20 +58,20 @@ type InvitePayload struct {
|
|||
|
||||
// Invite represents an invitation for a user to join Kolide.
|
||||
type Invite struct {
|
||||
ID uint `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
InvitedBy uint `gorm:"not null"`
|
||||
Email string `gorm:"not null;unique_index:idx_invite_unique_email"`
|
||||
Admin bool
|
||||
Name string
|
||||
Position string
|
||||
Token string `gorm:"not null;unique_index:idx_invite_unique_key"`
|
||||
ID uint `json:"id" gorm:"primary_key"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
InvitedBy uint `json:"invited_by" gorm:"not null"`
|
||||
Email string `json:"email" gorm:"not null;unique_index:idx_invite_unique_email"`
|
||||
Admin bool `json:"admin"`
|
||||
Name string `json:"name"`
|
||||
Position string `json:"position,omitempty"`
|
||||
Token string `json:"-" gorm:"not null;unique_index:idx_invite_unique_key"`
|
||||
}
|
||||
|
||||
// TODO: fixme
|
||||
// this is not the right way to generate emails at all
|
||||
const inviteEmailTempate = `
|
||||
{{.InvitedBy}} invited you to join Kolide.,
|
||||
{{.InvitedBy}} invited you to join Kolide.,
|
||||
http://localhost:8080/signup?token={{.Token}}
|
||||
`
|
||||
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@ type LabelPayload struct {
|
|||
}
|
||||
|
||||
type Label struct {
|
||||
ID uint `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string `gorm:"not null;unique_index:idx_label_unique_name"`
|
||||
QueryID uint
|
||||
ID uint `json:"id" gorm:"primary_key"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
Name string `json:"name" gorm:"not null;unique_index:idx_label_unique_name"`
|
||||
QueryID uint `json:"query_id"`
|
||||
}
|
||||
|
||||
type LabelQueryExecution struct {
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@ type PackService interface {
|
|||
}
|
||||
|
||||
type Pack struct {
|
||||
ID uint `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string `gorm:"not null;unique_index:idx_pack_unique_name"`
|
||||
Platform string
|
||||
ID uint `json:"id" gorm:"primary_key"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
Name string `json:"name" gorm:"not null;unique_index:idx_pack_unique_name"`
|
||||
Platform string `json:"platform"`
|
||||
}
|
||||
|
||||
type PackQuery struct {
|
||||
|
|
|
|||
|
|
@ -39,16 +39,16 @@ type PackPayload struct {
|
|||
}
|
||||
|
||||
type Query struct {
|
||||
ID uint `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Name string `gorm:"not null;unique_index:idx_query_unique_name"`
|
||||
Query string `gorm:"not null"`
|
||||
Interval uint
|
||||
Snapshot bool
|
||||
Differential bool
|
||||
Platform string
|
||||
Version string
|
||||
ID uint `json:"id" gorm:"primary_key"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
Name string `json:"name" gorm:"not null;unique_index:idx_query_unique_name"`
|
||||
Query string `json:"query" gorm:"not null"`
|
||||
Interval uint `json:"interval"`
|
||||
Snapshot bool `json:"snapshot"`
|
||||
Differential bool `json:"differential"`
|
||||
Platform string `json:"platform"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
type DistributedQueryStatus int
|
||||
|
|
|
|||
|
|
@ -51,19 +51,19 @@ type UserService interface {
|
|||
|
||||
// User is the model struct which represents a kolide user
|
||||
type User struct {
|
||||
ID uint `gorm:"primary_key"`
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
Username string `gorm:"not null;unique_index:idx_user_unique_username"`
|
||||
Password []byte `gorm:"not null"`
|
||||
Salt string `gorm:"not null"`
|
||||
Name string
|
||||
Email string `gorm:"not null;unique_index:idx_user_unique_email"`
|
||||
Admin bool `gorm:"not null"`
|
||||
Enabled bool `gorm:"not null"`
|
||||
AdminForcedPasswordReset bool
|
||||
GravatarURL string
|
||||
Position string // job role
|
||||
ID uint `json:"id" gorm:"primary_key"`
|
||||
CreatedAt time.Time `json:"-"`
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
Username string `json:"username" gorm:"not null;unique_index:idx_user_unique_username"`
|
||||
Password []byte `json:"-" gorm:"not null"`
|
||||
Salt string `json:"-" gorm:"not null"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email" gorm:"not null;unique_index:idx_user_unique_email"`
|
||||
Admin bool `json:"admin" gorm:"not null"`
|
||||
Enabled bool `json:"enabled" gorm:"not null"`
|
||||
AdminForcedPasswordReset bool `json:"force_password_reset"`
|
||||
GravatarURL string `json:"gravatar_url"`
|
||||
Position string `json:"position,omitempty"` // job role
|
||||
}
|
||||
|
||||
// UserPayload is used to modify an existing user
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ type getHostRequest struct {
|
|||
}
|
||||
|
||||
type getHostResponse struct {
|
||||
kolide.Host
|
||||
Err error `json:"error,omitempty"`
|
||||
Host *kolide.Host `json:"host"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getHostResponse) error() error { return r.Err }
|
||||
|
|
@ -28,7 +28,7 @@ func makeGetHostEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return getHostResponse{Err: err}, nil
|
||||
}
|
||||
return getHostResponse{*host, nil}, nil
|
||||
return getHostResponse{host, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,13 +11,8 @@ type createInviteRequest struct {
|
|||
}
|
||||
|
||||
type createInviteResponse struct {
|
||||
ID uint `json:"id"`
|
||||
InvitedBy uint `json:"invited_by"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
Position string `json:"position,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Invite *kolide.Invite `json:"invite,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r createInviteResponse) error() error { return r.Err }
|
||||
|
|
@ -29,29 +24,13 @@ func makeCreateInviteEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return createInviteResponse{Err: err}, nil
|
||||
}
|
||||
return createInviteResponse{
|
||||
ID: invite.ID,
|
||||
InvitedBy: invite.InvitedBy,
|
||||
Email: invite.Email,
|
||||
Name: invite.Name,
|
||||
Position: invite.Position,
|
||||
Admin: invite.Admin,
|
||||
}, nil
|
||||
return createInviteResponse{invite, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
type inviteResponse struct {
|
||||
ID uint `json:"id"`
|
||||
InvitedBy uint `json:"invited_by"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
Position string `json:"position,omitempty"`
|
||||
}
|
||||
|
||||
type listInvitesResponse struct {
|
||||
Invites []inviteResponse `json:"invites"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Invites []kolide.Invite `json:"invites"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r listInvitesResponse) error() error { return r.Err }
|
||||
|
|
@ -63,16 +42,9 @@ func makeListInvitesEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
return listInvitesResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
resp := listInvitesResponse{Invites: []inviteResponse{}}
|
||||
resp := listInvitesResponse{Invites: []kolide.Invite{}}
|
||||
for _, invite := range invites {
|
||||
resp.Invites = append(resp.Invites, inviteResponse{
|
||||
ID: invite.ID,
|
||||
InvitedBy: invite.InvitedBy,
|
||||
Email: invite.Email,
|
||||
Name: invite.Name,
|
||||
Admin: invite.Admin,
|
||||
Position: invite.Position,
|
||||
})
|
||||
resp.Invites = append(resp.Invites, *invite)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,10 +15,8 @@ type getLabelRequest struct {
|
|||
}
|
||||
|
||||
type getLabelResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
QueryID uint `json:"query_id"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Label *kolide.Label `json:"label"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getLabelResponse) error() error { return r.Err }
|
||||
|
|
@ -30,11 +28,7 @@ func makeGetLabelEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return getLabelResponse{Err: err}, nil
|
||||
}
|
||||
return getLabelResponse{
|
||||
ID: label.ID,
|
||||
Name: label.Name,
|
||||
QueryID: label.QueryID,
|
||||
}, nil
|
||||
return getLabelResponse{label, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,8 +37,8 @@ func makeGetLabelEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type listLabelsResponse struct {
|
||||
Labels []getLabelResponse `json:"labels"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Labels []kolide.Label `json:"labels"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r listLabelsResponse) error() error { return r.Err }
|
||||
|
|
@ -56,13 +50,9 @@ func makeListLabelsEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
return listLabelsResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
resp := listLabelsResponse{Labels: []getLabelResponse{}}
|
||||
resp := listLabelsResponse{Labels: []kolide.Label{}}
|
||||
for _, label := range labels {
|
||||
resp.Labels = append(resp.Labels, getLabelResponse{
|
||||
ID: label.ID,
|
||||
Name: label.Name,
|
||||
QueryID: label.QueryID,
|
||||
})
|
||||
resp.Labels = append(resp.Labels, *label)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -77,10 +67,8 @@ type createLabelRequest struct {
|
|||
}
|
||||
|
||||
type createLabelResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
QueryID uint `json:"query_id"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Label *kolide.Label `json:"label"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r createLabelResponse) error() error { return r.Err }
|
||||
|
|
@ -92,11 +80,7 @@ func makeCreateLabelEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return createLabelResponse{Err: err}, nil
|
||||
}
|
||||
return createLabelResponse{
|
||||
ID: label.ID,
|
||||
Name: label.Name,
|
||||
QueryID: label.QueryID,
|
||||
}, nil
|
||||
return createLabelResponse{label, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,10 +94,8 @@ type modifyLabelRequest struct {
|
|||
}
|
||||
|
||||
type modifyLabelResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
QueryID uint `json:"query_id"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Label *kolide.Label `json:"label"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r modifyLabelResponse) error() error { return r.Err }
|
||||
|
|
@ -125,11 +107,7 @@ func makeModifyLabelEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return modifyLabelResponse{Err: err}, nil
|
||||
}
|
||||
return modifyLabelResponse{
|
||||
ID: label.ID,
|
||||
Name: label.Name,
|
||||
QueryID: label.QueryID,
|
||||
}, nil
|
||||
return modifyLabelResponse{label, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,8 @@ type getPackRequest struct {
|
|||
}
|
||||
|
||||
type getPackResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Platform string `json:"platform"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Pack *kolide.Pack `json:"pack,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getPackResponse) error() error { return r.Err }
|
||||
|
|
@ -30,11 +28,7 @@ func makeGetPackEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return getPackResponse{Err: err}, nil
|
||||
}
|
||||
return getPackResponse{
|
||||
ID: pack.ID,
|
||||
Name: pack.Name,
|
||||
Platform: pack.Platform,
|
||||
}, nil
|
||||
return getPackResponse{pack, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,8 +37,8 @@ func makeGetPackEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type listPacksResponse struct {
|
||||
Packs []getPackResponse `json:"packs"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Packs []kolide.Pack `json:"packs"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r listPacksResponse) error() error { return r.Err }
|
||||
|
|
@ -56,13 +50,9 @@ func makeListPacksEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
return getPackResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
resp := listPacksResponse{Packs: []getPackResponse{}}
|
||||
resp := listPacksResponse{Packs: []kolide.Pack{}}
|
||||
for _, pack := range packs {
|
||||
resp.Packs = append(resp.Packs, getPackResponse{
|
||||
ID: pack.ID,
|
||||
Name: pack.Name,
|
||||
Platform: pack.Platform,
|
||||
})
|
||||
resp.Packs = append(resp.Packs, *pack)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -77,10 +67,8 @@ type createPackRequest struct {
|
|||
}
|
||||
|
||||
type createPackResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Platform string `json:"platform"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Pack *kolide.Pack `json:"pack,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r createPackResponse) error() error { return r.Err }
|
||||
|
|
@ -92,11 +80,7 @@ func makeCreatePackEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return createPackResponse{Err: err}, nil
|
||||
}
|
||||
return createPackResponse{
|
||||
ID: pack.ID,
|
||||
Name: pack.Name,
|
||||
Platform: pack.Platform,
|
||||
}, nil
|
||||
return createPackResponse{pack, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -110,10 +94,8 @@ type modifyPackRequest struct {
|
|||
}
|
||||
|
||||
type modifyPackResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Platform string `json:"platform"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Pack *kolide.Pack `json:"pack,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r modifyPackResponse) error() error { return r.Err }
|
||||
|
|
@ -125,11 +107,7 @@ func makeModifyPackEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return modifyPackResponse{Err: err}, nil
|
||||
}
|
||||
return modifyPackResponse{
|
||||
ID: pack.ID,
|
||||
Name: pack.Name,
|
||||
Platform: pack.Platform,
|
||||
}, nil
|
||||
return modifyPackResponse{pack, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -193,8 +171,8 @@ type getQueriesInPackRequest struct {
|
|||
}
|
||||
|
||||
type getQueriesInPackResponse struct {
|
||||
Queries []getQueryResponse
|
||||
Err error `json:"error,omitempty"`
|
||||
Queries []kolide.Query `json:"queries"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getQueriesInPackResponse) error() error { return r.Err }
|
||||
|
|
@ -209,16 +187,7 @@ func makeGetQueriesInPackEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
|
||||
var resp getQueriesInPackResponse
|
||||
for _, query := range queries {
|
||||
resp.Queries = append(resp.Queries, getQueryResponse{
|
||||
ID: query.ID,
|
||||
Name: query.Name,
|
||||
Query: query.Query,
|
||||
Interval: query.Interval,
|
||||
Snapshot: query.Snapshot,
|
||||
Differential: query.Differential,
|
||||
Platform: query.Platform,
|
||||
Version: query.Version,
|
||||
})
|
||||
resp.Queries = append(resp.Queries, *query)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -285,8 +254,8 @@ type getLabelsForPackRequest struct {
|
|||
}
|
||||
|
||||
type getLabelsForPackResponse struct {
|
||||
Labels []getLabelResponse
|
||||
Err error `json:"error,omitempty"`
|
||||
Labels []kolide.Label `json:"labels"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getLabelsForPackResponse) error() error { return r.Err }
|
||||
|
|
@ -301,11 +270,7 @@ func makeGetLabelsForPackEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
|
||||
var resp getLabelsForPackResponse
|
||||
for _, label := range labels {
|
||||
resp.Labels = append(resp.Labels, getLabelResponse{
|
||||
ID: label.ID,
|
||||
Name: label.Name,
|
||||
QueryID: label.QueryID,
|
||||
})
|
||||
resp.Labels = append(resp.Labels, *label)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,15 +15,8 @@ type getQueryRequest struct {
|
|||
}
|
||||
|
||||
type getQueryResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
Interval uint `json:"interval"`
|
||||
Snapshot bool `json:"snapshot"`
|
||||
Differential bool `json:"differential"`
|
||||
Platform string `json:"platform"`
|
||||
Version string `json:"version"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Query *kolide.Query `json:"query,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getQueryResponse) error() error { return r.Err }
|
||||
|
|
@ -35,16 +28,7 @@ func makeGetQueryEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return getQueryResponse{Err: err}, nil
|
||||
}
|
||||
return getQueryResponse{
|
||||
ID: query.ID,
|
||||
Name: query.Name,
|
||||
Query: query.Query,
|
||||
Interval: query.Interval,
|
||||
Snapshot: query.Snapshot,
|
||||
Differential: query.Differential,
|
||||
Platform: query.Platform,
|
||||
Version: query.Version,
|
||||
}, nil
|
||||
return getQueryResponse{query, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -53,8 +37,8 @@ func makeGetQueryEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type listQueriesResponse struct {
|
||||
Queries []getQueryResponse `json:"queries"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Queries []kolide.Query `json:"queries"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r listQueriesResponse) error() error { return r.Err }
|
||||
|
|
@ -66,18 +50,9 @@ func makeListQueriesEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
return listQueriesResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
resp := listQueriesResponse{Queries: []getQueryResponse{}}
|
||||
resp := listQueriesResponse{Queries: []kolide.Query{}}
|
||||
for _, query := range queries {
|
||||
resp.Queries = append(resp.Queries, getQueryResponse{
|
||||
ID: query.ID,
|
||||
Name: query.Name,
|
||||
Query: query.Query,
|
||||
Interval: query.Interval,
|
||||
Snapshot: query.Snapshot,
|
||||
Differential: query.Differential,
|
||||
Platform: query.Platform,
|
||||
Version: query.Version,
|
||||
})
|
||||
resp.Queries = append(resp.Queries, *query)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -92,15 +67,8 @@ type createQueryRequest struct {
|
|||
}
|
||||
|
||||
type createQueryResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
Interval uint `json:"interval"`
|
||||
Snapshot bool `json:"snapshot"`
|
||||
Differential bool `json:"differential"`
|
||||
Platform string `json:"platform"`
|
||||
Version string `json:"version"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Query *kolide.Query `json:"query,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r createQueryResponse) error() error { return r.Err }
|
||||
|
|
@ -112,16 +80,7 @@ func makeCreateQueryEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return createQueryResponse{Err: err}, nil
|
||||
}
|
||||
return createQueryResponse{
|
||||
ID: query.ID,
|
||||
Name: query.Name,
|
||||
Query: query.Query,
|
||||
Interval: query.Interval,
|
||||
Snapshot: query.Snapshot,
|
||||
Differential: query.Differential,
|
||||
Platform: query.Platform,
|
||||
Version: query.Version,
|
||||
}, nil
|
||||
return createQueryResponse{query, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,15 +94,8 @@ type modifyQueryRequest struct {
|
|||
}
|
||||
|
||||
type modifyQueryResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Query string `json:"query"`
|
||||
Interval uint `json:"interval"`
|
||||
Snapshot bool `json:"snapshot"`
|
||||
Differential bool `json:"differential"`
|
||||
Platform string `json:"platform"`
|
||||
Version string `json:"version"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Query *kolide.Query `json:"query,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r modifyQueryResponse) error() error { return r.Err }
|
||||
|
|
@ -155,16 +107,7 @@ func makeModifyQueryEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return modifyQueryResponse{Err: err}, nil
|
||||
}
|
||||
return modifyQueryResponse{
|
||||
ID: query.ID,
|
||||
Name: query.Name,
|
||||
Query: query.Query,
|
||||
Interval: query.Interval,
|
||||
Snapshot: query.Snapshot,
|
||||
Differential: query.Differential,
|
||||
Platform: query.Platform,
|
||||
Version: query.Version,
|
||||
}, nil
|
||||
return modifyQueryResponse{query, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,16 +18,9 @@ type loginRequest struct {
|
|||
}
|
||||
|
||||
type loginResponse struct {
|
||||
Token string `json:"token"`
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Position string `json:"position,omitempty"`
|
||||
AdminForcedPasswordReset bool `json:"force_password_reset"`
|
||||
Err error `json:"error,omitempty"`
|
||||
User *kolide.User `json:"user,omitempty"`
|
||||
Token string `json:"token,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r loginResponse) error() error { return r.Err }
|
||||
|
|
@ -39,17 +32,7 @@ func makeLoginEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return loginResponse{Err: err}, nil
|
||||
}
|
||||
return loginResponse{
|
||||
Token: token,
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Admin: user.Admin,
|
||||
Enabled: user.Enabled,
|
||||
Position: user.Position,
|
||||
AdminForcedPasswordReset: user.AdminForcedPasswordReset,
|
||||
}, nil
|
||||
return loginResponse{user, token, nil}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,15 +17,8 @@ type createUserRequest struct {
|
|||
}
|
||||
|
||||
type createUserResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Position string `json:"position,omitempty"`
|
||||
AdminForcedPasswordReset bool `json:"force_password_reset"`
|
||||
Err error `json:"error,omitempty"`
|
||||
User *kolide.User `json:"user,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r createUserResponse) error() error { return r.Err }
|
||||
|
|
@ -37,16 +30,7 @@ func makeCreateUserEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return createUserResponse{Err: err}, nil
|
||||
}
|
||||
return createUserResponse{
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Admin: user.Admin,
|
||||
Enabled: user.Enabled,
|
||||
Position: user.Position,
|
||||
AdminForcedPasswordReset: user.AdminForcedPasswordReset,
|
||||
}, nil
|
||||
return createUserResponse{User: user}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -59,15 +43,8 @@ type getUserRequest struct {
|
|||
}
|
||||
|
||||
type getUserResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Position string `json:"position,omitempty"`
|
||||
AdminForcedPasswordReset bool `json:"force_password_reset"`
|
||||
Err error `json:"error,omitempty"`
|
||||
User *kolide.User `json:"user,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r getUserResponse) error() error { return r.Err }
|
||||
|
|
@ -79,16 +56,7 @@ func makeGetUserEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return getUserResponse{Err: err}, nil
|
||||
}
|
||||
return getUserResponse{
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Admin: user.Admin,
|
||||
Enabled: user.Enabled,
|
||||
Position: user.Position,
|
||||
AdminForcedPasswordReset: user.AdminForcedPasswordReset,
|
||||
}, nil
|
||||
return getUserResponse{User: user}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -98,16 +66,7 @@ func makeGetSessionUserEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
if err != nil {
|
||||
return getUserResponse{Err: err}, nil
|
||||
}
|
||||
return getUserResponse{
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Admin: user.Admin,
|
||||
Enabled: user.Enabled,
|
||||
Position: user.Position,
|
||||
AdminForcedPasswordReset: user.AdminForcedPasswordReset,
|
||||
}, nil
|
||||
return getUserResponse{User: user}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,8 +75,8 @@ func makeGetSessionUserEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
type listUsersResponse struct {
|
||||
Users []getUserResponse `json:"users"`
|
||||
Err error `json:"error,omitempty"`
|
||||
Users []kolide.User `json:"users"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r listUsersResponse) error() error { return r.Err }
|
||||
|
|
@ -129,18 +88,9 @@ func makeListUsersEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
return listUsersResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
resp := listUsersResponse{Users: []getUserResponse{}}
|
||||
resp := listUsersResponse{Users: []kolide.User{}}
|
||||
for _, user := range users {
|
||||
resp.Users = append(resp.Users, getUserResponse{
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Admin: user.Admin,
|
||||
Enabled: user.Enabled,
|
||||
Position: user.Position,
|
||||
AdminForcedPasswordReset: user.AdminForcedPasswordReset,
|
||||
})
|
||||
resp.Users = append(resp.Users, *user)
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
|
@ -179,15 +129,8 @@ type modifyUserRequest struct {
|
|||
}
|
||||
|
||||
type modifyUserResponse struct {
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
Enabled bool `json:"enabled"`
|
||||
Position string `json:"position,omitempty"`
|
||||
AdminForcedPasswordReset bool `json:"force_password_reset"`
|
||||
Err error `json:"error,omitempty"`
|
||||
User *kolide.User `json:"user,omitempty"`
|
||||
Err error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (r modifyUserResponse) error() error { return r.Err }
|
||||
|
|
@ -200,17 +143,7 @@ func makeModifyUserEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|||
return modifyUserResponse{Err: err}, nil
|
||||
}
|
||||
|
||||
return modifyUserResponse{
|
||||
ID: user.ID,
|
||||
Username: user.Username,
|
||||
Name: user.Name,
|
||||
Email: user.Email,
|
||||
Admin: user.Admin,
|
||||
Enabled: user.Enabled,
|
||||
Position: user.Position,
|
||||
AdminForcedPasswordReset: user.AdminForcedPasswordReset,
|
||||
Err: err,
|
||||
}, nil
|
||||
return modifyUserResponse{User: user}, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import (
|
|||
kithttp "github.com/go-kit/kit/transport/http"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/kolide/kolide-ose/server/datastore"
|
||||
"github.com/kolide/kolide-ose/server/kolide"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
|
|
@ -55,6 +56,11 @@ func TestLogin(t *testing.T) {
|
|||
password: testUsers["admin1"].PlaintextPassword,
|
||||
status: http.StatusOK,
|
||||
},
|
||||
{
|
||||
username: "user1",
|
||||
password: testUsers["user1"].PlaintextPassword,
|
||||
status: http.StatusOK,
|
||||
},
|
||||
{
|
||||
username: "nosuchuser",
|
||||
password: "nosuchuser",
|
||||
|
|
@ -89,15 +95,9 @@ func TestLogin(t *testing.T) {
|
|||
assert.Equal(t, tt.status, resp.StatusCode)
|
||||
|
||||
var jsn = struct {
|
||||
Token string `json:"token"`
|
||||
ID uint `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Email string `json:"email"`
|
||||
Name string `json:"name"`
|
||||
Admin bool `json:"admin"`
|
||||
Enabled bool `json:"enabled"`
|
||||
NeedsPasswordReset bool `json:"needs_password_reset"`
|
||||
Err string `json:"error,omitempty"`
|
||||
User *kolide.User `json:"user"`
|
||||
Token string `json:"token"`
|
||||
Err string `json:"error,omitempty"`
|
||||
}{}
|
||||
err = json.NewDecoder(resp.Body).Decode(&jsn)
|
||||
assert.Nil(t, err)
|
||||
|
|
@ -107,7 +107,9 @@ func TestLogin(t *testing.T) {
|
|||
continue // skip remaining tests
|
||||
}
|
||||
|
||||
assert.Equal(t, shouldBeAdmin, jsn.Admin)
|
||||
require.NotNil(t, jsn.User)
|
||||
assert.Equal(t, shouldBeAdmin, jsn.User.Admin)
|
||||
assert.Equal(t, tt.username, jsn.User.Username)
|
||||
|
||||
// ensure that a session was created for our test user and stored
|
||||
sessions, err := ds.FindAllSessionsForUser(testUser.ID)
|
||||
|
|
|
|||
Loading…
Reference in a new issue