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 GetTlsConfig() *tls.Config
- func MongoConnection() (*mongo.Client, error)
- func ProjectInitializer(context context.Context, client grpc2.ProjectClient, projectID string, ...) error
- func RandomString(n int) (string, error)
- func SanitizeString(input string) string
- func ValidateOAuthJWT(tokenString string) (bool, error)
- func ValidateStrictPassword(input string) error
- func ValidateStrictUsername(username string) error
- type AppError
Constants ¶
This section is empty.
Variables ¶
var ( 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") 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") EnableInternalTls = getEnvAsBool("ENABLE_INTERNAL_TLS", false) TlsCertPath = os.Getenv("TLS_CERT_PATH") TlSKeyPath = os.Getenv("TLS_KEY_PATH") CaCertPath = os.Getenv("CA_CERT_TLS_PATH") RestPort = os.Getenv("REST_PORT") GrpcPort = os.Getenv("GRPC_PORT") DBName = "auth" UserCollection = "users" ProjectCollection = "project" AuthConfigCollection = "auth-config" RevokedTokenCollection = "revoked-token" ApiTokenCollection = "api-token" UsernameField = "username" ExpiresAtField = "expires_at" PasswordEncryptionCost = 8 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 atleast 8 characters long and atmost 16 characters long and has atleast 1 digit, 1 lowercase alphabet, 1 uppercase alphabet and 1 special character", ErrStrictUsernamePolicyViolation: "The username should be atleast 3 characters long and atmost 16 characters long.", ErrEmptyProjectName: "Project name can't be empty", ErrInvalidRole: "Role is invalid", ErrProjectNotFound: "This project does not exist", ErrInvalidEmail: "Email address is invalid", ErrPasswordNotUpdated: "Please update your default password", ErrOldPassword: "old and new passwords can't be same", }
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, ErrStrictUsernamePolicyViolation: 401, ErrUserNotFound: 400, ErrProjectNotFound: 400, ErrUpdatingAdmin: 400, ErrUserDeactivated: 400, ErrUserAlreadyDeactivated: 400, ErrEmptyProjectName: 400, ErrInvalidRole: 400, ErrInvalidEmail: 400, ErrPasswordNotUpdated: 401, ErrOldPassword: 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 GetTlsConfig ¶
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 RandomString ¶
RandomString generates random strings, can be used to create ids
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 and at most 16 characters long - Input contains at least one special character of these @$!%*?_&# - Input contains at least one digit - Input contains at least one uppercase alphabet - Input contains at least one lowercase alphabet
func ValidateStrictUsername ¶
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") ErrStrictUsernamePolicyViolation AppError = errors.New("username_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") ErrPasswordNotUpdated AppError = errors.New("default password not updated") ErrOldPassword AppError = errors.New("old and new passwords can't be same") )