1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-29 13:49:28 +08:00
b1ackd0t d008ae5d97
NOISSUE - Add cert revocation to SDK (#1693)
* initial commit

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* fix certificate revoking

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* change from mapstructure to json

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* add comments to serial modification

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* fix typo

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* update vault docker version

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* write env variables

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* change env path

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* return revocation time

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* revert to intermediate CA

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* remove deadcode

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* make revoke cert output readable

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* remove keybits and keytype

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* remove dead code

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* make inline

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* add empty line

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* remove commented code

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* remove keyBits

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

* remove keyBits

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>

Signed-off-by: rodneyosodo <socials@rodneyosodo.com>
Co-authored-by: rodneyosodo <socials@rodneyosodo.com>
2023-01-13 14:33:00 +01:00

93 lines
3.0 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
//go:build !test
package api
import (
"context"
"fmt"
"time"
"github.com/mainflux/mainflux/certs"
log "github.com/mainflux/mainflux/logger"
)
var _ certs.Service = (*loggingMiddleware)(nil)
type loggingMiddleware struct {
logger log.Logger
svc certs.Service
}
// NewLoggingMiddleware adds logging facilities to the core service.
func NewLoggingMiddleware(svc certs.Service, logger log.Logger) certs.Service {
return &loggingMiddleware{logger, svc}
}
func (lm *loggingMiddleware) IssueCert(ctx context.Context, token, thingID, ttl string) (c certs.Cert, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method issue_cert for token: %s and thing: %s took %s to complete", token, thingID, time.Since(begin))
if err != nil {
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err))
return
}
lm.logger.Info(fmt.Sprintf("%s without errors.", message))
}(time.Now())
return lm.svc.IssueCert(ctx, token, thingID, ttl)
}
func (lm *loggingMiddleware) ListCerts(ctx context.Context, token, thingID string, offset, limit uint64) (cp certs.Page, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method list_certs for token: %s and thing id: %s took %s to complete", token, thingID, time.Since(begin))
if err != nil {
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err))
return
}
lm.logger.Info(fmt.Sprintf("%s without errors.", message))
}(time.Now())
return lm.svc.ListCerts(ctx, token, thingID, offset, limit)
}
func (lm *loggingMiddleware) ListSerials(ctx context.Context, token, thingID string, offset, limit uint64) (cp certs.Page, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method list_serials for token: %s and thing id: %s took %s to complete", token, thingID, time.Since(begin))
if err != nil {
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err))
return
}
lm.logger.Info(fmt.Sprintf("%s without errors.", message))
}(time.Now())
return lm.svc.ListSerials(ctx, token, thingID, offset, limit)
}
func (lm *loggingMiddleware) ViewCert(ctx context.Context, token, serialID string) (c certs.Cert, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method view_cert for token: %s and serial id %s took %s to complete", token, serialID, time.Since(begin))
if err != nil {
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err))
return
}
lm.logger.Info(fmt.Sprintf("%s without errors.", message))
}(time.Now())
return lm.svc.ViewCert(ctx, token, serialID)
}
func (lm *loggingMiddleware) RevokeCert(ctx context.Context, token, thingID string) (c certs.Revoke, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method revoke_cert for token: %s and thing: %s took %s to complete", token, thingID, time.Since(begin))
if err != nil {
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err))
return
}
lm.logger.Info(fmt.Sprintf("%s without errors.", message))
}(time.Now())
return lm.svc.RevokeCert(ctx, token, thingID)
}