utils

package
v0.0.0-...-bcdb799 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	JwtSecret                    = os.Getenv("JWT_SECRET")
	AdminName                    = os.Getenv("ADMIN_USERNAME")
	AdminPassword                = os.Getenv("ADMIN_PASSWORD")
	DBUrl                        = os.Getenv("DB_SERVER")
	DBUser                       = os.Getenv("DB_USER")
	DBPassword                   = os.Getenv("DB_PASSWORD")
	JWTExpiryDuration            = getEnvAsInt("JWT_EXPIRY_MINS", 1440)
	OAuthJWTExpDuration          = getEnvAsInt("OAUTH_JWT_EXP_MINS", 5)
	OAuthJwtSecret               = os.Getenv("OAUTH_SECRET")
	StrictPasswordPolicy         = getEnvAsBool("STRICT_PASSWORD_POLICY", false)
	DexEnabled                   = getEnvAsBool("DEX_ENABLED", false)
	DexCallBackURL               = os.Getenv("DEX_OAUTH_CALLBACK_URL")
	DexClientID                  = os.Getenv("DEX_OAUTH_CLIENT_ID")
	DexClientSecret              = os.Getenv("DEX_OAUTH_CLIENT_SECRET")
	DexOIDCIssuer                = os.Getenv("OIDC_ISSUER")
	DBName                       = "auth"
	Port                         = ":3000"
	GrpcPort                     = ":3030"
	UserCollection               = "users"
	ProjectCollection            = "project"
	RevokedTokenCollection       = "revoked-token"
	ApiTokenCollection           = "api-token"
	UsernameField                = "username"
	ExpiresAtField               = "expires_at"
	PasswordEncryptionCost       = 15
	DefaultLitmusGqlGrpcEndpoint = "localhost"
	DefaultLitmusGqlGrpcPort     = ":8000"
)
View Source
var ErrorDescriptions = map[AppError]string{
	ErrServerError:                   "The authorization server encountered an unexpected condition that prevented it from fulfilling the request",
	ErrInvalidCredentials:            "Invalid Credentials",
	ErrInvalidRequest:                "The request is missing a required parameter, includes an invalid parameter value, includes a parameter more than once, or is otherwise malformed",
	ErrUnauthorized:                  "The user does not have requested authorization to access this resource",
	ErrUserExists:                    "This username is already assigned to another user",
	ErrStrictPasswordPolicyViolation: "Please ensure the password is 8 characters long and has 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character",
	ErrEmptyProjectName:              "Project name can't be empty",
	ErrInvalidRole:                   "Role is invalid",
	ErrProjectNotFound:               "This project does not exist",
	ErrInvalidEmail:                  "Email address is invalid",
}

ErrorDescriptions holds detailed error description for every AppError

ErrorStatusCodes holds the http status codes for every AppError

Functions

func CreateCollection

func CreateCollection(collectionName string, db *mongo.Database) error

CreateCollection creates a new mongo collection if it does not exist

func CreateIndex

func CreateIndex(collectionName string, field string, db *mongo.Database) error

CreateIndex creates a unique index for the given field in the collectionName

func CreateTTLIndex

func CreateTTLIndex(collectionName string, db *mongo.Database) error

CreateTTLIndex creates a TTL index for the given field in the collectionName

func GenerateOAuthJWT

func GenerateOAuthJWT() (string, error)

func GetProjectGRPCSvcClient

func GetProjectGRPCSvcClient(conn *grpc.ClientConn) (grpc2.ProjectClient, *grpc.ClientConn)

GetProjectGRPCSvcClient returns an RPC client for Project service

func MongoConnection

func MongoConnection() (*mongo.Client, error)

MongoConnection creates a connection to the mongo

func ProjectInitializer

func ProjectInitializer(context context.Context, client grpc2.ProjectClient, projectID string, role string) error

ProjectInitializer initializes a new project with default hub and image registry

func SanitizeString

func SanitizeString(input string) string

SanitizeString trims the string input

func ValidateOAuthJWT

func ValidateOAuthJWT(tokenString string) (bool, error)

func ValidateStrictPassword

func ValidateStrictPassword(input string) error

ValidateStrictPassword represents and checks for the following patterns: - Input is at least 8 characters long - Input contains at least one special character - Input contains at least one digit - Input contains at least one uppercase alphabet - Input contains at least one lowercase alphabet

Types

type AppError

type AppError error

AppError defines general error's throughout the system

var (
	ErrInvalidCredentials            AppError = errors.New("invalid_credentials")
	ErrServerError                   AppError = errors.New("server_error")
	ErrInvalidRequest                AppError = errors.New("invalid_request")
	ErrStrictPasswordPolicyViolation AppError = errors.New("password_policy_violation")
	ErrUnauthorized                  AppError = errors.New("unauthorized")
	ErrUserExists                    AppError = errors.New("user_exists")
	ErrUserNotFound                  AppError = errors.New("user does not exist")
	ErrProjectNotFound               AppError = errors.New("project does not exist")
	ErrWrongPassword                 AppError = errors.New("password doesn't match")
	ErrUpdatingAdmin                 AppError = errors.New("cannot remove admin")
	ErrUserDeactivated               AppError = errors.New("your account has been deactivated")
	ErrUserAlreadyDeactivated        AppError = errors.New("user already deactivated")
	ErrEmptyProjectName              AppError = errors.New("invalid project name")
	ErrInvalidRole                   AppError = errors.New("invalid role")
	ErrInvalidEmail                  AppError = errors.New("invalid email")
)

Jump to

Keyboard shortcuts

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