util

package
v0.0.0-...-1f6a4c1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XRHIDENTITY      = "x-rh-identity"
	LAST_VISITED_MAX = 10
	IDENTITY_CTX_KEY = "identity"
	USER_CTX_KEY     = "user"
	GET_ALL_PARAM    = "getAll"   // Used for searching ALL favorited pages
	DEFAULT_PARAM    = "archived" // Used as default value for active favorited pages
	FAVORITE_PARAM   = "favorite"
)
View Source
const ProjectName = "chrome-service-backend"

Variables

View Source
var (
	ErrNotAuthorized = errors.New("not authorized")
)

Functions

func InitUserIdentitiesCache

func InitUserIdentitiesCache()

func LoadEnv

func LoadEnv() error

func ParseXRHIdentityHeader

func ParseXRHIdentityHeader(identityHeader string) (*identity.XRHID, error)

Types

type CacheEntry

type CacheEntry struct {
	ExpireAt time.Time
	Identity models.UserIdentity
}

type DecodedToken

type DecodedToken struct {
	UserId        string `json:"user_id"`
	OrgId         string `json:"org_id"`
	AccountNumber string `json:"account_number"`
	Username      string `json:"username"`
}

func ParseJWTToken

func ParseJWTToken(tokenString string) (DecodedToken, error)

Adaptation of chrome UI token parsing as we can't yse the JWT decode, because we do not have the decode key

type EntityResponse

type EntityResponse[T interface{}] struct {
	Data T `json:"data"`
}

type ErrorResponse

type ErrorResponse struct {
	Errors []string `json:"errors"`
}

type ListMeta

type ListMeta struct {
	Count  int `json:"count,omitempty"`
	Total  int `json:"total,omitempty"`
	Limit  int `json:"limit,omitempty"`
	Offset int `json:"offset,omitempty"`
}

type ListResponse

type ListResponse[T interface{}] struct {
	Data []T      `json:"data"`
	Meta ListMeta `json:"meta"`
}

type UserIdentityCache

type UserIdentityCache struct {
	Identities map[string]CacheEntry
	sync.Mutex
}
var UsersCache *UserIdentityCache

func (*UserIdentityCache) Delete

func (c *UserIdentityCache) Delete(accountId string)

func (*UserIdentityCache) Get

func (c *UserIdentityCache) Get(accountId string) (models.UserIdentity, bool)

func (*UserIdentityCache) Set

func (c *UserIdentityCache) Set(accountId string, identity models.UserIdentity)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL