2016-09-29 02:44:05 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/kolide/kolide-ose/server/contexts/viewer"
|
|
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (mw loggingMiddleware) InviteNewUser(ctx context.Context, payload kolide.InvitePayload) (*kolide.Invite, error) {
|
|
|
|
var (
|
|
|
|
invite *kolide.Invite
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
|
|
|
|
vc, ok := viewer.FromContext(ctx)
|
|
|
|
if !ok {
|
|
|
|
return nil, errNoContext
|
|
|
|
}
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "InviteNewUser",
|
|
|
|
"created_by", vc.Username(),
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
invite, err = mw.Service.InviteNewUser(ctx, payload)
|
|
|
|
return invite, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mw loggingMiddleware) DeleteInvite(ctx context.Context, id uint) error {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
vc, ok := viewer.FromContext(ctx)
|
|
|
|
if !ok {
|
|
|
|
return errNoContext
|
|
|
|
}
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "DeleteInvite",
|
|
|
|
"deleted_by", vc.Username(),
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
err = mw.Service.DeleteInvite(ctx, id)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-10-14 15:59:27 +00:00
|
|
|
func (mw loggingMiddleware) ListInvites(ctx context.Context, opt kolide.ListOptions) ([]*kolide.Invite, error) {
|
2016-09-29 02:44:05 +00:00
|
|
|
var (
|
|
|
|
invites []*kolide.Invite
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
vc, ok := viewer.FromContext(ctx)
|
|
|
|
if !ok {
|
|
|
|
return nil, errNoContext
|
|
|
|
}
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "Invites",
|
|
|
|
"called_by", vc.Username(),
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
2016-10-14 15:59:27 +00:00
|
|
|
invites, err = mw.Service.ListInvites(ctx, opt)
|
2016-09-29 02:44:05 +00:00
|
|
|
return invites, err
|
|
|
|
}
|
|
|
|
|
2016-12-30 01:58:12 +00:00
|
|
|
func (mw loggingMiddleware) VerifyInvite(ctx context.Context, token string) (*kolide.Invite, error) {
|
2016-09-29 02:44:05 +00:00
|
|
|
var (
|
2016-12-30 01:58:12 +00:00
|
|
|
err error
|
|
|
|
invite *kolide.Invite
|
2016-09-29 02:44:05 +00:00
|
|
|
)
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = mw.logger.Log(
|
|
|
|
"method", "VerifyInvite",
|
2016-12-30 01:58:12 +00:00
|
|
|
"token", token,
|
2016-09-29 02:44:05 +00:00
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
2016-12-30 01:58:12 +00:00
|
|
|
invite, err = mw.Service.VerifyInvite(ctx, token)
|
|
|
|
return invite, err
|
2016-09-29 02:44:05 +00:00
|
|
|
}
|