...

Source file src/edge-infra.dev/pkg/sds/emergencyaccess/types/auth_type.go

Documentation: edge-infra.dev/pkg/sds/emergencyaccess/types

     1  package types
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  type contextUserKey struct{}
     8  
     9  // UserIntoContext allows saving a User struct into the context
    10  func UserIntoContext(ctx context.Context, user User) context.Context {
    11  	return context.WithValue(ctx, contextUserKey{}, user)
    12  }
    13  
    14  // UserFromContext allows extracting the user from the context. Returns false if
    15  // the user has not been saved into the context
    16  func UserFromContext(ctx context.Context) (User, bool) {
    17  	u, ok := ctx.Value(contextUserKey{}).(User)
    18  	return u, ok
    19  }
    20  
    21  // User represents an user attempting to connect to cliservices
    22  type User struct {
    23  	Username string
    24  	Email    string
    25  	Roles    []string
    26  	Banners  []string
    27  }
    28  

View as plain text