Documentation ¶
Overview ¶
Package config will have necessary configuration for the application
Index ¶
- Constants
- Variables
- func AddAsSuperAdmin(ctx *AppContext, userID uint, email string) error
- func CreateInitDatastore(ctx AppContext, name string) error
- func InitAuthState(l Logger) error
- func StartRPC()
- type App
- type AppContext
- type AppInfo
- type AuthenticatedUsers
- func (a *AuthenticatedUsers) DeleteAuthenticatedApp(app App)
- func (a *AuthenticatedUsers) DeleteAuthenticatedUser(user User)
- func (a *AuthenticatedUsers) SetAuthenticatedApp(app App)
- func (a *AuthenticatedUsers) SetAuthenticatedUser(user User)
- func (a *AuthenticatedUsers) SetAuthenticatedUsers(users map[string]User)
- type DbConfig
- type Logger
- type RPCAuth
- type Session
- type User
- type UserInfo
Constants ¶
const ( //DbHost is the environment variable storing the database access url DbHost = "DB_HOST" //DbPort is the environment variable storing the database access port DbPort = "DB_PORT" //DbDatabaseName is the environment variable storing the database name DbDatabaseName = "DB_DATABASE_NAME" //DbUsername is the environment variable storing the database username DbUsername = "DB_USERNAME" //DbPassword is the environment variable storing the database password DbPassword = "DB_PASSWORD" //EnabledDB is the environment variable stating whether the db is enabled or not EnabledDB = "ENABLE_DB" //DevelopmentDatastoreDirectory is the directory location where the data has to be dumped //for the development data store which will be created by admin logs in for the first time DevelopmentDatastoreDirectory = "DEVELOPMENT_DATSTORE_DIRECTORY" )
const ( //NormalUser is a normal user in the system NormalUser = "NormalUser" //ManagerUser is a user with managerial previlege ManagerUser = "ManagerUser" //AdminUser has the admin access in the system AdminUser = "AdminUser" //SuperAdmin has the super admin access in the system SuperAdmin = "SuperAdmin" //RegisteredApp has the previleges a registered app has RegisteredApp = "RegisteredApp" //CuttleApp has all the previleges the platform itself CuttleApp = "CuttleApp" )
const AuthHeaderKey = "auth-token"
AuthHeaderKey is the key to be used to store the auth token in the header
const (
//CuttleAI for string as auth agent for registered apps
CuttleAI = "CUTTLE.AI"
)
Variables ¶
var ( //Port in which the application is being served Port = "8080" //IntPort is the port converted into integer IntPort = 8080 //RPCPort in which the application's rpc server is being served RPCPort = "9090" //RPCIntPort is the rpc port converted into integer RPCIntPort = 9090 //ResponseTimeout of the api to respond in milliseconds ResponseTimeout = time.Duration(12000 * time.Millisecond) //RequestRTimeout of the api request body read timeout in milliseconds RequestRTimeout = time.Duration(40 * time.Millisecond) //ResponseWTimeout of the api response write timeout in milliseconds ResponseWTimeout = time.Duration(10000 * time.Millisecond) //MaxRequests is the maximum no. of requests catered at a given point of time MaxRequests = 2 //RequestCleanUpCheck is the time after which request cleanup check has to happen RequestCleanUpCheck = time.Duration(2 * time.Minute) //FrontendURL is the url with which the frontend of the application can be accessed FrontendURL = "localhost:4200" //DiscoveryURL is the url of the discovery service DiscoveryURL = "127.0.0.1:8500" //DiscoveryToken is the token to communicate with discovery service DiscoveryToken = "" //ServiceDomain is the url on which the service will be available across the platform ServiceDomain = "127.0.0.1" //IsAuthService to make sure that the configuration belongs to auth service. This will prevent cross initialization across services IsAuthService = false )
var AuthServiceID = "Brain-Auth-Service"
AuthServiceID is the auth service id to be used with the discovery service
var AuthServiceRPCID = "Brain-Auth-Service-RPC"
AuthServiceRPCID is the rpc auth service id tpo be used with the discovery service
var IsTest bool
IsTest indicates that the current runtime is for test
var ( //PRODUCTION is the switch to turn on and off the Production environment. //1: On, 0: Off PRODUCTION = 0 )
var SkipVault bool
SkipVault will skip the vault initialization if set true
Functions ¶
func AddAsSuperAdmin ¶
func AddAsSuperAdmin(ctx *AppContext, userID uint, email string) error
AddAsSuperAdmin will add the given user as a super admin
func CreateInitDatastore ¶
func CreateInitDatastore(ctx AppContext, name string) error
CreateInitDatastore creates a datastore with the given name
func InitAuthState ¶
InitAuthState will init the authentication state of the microservice. It will fetch all the authentitcated users from the auth service service
Types ¶
type App ¶
type App struct { //ID of the app ID uint //UID is the unique id of the user UID uuid.UUID //AccessToken is the token with which the user is authenticated AccessToken string //Email associated with the app Email string //Description for the App Description string //Name of the app Name string //UserID is the id of the user who registered the app UserID uint //IsMasterApp indicates whether ther app is from cuttle platform IsMasterApp bool }
App is to store the information about the apps authenticated in the system
type AppContext ¶
type AppContext struct { //Db is the database connection Db *gorm.DB //Log for logging purposes Log Logger //Session is the session associated with the request Session Session }
AppContext contains the
func NewAppContext ¶
func NewAppContext(l Logger) *AppContext
NewAppContext returns an initlized app context
func (*AppContext) ConnectToDB ¶
func (a *AppContext) ConnectToDB() error
ConnectToDB connects the database and updates the Db property of the context as new connection If any error happens in between , it will be returned and connection won't be set in the context
func (AppContext) DiscoveryAddress ¶
func (a AppContext) DiscoveryAddress() string
DiscoveryAddress of thedisocvery service
func (AppContext) DiscoveryToken ¶
func (a AppContext) DiscoveryToken() string
DiscoveryToken of the discovery service
func (AppContext) Logger ¶
func (a AppContext) Logger() bLog.Log
Logger returns the logger of the app context
type AppInfo ¶
type AppInfo struct { gorm.Model //UID is the unique id of the user UID uuid.UUID //AccessToken is the token with which the user is authenticated AccessToken string //Email is the email of the user who registerd the app Email string //Description for the App Description string //Name of the app Name string //UserID of the user who registered the app UserID uint //IsMasterApp indicates the app is from cuttle platform itself IsMasterApp bool }
AppInfo is to model storing the app info of applications registered with the system in database
var MasterAppDetails *AppInfo
MasterAppDetails details has the master app details
func GetAllApps ¶
func GetAllApps(ctx AppContext) (results []AppInfo)
GetAllApps will return the list of all the authenticated apps in the system
func GetMasterApp ¶
func GetMasterApp(ctx AppContext) (*AppInfo, error)
GetMasterApp will return an error if couldn't find the mast app info
func (*AppInfo) Delete ¶
func (a *AppInfo) Delete(ctx AppContext) error
Delete deletes an app's info record in the database
func (*AppInfo) Insert ¶
func (a *AppInfo) Insert(ctx AppContext) error
Insert inserts the user info record to the database
func (*AppInfo) Update ¶
func (a *AppInfo) Update(ctx AppContext) error
Update updates the userinfo model based on the uid -- name and description
type AuthenticatedUsers ¶
type AuthenticatedUsers struct {
// contains filtered or unexported fields
}
AuthenticatedUsers stores the users/apps that are authenticated in the system
func (*AuthenticatedUsers) DeleteAuthenticatedApp ¶
func (a *AuthenticatedUsers) DeleteAuthenticatedApp(app App)
DeleteAuthenticatedApp will delete an app as an authenticated app
func (*AuthenticatedUsers) DeleteAuthenticatedUser ¶
func (a *AuthenticatedUsers) DeleteAuthenticatedUser(user User)
DeleteAuthenticatedUser will delete an user as an authenticated user
func (*AuthenticatedUsers) SetAuthenticatedApp ¶
func (a *AuthenticatedUsers) SetAuthenticatedApp(app App)
SetAuthenticatedApp will set a app as an authenticated app
func (*AuthenticatedUsers) SetAuthenticatedUser ¶
func (a *AuthenticatedUsers) SetAuthenticatedUser(user User)
SetAuthenticatedUser will set a user as an authenticated user
func (*AuthenticatedUsers) SetAuthenticatedUsers ¶
func (a *AuthenticatedUsers) SetAuthenticatedUsers(users map[string]User)
SetAuthenticatedUsers sets the authenticated users in the system
type DbConfig ¶
type DbConfig struct { //Host to be used to connect to the database Host string //Port with which the database can be accessed Port string //Database to connect Database string //Username to access the connection Username string //Password to access the connection Password string }
DbConfig is the database configuration to connect to it
func NewDbConfig ¶
func NewDbConfig() *DbConfig
NewDbConfig will read the db config from the os environment variables and set it in the config
type Logger ¶
type Logger interface { //Info logs the informative logs Info(l ...interface{}) //Debug logs for the debugging logs Debug(l ...interface{}) //Warn logs the warning logs Warn(l ...interface{}) //Error logs the error Error(l ...interface{}) //Fatal logs the fatal issues Fatal(l ...interface{}) //GetID returns the ID of the logger GetID() int }
Logger must be implemented by the logger utilities to be an app logger
type RPCAuth ¶
type RPCAuth struct{}
RPCAuth has the handler for the auth rpc api of the application
func (*RPCAuth) Authenticate ¶
Authenticate will inform the service that the provided user is authenticated
func (*RPCAuth) GetAllAutheticatedUsers ¶
GetAllAutheticatedUsers will return the list of all the authenticated users
type Session ¶
type Session struct { //ID is the id of the session ID string //Authenticated denotes whether the session is authenticated or not Authenticated bool //User with which the app context is associated with User *User }
Session denotes an existing user session
type User ¶
type User struct { //ID is the of the user ID uint //UID is the unique id of the user UID uuid.UUID //AccessToken is the token with which the user is authenticated AccessToken string //AuthAgent has the name of the agent who authenticated the user. Eg. GOOGLE AuthAgent string //Email is the email of the user Email string //UserType is the type of user like NormalUser/Manager/Admin/SuperAdmin UserType string }
User is used by the application to authenticate the users
func GetAutenticatedUser ¶
GetAutenticatedUser will return the autenticated user for a given accesstoken It will return the user if existing. ok parameter will be false if the user is not authenticated for a given access token
func (User) InformAuth ¶
func (u User) InformAuth(appCtx AppContext, loggedIn bool)
InformAuth will info other services that the user has been authenticated
func (User) ToUserInfo ¶
ToUserInfo will convert the user to userinfo instance
type UserInfo ¶
type UserInfo struct { gorm.Model //Email of the user Email string `db:"email"` //Name of the user Name string `db:"name"` //Picture of the user Picture string `db:"picture"` //Registered indicates whether the user has registered with the application Registered bool `db:"registered"` //Subscribed indicates that the user is subscribed to the platform newsletter Subscribed bool `db:"subscribed"` //UserType is the type of user like NormalUser/Manager/Admin/SuperAdmin/RegisteredApp UserType string }
UserInfo is the model used for storing the profile info of the user
func (*UserInfo) AddAsSuperAdmin ¶
func (u *UserInfo) AddAsSuperAdmin(ctx AppContext) error
AddAsSuperAdmin updates the userinfo models user type as super admin
func (UserInfo) Get ¶
func (u UserInfo) Get(ctx AppContext) (result *UserInfo)
Get returns the userinfo model from the database If doesn't exist in the db, the method will return nil
func (*UserInfo) GetApps ¶
func (u *UserInfo) GetApps(ctx AppContext) ([]AppInfo, error)
GetApps will return the apps the user has access to
func (*UserInfo) Insert ¶
func (u *UserInfo) Insert(ctx AppContext) error
Insert inserts the user info record to the database
func (*UserInfo) Update ¶
func (u *UserInfo) Update(ctx AppContext) error
Update updates the userinfo model based on the email