utils

package
v0.0.0-...-0888c38 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateJWTForAPIUser

func GenerateJWTForAPIUser(userID string, orgID string, expiresAt time.Time, audience string) *jwtpb.JWTClaims

GenerateJWTForAPIUser creates a protobuf claims for the api user.

func GenerateJWTForCluster

func GenerateJWTForCluster(clusterID string, audience string) *jwtpb.JWTClaims

GenerateJWTForCluster creates a protobuf claims for the given cluster.

func GenerateJWTForService

func GenerateJWTForService(serviceID string, audience string) *jwtpb.JWTClaims

GenerateJWTForService creates a protobuf claims for the given service.

func GenerateJWTForUser

func GenerateJWTForUser(userID string, orgID string, email string, expiresAt time.Time, audience string) *jwtpb.JWTClaims

GenerateJWTForUser creates a protobuf claims for the given user.

func GetClusterID

func GetClusterID(t jwt.Token) string

GetClusterID fetches the ClusterID from the custom claims.

func GetEmail

func GetEmail(t jwt.Token) string

GetEmail fetches the Email from the custom claims.

func GetIsAPIUser

func GetIsAPIUser(t jwt.Token) bool

GetIsAPIUser fetches the IsAPIUser from the custom claims.

func GetOrgID

func GetOrgID(t jwt.Token) string

GetOrgID fetches the OrgID from the custom claims.

func GetScopes

func GetScopes(t jwt.Token) []string

GetScopes fetches the Scopes from the custom claims.

func GetServiceID

func GetServiceID(t jwt.Token) string

GetServiceID fetches the ServiceID from the custom claims.

func GetUserID

func GetUserID(t jwt.Token) string

GetUserID fetches the UserID from the custom claims.

func HasClusterClaims

func HasClusterClaims(t jwt.Token) bool

HasClusterClaims checks if the custom claims include ClusterClaims.

func HasServiceClaims

func HasServiceClaims(t jwt.Token) bool

HasServiceClaims checks if the custom claims include ServiceClaims.

func HasUserClaims

func HasUserClaims(t jwt.Token) bool

HasUserClaims checks if the custom claims include UserClaims.

func ParseToken

func ParseToken(tokenString string, signingKey string, audience string) (jwt.Token, error)

ParseToken parses the claim and validates that it was signed given signing key, and has the expected audience.

func ProtoToToken

func ProtoToToken(pb *jwtpb.JWTClaims) (jwt.Token, error)

ProtoToToken maps protobuf claims to map claims.

func SignJWTClaims

func SignJWTClaims(claims *jwtpb.JWTClaims, signingKey string) (string, error)

SignJWTClaims signs the claim using the given signing key.

func SignToken

func SignToken(token jwt.Token, signingKey string) (string, error)

SignToken signs the token using the given signing key.

func TokenToProto

func TokenToProto(token jwt.Token) (*jwtpb.JWTClaims, error)

TokenToProto tkes a Token and converts it to a protobuf.

Types

type AtomicError

type AtomicError struct {
	// contains filtered or unexported fields
}

AtomicError allows atomic storing and loading of an error interface.

func (*AtomicError) Load

func (e *AtomicError) Load() error

Load atomically loads the currently stored error. Note that if Load() is called before Store() it returns nil.

func (*AtomicError) Store

func (e *AtomicError) Store(err error)

Store atomically stores a new error in the AtomicError.

type ClaimType

type ClaimType int

ClaimType represents the type of claims we allow in our system.

const (
	// UnknownClaimType is an unknown type.
	UnknownClaimType ClaimType = iota
	// UserClaimType is a claim for a user.
	UserClaimType
	// ServiceClaimType is a claim for a service.
	ServiceClaimType
	// ClusterClaimType is a claim type for a cluster.
	ClusterClaimType
)

func GetClaimsType

func GetClaimsType(c *jwtpb.JWTClaims) ClaimType

GetClaimsType gets the type of the given claim.

Jump to

Keyboard shortcuts

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