Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
Signed-off-by: Arvindh <[email protected]>
  • Loading branch information
arvindh123 committed Jul 12, 2024
1 parent 6189088 commit b4d46c5
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 12 deletions.
1 change: 0 additions & 1 deletion auth/api/http/pats/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ func removePATScopeEntryEndpoint(svc auth.Service) endpoint.Endpoint {
}
return removePatScopeEntryRes{scope}, nil
}

}

func clearPATAllScopeEntryEndpoint(svc auth.Service) endpoint.Endpoint {
Expand Down
3 changes: 1 addition & 2 deletions auth/api/http/pats/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func (apser *addPatScopeEntryReq) UnmarshalJSON(data []byte) error {
apser.Operation = op
apser.EntityIDs = temp.EntityIDs
return nil

}

func (req addPatScopeEntryReq) validate() (err error) {
if req.token == "" {
return apiutil.ErrBearerToken
Expand Down Expand Up @@ -275,7 +275,6 @@ func (rpser *removePatScopeEntryReq) UnmarshalJSON(data []byte) error {
rpser.Operation = op
rpser.EntityIDs = temp.EntityIDs
return nil

}

func (req removePatScopeEntryReq) validate() (err error) {
Expand Down
13 changes: 13 additions & 0 deletions auth/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ func (lm *loggingMiddleware) CreatePAT(ctx context.Context, token, name, descrip
}(time.Now())
return lm.svc.CreatePAT(ctx, token, name, description, duration, scope)
}

func (lm *loggingMiddleware) UpdatePATName(ctx context.Context, token, patID, name string) (pa auth.PAT, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -542,6 +543,7 @@ func (lm *loggingMiddleware) UpdatePATName(ctx context.Context, token, patID, na
}(time.Now())
return lm.svc.UpdatePATName(ctx, token, patID, name)
}

func (lm *loggingMiddleware) UpdatePATDescription(ctx context.Context, token, patID, description string) (pa auth.PAT, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -558,6 +560,7 @@ func (lm *loggingMiddleware) UpdatePATDescription(ctx context.Context, token, pa
}(time.Now())
return lm.svc.UpdatePATDescription(ctx, token, patID, description)
}

func (lm *loggingMiddleware) RetrievePAT(ctx context.Context, token, patID string) (pa auth.PAT, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -573,6 +576,7 @@ func (lm *loggingMiddleware) RetrievePAT(ctx context.Context, token, patID strin
}(time.Now())
return lm.svc.RetrievePAT(ctx, token, patID)
}

func (lm *loggingMiddleware) ListPATS(ctx context.Context, token string, pm auth.PATSPageMeta) (pp auth.PATSPage, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -589,6 +593,7 @@ func (lm *loggingMiddleware) ListPATS(ctx context.Context, token string, pm auth
}(time.Now())
return lm.svc.ListPATS(ctx, token, pm)
}

func (lm *loggingMiddleware) DeletePAT(ctx context.Context, token, patID string) (err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -604,6 +609,7 @@ func (lm *loggingMiddleware) DeletePAT(ctx context.Context, token, patID string)
}(time.Now())
return lm.svc.DeletePAT(ctx, token, patID)
}

func (lm *loggingMiddleware) ResetPATSecret(ctx context.Context, token, patID string, duration time.Duration) (pa auth.PAT, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -620,6 +626,7 @@ func (lm *loggingMiddleware) ResetPATSecret(ctx context.Context, token, patID st
}(time.Now())
return lm.svc.ResetPATSecret(ctx, token, patID, duration)
}

func (lm *loggingMiddleware) RevokePATSecret(ctx context.Context, token, patID string) (err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -635,6 +642,7 @@ func (lm *loggingMiddleware) RevokePATSecret(ctx context.Context, token, patID s
}(time.Now())
return lm.svc.RevokePATSecret(ctx, token, patID)
}

func (lm *loggingMiddleware) AddPATScopeEntry(ctx context.Context, token, patID string, platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) (sc auth.Scope, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -655,6 +663,7 @@ func (lm *loggingMiddleware) AddPATScopeEntry(ctx context.Context, token, patID
}(time.Now())
return lm.svc.AddPATScopeEntry(ctx, token, patID, platformEntityType, optionalDomainID, optionalDomainEntityType, operation, entityIDs...)
}

func (lm *loggingMiddleware) RemovePATScopeEntry(ctx context.Context, token, patID string, platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) (sc auth.Scope, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -675,6 +684,7 @@ func (lm *loggingMiddleware) RemovePATScopeEntry(ctx context.Context, token, pat
}(time.Now())
return lm.svc.RemovePATScopeEntry(ctx, token, patID, platformEntityType, optionalDomainID, optionalDomainEntityType, operation, entityIDs...)
}

func (lm *loggingMiddleware) ClearPATAllScopeEntry(ctx context.Context, token, patID string) (err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -690,6 +700,7 @@ func (lm *loggingMiddleware) ClearPATAllScopeEntry(ctx context.Context, token, p
}(time.Now())
return lm.svc.ClearPATAllScopeEntry(ctx, token, patID)
}

func (lm *loggingMiddleware) TestCheckPATScopeEntry(ctx context.Context, paToken string, platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) (err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -709,6 +720,7 @@ func (lm *loggingMiddleware) TestCheckPATScopeEntry(ctx context.Context, paToken
}(time.Now())
return lm.svc.TestCheckPATScopeEntry(ctx, paToken, platformEntityType, optionalDomainID, optionalDomainEntityType, operation, entityIDs...)
}

func (lm *loggingMiddleware) IdentifyPAT(ctx context.Context, paToken string) (pa auth.PAT, err error) {
defer func(begin time.Time) {
args := []any{
Expand All @@ -723,6 +735,7 @@ func (lm *loggingMiddleware) IdentifyPAT(ctx context.Context, paToken string) (p
}(time.Now())
return lm.svc.IdentifyPAT(ctx, paToken)
}

func (lm *loggingMiddleware) AuthorizePAT(ctx context.Context, paToken string) (pa auth.PAT, err error) {
defer func(begin time.Time) {
args := []any{
Expand Down
2 changes: 2 additions & 0 deletions auth/api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (ms *metricsMiddleware) ListPATS(ctx context.Context, token string, pm auth
}(time.Now())
return ms.svc.ListPATS(ctx, token, pm)
}

func (ms *metricsMiddleware) DeletePAT(ctx context.Context, token, patID string) error {
defer func(begin time.Time) {
ms.counter.With("method", "delete_pat").Add(1)
Expand All @@ -310,6 +311,7 @@ func (ms *metricsMiddleware) RevokePATSecret(ctx context.Context, token, patID s
}(time.Now())
return ms.svc.RevokePATSecret(ctx, token, patID)
}

func (ms *metricsMiddleware) AddPATScopeEntry(ctx context.Context, token, patID string, platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) (auth.Scope, error) {
defer func(begin time.Time) {
ms.counter.With("method", "add_pat_scope_entry").Add(1)
Expand Down
6 changes: 3 additions & 3 deletions auth/bolt/pat.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/absmach/magistrala/auth"
"github.com/absmach/magistrala/pkg/errors"
repoerr "github.com/absmach/magistrala/pkg/errors/repository"

bolt "go.etcd.io/bbolt"
)

Expand Down Expand Up @@ -161,7 +160,7 @@ func (pr *patRepo) RetrieveAll(ctx context.Context, userID string, pm auth.PATSP

var pats []auth.PAT

var patsPage = auth.PATSPage{
patsPage := auth.PATSPage{
Total: uint64(total),
Limit: pm.Limit,
Offset: pm.Offset,
Expand Down Expand Up @@ -276,7 +275,7 @@ func (pr *patRepo) RemoveScopeEntry(ctx context.Context, userID, patID string, p
if err != nil {
return err
}
for key, _ := range kv {
for key := range kv {
fullKey := []byte(patID + keySeparator + key)
if err := b.Delete(fullKey); err != nil {
return errors.Wrap(repoerr.ErrRemoveEntity, err)
Expand Down Expand Up @@ -430,6 +429,7 @@ func scopeToKeyValue(scope auth.Scope) (map[string][]byte, error) {
}
return kv, nil
}

func scopeEntryToKeyValue(platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) (map[string][]byte, error) {
if len(entityIDs) == 0 {
return nil, repoerr.ErrMalformedEntity
Expand Down
13 changes: 13 additions & 0 deletions auth/events/streams.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,42 +267,55 @@ func (es *eventStore) ListPermissions(ctx context.Context, pr auth.PolicyReq, fi
func (es *eventStore) CreatePAT(ctx context.Context, token, name, description string, duration time.Duration, scope auth.Scope) (auth.PAT, error) {
return es.svc.CreatePAT(ctx, token, name, description, duration, scope)
}

func (es *eventStore) UpdatePATName(ctx context.Context, token, patID, name string) (auth.PAT, error) {
return es.svc.UpdatePATName(ctx, token, patID, name)
}

func (es *eventStore) UpdatePATDescription(ctx context.Context, token, patID, description string) (auth.PAT, error) {
return es.svc.UpdatePATDescription(ctx, token, patID, description)
}

func (es *eventStore) RetrievePAT(ctx context.Context, token, patID string) (auth.PAT, error) {
return es.svc.RetrievePAT(ctx, token, patID)
}

func (es *eventStore) ListPATS(ctx context.Context, token string, pm auth.PATSPageMeta) (auth.PATSPage, error) {
return es.svc.ListPATS(ctx, token, pm)
}

func (es *eventStore) DeletePAT(ctx context.Context, token, patID string) error {
return es.svc.DeletePAT(ctx, token, patID)
}

func (es *eventStore) ResetPATSecret(ctx context.Context, token, patID string, duration time.Duration) (auth.PAT, error) {
return es.svc.ResetPATSecret(ctx, token, patID, duration)
}

func (es *eventStore) RevokePATSecret(ctx context.Context, token, patID string) error {
return es.svc.RevokePATSecret(ctx, token, patID)
}

func (es *eventStore) AddPATScopeEntry(ctx context.Context, token, patID string, platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) (auth.Scope, error) {
return es.svc.AddPATScopeEntry(ctx, token, patID, platformEntityType, optionalDomainID, optionalDomainEntityType, operation, entityIDs...)
}

func (es *eventStore) RemovePATScopeEntry(ctx context.Context, token, patID string, platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) (auth.Scope, error) {
return es.svc.RemovePATScopeEntry(ctx, token, patID, platformEntityType, optionalDomainID, optionalDomainEntityType, operation, entityIDs...)
}

func (es *eventStore) ClearPATAllScopeEntry(ctx context.Context, token, patID string) error {
return es.svc.ClearPATAllScopeEntry(ctx, token, patID)
}

func (es *eventStore) TestCheckPATScopeEntry(ctx context.Context, paToken string, platformEntityType auth.PlatformEntityType, optionalDomainID string, optionalDomainEntityType auth.DomainEntityType, operation auth.OperationType, entityIDs ...string) error {
return es.svc.TestCheckPATScopeEntry(ctx, paToken, platformEntityType, optionalDomainID, optionalDomainEntityType, operation, entityIDs...)
}

func (es *eventStore) IdentifyPAT(ctx context.Context, paToken string) (auth.PAT, error) {
return es.svc.IdentifyPAT(ctx, paToken)
}

func (es *eventStore) AuthorizePAT(ctx context.Context, paToken string) (auth.PAT, error) {
return es.svc.AuthorizePAT(ctx, paToken)
}
5 changes: 2 additions & 3 deletions auth/pat.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import (
"github.com/absmach/magistrala/pkg/errors"
)

var (
errAddEntityToAnyIDs = errors.New("could not add entity id to any ID scope value")
)
var errAddEntityToAnyIDs = errors.New("could not add entity id to any ID scope value")

// Define OperationType.
type OperationType uint32
Expand Down Expand Up @@ -241,6 +239,7 @@ func (s SelectedIDs) Values() []string {
}
return values
}

func (s *SelectedIDs) AddValues(ids ...string) error {
if *s == nil {
*s = make(SelectedIDs)
Expand Down
9 changes: 8 additions & 1 deletion auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ func (svc service) UpdatePATName(ctx context.Context, token, patID, name string)
}
return pat, nil
}

func (svc service) UpdatePATDescription(ctx context.Context, token, patID, description string) (PAT, error) {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand All @@ -1125,6 +1126,7 @@ func (svc service) UpdatePATDescription(ctx context.Context, token, patID, descr
}
return pat, nil
}

func (svc service) RetrievePAT(ctx context.Context, token, patID string) (PAT, error) {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand All @@ -1137,6 +1139,7 @@ func (svc service) RetrievePAT(ctx context.Context, token, patID string) (PAT, e
}
return pat, nil
}

func (svc service) ListPATS(ctx context.Context, token string, pm PATSPageMeta) (PATSPage, error) {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand All @@ -1148,6 +1151,7 @@ func (svc service) ListPATS(ctx context.Context, token string, pm PATSPageMeta)
}
return patsPage, nil
}

func (svc service) DeletePAT(ctx context.Context, token, patID string) error {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand All @@ -1158,6 +1162,7 @@ func (svc service) DeletePAT(ctx context.Context, token, patID string) error {
}
return nil
}

func (svc service) ResetPATSecret(ctx context.Context, token, patID string, duration time.Duration) (PAT, error) {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand All @@ -1174,6 +1179,7 @@ func (svc service) ResetPATSecret(ctx context.Context, token, patID string, dura
}
return pat, nil
}

func (svc service) RevokePATSecret(ctx context.Context, token, patID string) error {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand All @@ -1193,11 +1199,11 @@ func (svc service) AddPATScopeEntry(ctx context.Context, token, patID string, pl
}
scope, err := svc.pats.AddScopeEntry(ctx, key.User, patID, platformEntityType, optionalDomainID, optionalDomainEntityType, operation, entityIDs...)
if err != nil {

return Scope{}, errors.Wrap(errRevokePAT, err)
}
return scope, nil
}

func (svc service) RemovePATScopeEntry(ctx context.Context, token, patID string, platformEntityType PlatformEntityType, optionalDomainID string, optionalDomainEntityType DomainEntityType, operation OperationType, entityIDs ...string) (Scope, error) {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand All @@ -1209,6 +1215,7 @@ func (svc service) RemovePATScopeEntry(ctx context.Context, token, patID string,
}
return scope, nil
}

func (svc service) ClearPATAllScopeEntry(ctx context.Context, token, patID string) error {
key, err := svc.Identify(ctx, token)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/clients/bolt/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/absmach/magistrala/pkg/errors"
"github.com/caarlos0/env/v10"

bolt "go.etcd.io/bbolt"
)

Expand Down Expand Up @@ -44,7 +43,7 @@ func Setup(envPrefix string, initFn func(*bolt.Tx, string) error) (*bolt.DB, err
return SetupDB(envPrefix, initFn)
}

// SetupDB load configuration from environment,
// SetupDB load configuration from environment,.
func SetupDB(envPrefix string, initFn func(*bolt.Tx, string) error) (*bolt.DB, error) {
cfg := Config{}
if err := env.ParseWithOptions(&cfg, env.Options{Prefix: envPrefix}); err != nil {
Expand Down

0 comments on commit b4d46c5

Please sign in to comment.