2019-05-06 00:56:27 +00:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-kit/kit/log"
|
2019-07-20 08:12:58 +00:00
|
|
|
|
2019-07-11 02:33:22 +00:00
|
|
|
"github.com/mitchell/selfpass/services/credentials/types"
|
2019-05-06 00:56:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func NewServiceLogger(l log.Logger, next types.Service) ServiceLogger {
|
|
|
|
return ServiceLogger{
|
|
|
|
l: l,
|
|
|
|
next: next,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ServiceLogger struct {
|
|
|
|
l log.Logger
|
|
|
|
next types.Service
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc ServiceLogger) GetAllMetadata(ctx context.Context, sourceHost string) (output <-chan types.Metadata, errch chan error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = svc.l.Log(
|
|
|
|
"service", "Credentials",
|
|
|
|
"method", "GetAllMetadata",
|
|
|
|
"input", sourceHost,
|
|
|
|
"output", "channel",
|
|
|
|
"err", "channel",
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
return svc.next.GetAllMetadata(ctx, sourceHost)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc ServiceLogger) Get(ctx context.Context, id string) (output types.Credential, err error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = svc.l.Log(
|
|
|
|
"service", "Credentials",
|
|
|
|
"method", "Get",
|
|
|
|
"input", id,
|
|
|
|
"output", output,
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
output, err = svc.next.Get(ctx, id)
|
|
|
|
return output, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc ServiceLogger) Create(ctx context.Context, ci types.CredentialInput) (output types.Credential, err error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = svc.l.Log(
|
|
|
|
"service", "Credentials",
|
|
|
|
"method", "Create",
|
|
|
|
"input", ci,
|
|
|
|
"output", output,
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
output, err = svc.next.Create(ctx, ci)
|
|
|
|
return output, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc ServiceLogger) Update(ctx context.Context, id string, ci types.CredentialInput) (output types.Credential, err error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = svc.l.Log(
|
|
|
|
"service", "Credentials",
|
|
|
|
"method", "Update",
|
|
|
|
"input", []interface{}{id, ci},
|
|
|
|
"output", output,
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
output, err = svc.next.Update(ctx, id, ci)
|
|
|
|
return output, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (svc ServiceLogger) Delete(ctx context.Context, id string) (err error) {
|
|
|
|
defer func(begin time.Time) {
|
|
|
|
_ = svc.l.Log(
|
|
|
|
"service", "Credentials",
|
|
|
|
"method", "Delete",
|
|
|
|
"input", id,
|
|
|
|
"err", err,
|
|
|
|
"took", time.Since(begin),
|
|
|
|
)
|
|
|
|
}(time.Now())
|
|
|
|
|
|
|
|
err = svc.next.Delete(ctx, id)
|
|
|
|
return err
|
|
|
|
}
|