Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export functions #8

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ func GetSessionType(ctx context.Context) (proto.SessionType, bool) {
// Account
//

// withAccount adds the account to the context.
func withAccount(ctx context.Context, account string) context.Context {
// WithAccount adds the account to the context.
//
// Deprecated: this will be removed in the future, use Session middleware with a JWT token.
func WithAccount(ctx context.Context, account string) context.Context {
return context.WithValue(ctx, ctxKeyAccount, account)
}

Expand All @@ -60,8 +62,10 @@ func GetAccount(ctx context.Context) (string, bool) {
// User
//

// withUser adds the user to the context.
func withUser(ctx context.Context, user any) context.Context {
// WithUser adds the user to the context.
//
// Deprecated: this will be removed in the future, use Session middleware with a JWT token.
func WithUser(ctx context.Context, user any) context.Context {
return context.WithValue(ctx, ctxKeyUser, user)
}

Expand Down Expand Up @@ -90,8 +94,10 @@ func GetService(ctx context.Context) (string, bool) {
// AccessKey
//

// withAccessKey adds the access key to the context.
func withAccessKey(ctx context.Context, accessKey string) context.Context {
// WithAccessKey adds the access key to the context.
//
// Deprecated: this will be removed in the future, use Session middleware with a JWT token.
func WithAccessKey(ctx context.Context, accessKey string) context.Context {
return context.WithValue(ctx, ctxKeyAccessKey, accessKey)
}

Expand All @@ -105,8 +111,10 @@ func GetAccessKey(ctx context.Context) (string, bool) {
// Project ID
//

// withProjectID adds the project to the context.
func withProjectID(ctx context.Context, project uint64) context.Context {
// WithProjectID adds the project to the context.
//
// Deprecated: this will be removed in the future, use Session middleware with a JWT token.
func WithProjectID(ctx context.Context, project uint64) context.Context {
return context.WithValue(ctx, ctxKeyProjectID, project)
}

Expand Down
8 changes: 4 additions & 4 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func Session(cfg *Options) func(next http.Handler) http.Handler {
ctx = WithService(ctx, serviceClaim)
sessionType = proto.SessionType_Service
case accountClaim != "":
ctx = withAccount(ctx, accountClaim)
ctx = WithAccount(ctx, accountClaim)
sessionType = proto.SessionType_Wallet

if cfg != nil && cfg.UserStore != nil {
Expand All @@ -90,7 +90,7 @@ func Session(cfg *Options) func(next http.Handler) http.Handler {
}

if user != nil {
ctx = withUser(ctx, user)
ctx = WithUser(ctx, user)

sessionType = proto.SessionType_User
if isAdmin {
Expand All @@ -105,14 +105,14 @@ func Session(cfg *Options) func(next http.Handler) http.Handler {

if projectClaim > 0 {
projectID := uint64(projectClaim)
ctx = withProjectID(ctx, projectID)
ctx = WithProjectID(ctx, projectID)
sessionType = proto.SessionType_Project
}
}
}

if accessKey != "" && sessionType < proto.SessionType_Admin {
ctx = withAccessKey(ctx, accessKey)
ctx = WithAccessKey(ctx, accessKey)
sessionType = max(sessionType, proto.SessionType_AccessKey)
}

Expand Down
Loading