Documentation ¶
Index ¶
- Variables
- func CreateCollection(collectionName string, db *mongo.Database) error
- func CreateIndex(collectionName string, field string, db *mongo.Database) error
- func CreateTTLIndex(collectionName string, db *mongo.Database) error
- func GenerateOAuthJWT() (string, error)
- func GetProjectGRPCSvcClient(conn *grpc.ClientConn) (grpc2.ProjectClient, *grpc.ClientConn)
- func MongoConnection() (*mongo.Client, error)
- func ProjectInitializer(context context.Context, client grpc2.ProjectClient, projectID string, ...) error
- func SanitizeString(input string) string
- func ValidateOAuthJWT(tokenString string) (bool, error)
- func ValidateStrictPassword(input string) error
- type AppError
Constants ¶
This section is empty.
Variables ¶
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" )
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
var ErrorStatusCodes = map[AppError]int{ ErrInvalidRequest: 400, ErrInvalidCredentials: 401, ErrServerError: 500, ErrUnauthorized: 401, ErrUserExists: 401, ErrStrictPasswordPolicyViolation: 401, ErrUserNotFound: 400, ErrProjectNotFound: 400, ErrUpdatingAdmin: 400, ErrUserDeactivated: 400, ErrUserAlreadyDeactivated: 400, ErrEmptyProjectName: 400, ErrInvalidRole: 400, ErrInvalidEmail: 400, }
ErrorStatusCodes holds the http status codes for every AppError
Functions ¶
func CreateCollection ¶
CreateCollection creates a new mongo collection if it does not exist
func CreateIndex ¶
CreateIndex creates a unique index for the given field in the collectionName
func CreateTTLIndex ¶
CreateTTLIndex creates a TTL index for the given field in the collectionName
func GenerateOAuthJWT ¶
func GetProjectGRPCSvcClient ¶
func GetProjectGRPCSvcClient(conn *grpc.ClientConn) (grpc2.ProjectClient, *grpc.ClientConn)
GetProjectGRPCSvcClient returns an RPC client for Project service
func MongoConnection ¶
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 ¶
SanitizeString trims the string input
func ValidateOAuthJWT ¶
func ValidateStrictPassword ¶
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") 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") )