2016-09-29 02:44:05 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
|
|
|
|
2016-09-29 02:44:05 +00:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
2017-06-22 19:50:45 +00:00
|
|
|
"github.com/kolide/fleet/server/kolide"
|
2016-09-29 02:44:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type createInviteRequest struct {
|
|
|
|
payload kolide.InvitePayload
|
|
|
|
}
|
|
|
|
|
|
|
|
type createInviteResponse struct {
|
2016-10-11 16:22:11 +00:00
|
|
|
Invite *kolide.Invite `json:"invite,omitempty"`
|
|
|
|
Err error `json:"error,omitempty"`
|
2016-09-29 02:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r createInviteResponse) error() error { return r.Err }
|
|
|
|
|
|
|
|
func makeCreateInviteEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(createInviteRequest)
|
|
|
|
invite, err := svc.InviteNewUser(ctx, req.payload)
|
|
|
|
if err != nil {
|
|
|
|
return createInviteResponse{Err: err}, nil
|
|
|
|
}
|
2016-10-11 16:22:11 +00:00
|
|
|
return createInviteResponse{invite, nil}, nil
|
2016-09-29 02:44:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-13 18:21:47 +00:00
|
|
|
type listInvitesRequest struct {
|
|
|
|
ListOptions kolide.ListOptions
|
|
|
|
}
|
|
|
|
|
2016-09-29 02:44:05 +00:00
|
|
|
type listInvitesResponse struct {
|
2016-10-11 16:22:11 +00:00
|
|
|
Invites []kolide.Invite `json:"invites"`
|
|
|
|
Err error `json:"error,omitempty"`
|
2016-09-29 02:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (r listInvitesResponse) error() error { return r.Err }
|
|
|
|
|
|
|
|
func makeListInvitesEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
2016-10-13 18:21:47 +00:00
|
|
|
req := request.(listInvitesRequest)
|
|
|
|
invites, err := svc.ListInvites(ctx, req.ListOptions)
|
2016-09-29 02:44:05 +00:00
|
|
|
if err != nil {
|
|
|
|
return listInvitesResponse{Err: err}, nil
|
|
|
|
}
|
2016-10-06 16:24:12 +00:00
|
|
|
|
2016-10-11 16:22:11 +00:00
|
|
|
resp := listInvitesResponse{Invites: []kolide.Invite{}}
|
2016-09-29 02:44:05 +00:00
|
|
|
for _, invite := range invites {
|
2016-10-11 16:22:11 +00:00
|
|
|
resp.Invites = append(resp.Invites, *invite)
|
2016-09-29 02:44:05 +00:00
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type deleteInviteRequest struct {
|
|
|
|
ID uint
|
|
|
|
}
|
|
|
|
|
|
|
|
type deleteInviteResponse struct {
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
2016-12-30 01:58:12 +00:00
|
|
|
func (r deleteInviteResponse) error() error { return r.Err }
|
|
|
|
|
2016-09-29 02:44:05 +00:00
|
|
|
func makeDeleteInviteEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(deleteInviteRequest)
|
|
|
|
err := svc.DeleteInvite(ctx, req.ID)
|
|
|
|
if err != nil {
|
|
|
|
return deleteInviteResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
return deleteInviteResponse{}, nil
|
|
|
|
}
|
|
|
|
}
|
2016-12-30 01:58:12 +00:00
|
|
|
|
|
|
|
type verifyInviteRequest struct {
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
|
|
|
type verifyInviteResponse struct {
|
|
|
|
Invite *kolide.Invite `json:"invite"`
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r verifyInviteResponse) error() error { return r.Err }
|
|
|
|
|
|
|
|
func makeVerifyInviteEndpoint(svc kolide.Service) endpoint.Endpoint {
|
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(verifyInviteRequest)
|
|
|
|
invite, err := svc.VerifyInvite(ctx, req.Token)
|
|
|
|
if err != nil {
|
|
|
|
return verifyInviteResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
return verifyInviteResponse{Invite: invite}, nil
|
|
|
|
}
|
|
|
|
}
|