2018-08-15 20:14:51 +00:00
|
|
|
package zap
|
2018-05-14 16:26:38 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2019-01-08 00:37:16 +00:00
|
|
|
platform "github.com/influxdata/influxdb"
|
2018-05-14 16:26:38 +00:00
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2018-08-28 18:01:32 +00:00
|
|
|
var _ platform.AuthorizationService = (*AuthorizationService)(nil)
|
|
|
|
|
2018-05-14 16:26:38 +00:00
|
|
|
// AuthorizationService manages authorizations.
|
|
|
|
type AuthorizationService struct {
|
|
|
|
Logger *zap.Logger
|
|
|
|
AuthorizationService platform.AuthorizationService
|
|
|
|
}
|
|
|
|
|
2018-05-16 18:59:35 +00:00
|
|
|
// FindAuthorizationByID returns an authorization given an id, and logs any errors.
|
|
|
|
func (s *AuthorizationService) FindAuthorizationByID(ctx context.Context, id platform.ID) (a *platform.Authorization, err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.Info("error finding authorization by id", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return s.AuthorizationService.FindAuthorizationByID(ctx, id)
|
|
|
|
}
|
|
|
|
|
2018-05-14 16:26:38 +00:00
|
|
|
// FindAuthorizationByToken returns an authorization given a token, and logs any errors.
|
|
|
|
func (s *AuthorizationService) FindAuthorizationByToken(ctx context.Context, t string) (a *platform.Authorization, err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.Info("error finding authorization by token", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return s.AuthorizationService.FindAuthorizationByToken(ctx, t)
|
|
|
|
}
|
|
|
|
|
|
|
|
// FindAuthorizations returns authorizations given a filter, and logs any errors.
|
|
|
|
func (s *AuthorizationService) FindAuthorizations(ctx context.Context, filter platform.AuthorizationFilter, opt ...platform.FindOptions) (as []*platform.Authorization, i int, err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.Info("error finding authorizations", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return s.AuthorizationService.FindAuthorizations(ctx, filter, opt...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateAuthorization creates an authorization, and logs any errors.
|
|
|
|
func (s *AuthorizationService) CreateAuthorization(ctx context.Context, a *platform.Authorization) (err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.Info("error creating authorization", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return s.AuthorizationService.CreateAuthorization(ctx, a)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteAuthorization deletes an authorization, and logs any errors.
|
2018-05-16 18:59:35 +00:00
|
|
|
func (s *AuthorizationService) DeleteAuthorization(ctx context.Context, id platform.ID) (err error) {
|
2018-05-14 16:26:38 +00:00
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.Info("error deleting authorization", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-05-16 18:59:35 +00:00
|
|
|
return s.AuthorizationService.DeleteAuthorization(ctx, id)
|
2018-05-14 16:26:38 +00:00
|
|
|
}
|
2018-08-28 18:01:32 +00:00
|
|
|
|
|
|
|
// SetAuthorizationStatus updates an authorization's status and logs any errors.
|
|
|
|
func (s *AuthorizationService) SetAuthorizationStatus(ctx context.Context, id platform.ID, status platform.Status) (err error) {
|
|
|
|
defer func() {
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.Info("error updating authorization", zap.Error(err))
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
return s.AuthorizationService.SetAuthorizationStatus(ctx, id, status)
|
|
|
|
}
|