remove pointer on ctxData

This commit is contained in:
Livio Amstutz 2020-03-30 10:06:48 +02:00
parent 501d453822
commit e5e39b3a6a
2 changed files with 6 additions and 16 deletions

View File

@ -2,7 +2,6 @@ package auth
import ( import (
"context" "context"
"time"
"github.com/caos/logging" "github.com/caos/logging"
) )
@ -43,24 +42,15 @@ func VerifyTokenAndWriteCtxData(ctx context.Context, token, orgID string, t Toke
projectID, err := t.GetProjectIDByClientID(ctx, clientID) projectID, err := t.GetProjectIDByClientID(ctx, clientID)
logging.LogWithFields("AUTH-GfAoV", "clientID", clientID).OnError(err).Warn("could not read projectid by clientid") logging.LogWithFields("AUTH-GfAoV", "clientID", clientID).OnError(err).Warn("could not read projectid by clientid")
return context.WithValue(ctx, CtxKeyData{}, &CtxData{UserID: userID, OrgID: orgID, ProjectID: projectID, AgentID: agentID}), nil return context.WithValue(ctx, CtxKeyData{}, CtxData{UserID: userID, OrgID: orgID, ProjectID: projectID, AgentID: agentID}), nil
} }
func GetCtxData(ctx context.Context) CtxData { func GetCtxData(ctx context.Context) CtxData {
if data := ctx.Value(CtxKeyData{}); data != nil { ctxData, _ := ctx.Value(CtxKeyData{}).(CtxData)
ctxData, ok := data.(*CtxData) return ctxData
if ok {
return *ctxData
}
time.Now()
}
return CtxData{}
} }
func GetPermissionsFromCtx(ctx context.Context) []string { func GetPermissionsFromCtx(ctx context.Context) []string {
if data := ctx.Value(CtxKeyPermissions{}); data != nil { ctxPermission, _ := ctx.Value(CtxKeyPermissions{}).([]string)
ctxPermission, _ := data.([]string)
return ctxPermission return ctxPermission
} }
return nil
}

View File

@ -8,7 +8,7 @@ import (
) )
func getTestCtx(userID, orgID string) context.Context { func getTestCtx(userID, orgID string) context.Context {
return context.WithValue(context.Background(), CtxKeyData{}, &CtxData{UserID: userID, OrgID: orgID}) return context.WithValue(context.Background(), CtxKeyData{}, CtxData{UserID: userID, OrgID: orgID})
} }
type testVerifier struct { type testVerifier struct {