mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
6fb96d98f7
User service checks that tokens are valid on new user signups. Closes #230
64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/kolide/kolide-ose/server/kolide"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
func (mw metricsMiddleware) InviteNewUser(ctx context.Context, payload kolide.InvitePayload) (*kolide.Invite, error) {
|
|
var (
|
|
invite *kolide.Invite
|
|
err error
|
|
)
|
|
defer func(begin time.Time) {
|
|
lvs := []string{"method", "InviteNewUser", "error", fmt.Sprint(err != nil)}
|
|
mw.requestCount.With(lvs...).Add(1)
|
|
mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
invite, err = mw.Service.InviteNewUser(ctx, payload)
|
|
return invite, err
|
|
}
|
|
|
|
func (mw metricsMiddleware) DeleteInvite(ctx context.Context, id uint) error {
|
|
var (
|
|
err error
|
|
)
|
|
defer func(begin time.Time) {
|
|
lvs := []string{"method", "DeleteInvite", "error", fmt.Sprint(err != nil)}
|
|
mw.requestCount.With(lvs...).Add(1)
|
|
mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
err = mw.Service.DeleteInvite(ctx, id)
|
|
return err
|
|
}
|
|
|
|
func (mw metricsMiddleware) Invites(ctx context.Context) ([]*kolide.Invite, error) {
|
|
var (
|
|
invites []*kolide.Invite
|
|
err error
|
|
)
|
|
defer func(begin time.Time) {
|
|
lvs := []string{"method", "Invites", "error", fmt.Sprint(err != nil)}
|
|
mw.requestCount.With(lvs...).Add(1)
|
|
mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
invites, err = mw.Service.Invites(ctx)
|
|
return invites, err
|
|
}
|
|
|
|
func (mw metricsMiddleware) VerifyInvite(ctx context.Context, email string, token string) error {
|
|
var (
|
|
err error
|
|
)
|
|
defer func(begin time.Time) {
|
|
lvs := []string{"method", "VerifyInvite", "error", fmt.Sprint(err != nil)}
|
|
mw.requestCount.With(lvs...).Add(1)
|
|
mw.requestLatency.With(lvs...).Observe(time.Since(begin).Seconds())
|
|
}(time.Now())
|
|
err = mw.Service.VerifyInvite(ctx, email, token)
|
|
return err
|
|
}
|