Documentation ¶
Index ¶
- Constants
- Variables
- func HandleError(err error, message string, args ...interface{})
- func NewAuthHandler(r *gin.Engine, db *gorm.DB)
- func NewUUID() string
- type AuthDataStore
- type AuthHandler
- func (h *AuthHandler) AddOperation(c *gin.Context)
- func (h *AuthHandler) AddPolicy(c *gin.Context)
- func (h *AuthHandler) AddPrincipal(c *gin.Context)
- func (h *AuthHandler) AddResource(c *gin.Context)
- func (h *AuthHandler) CheckPermission(c *gin.Context)
- func (h *AuthHandler) DeleteOperation(c *gin.Context)
- func (h *AuthHandler) DeletePolicy(c *gin.Context)
- func (h *AuthHandler) DeletePrincipal(c *gin.Context)
- func (h *AuthHandler) DeleteResource(c *gin.Context)
- func (h *AuthHandler) FetchOperation(c *gin.Context)
- func (h *AuthHandler) FetchPrincipal(c *gin.Context)
- func (h *AuthHandler) FetchResource(c *gin.Context)
- func (h *AuthHandler) UpdateOperation(c *gin.Context)
- func (h *AuthHandler) UpdatePrincipal(c *gin.Context)
- func (h *AuthHandler) UpdateResource(c *gin.Context)
- type AuthLogic
- func (a AuthLogic) AddOperation(operation Operation) (Operation, error)
- func (a AuthLogic) AddPermission(principalUUID string, resourceUUID string, operationUUID string, ...) (Policy, error)
- func (a AuthLogic) AddPrincipal(principal Principal) (Principal, error)
- func (a AuthLogic) AddResource(resource Resource) (Resource, error)
- func (a AuthLogic) DeleteOperation(UUID string) error
- func (a AuthLogic) DeletePermission(UUID string) error
- func (a AuthLogic) DeletePrincipal(UUID string) error
- func (a AuthLogic) DeleteResource(UUID string) error
- func (a AuthLogic) GetOperation(UUID string) (Operation, error)
- func (a AuthLogic) GetPermission(principalUUID string, resourceUUID string, operationUUID string) (PermissionStatusCode, error)
- func (a AuthLogic) GetPrincipal(UUID string) (Principal, error)
- func (a AuthLogic) GetResource(UUID string) (Resource, error)
- func (a AuthLogic) UpdateOperation(operation Operation) (Operation, error)
- func (a AuthLogic) UpdatePrincipal(principal Principal) (Principal, error)
- func (a AuthLogic) UpdateResource(resource Resource) (Resource, error)
- type AuthOpns
- type Configuration
- type DBconn
- type MemLoad
- type Operation
- type PermissionStatusCode
- type Policy
- type Principal
- type Resource
Constants ¶
const (
// NoRecordFound represents Empty SQL rows
NoRecordFound = "sql: no rows in result set"
)
const (
// ProductionEnv is the env value to denote Production environment
ProductionEnv = "production"
)
Variables ¶
var PermissionStatusCodeIDs = map[string]PermissionStatusCode{ "Granted": Granted, "Denied": Denied, }
PermissionStatusCodeIDs maps string to PermissionStatusCode type
var PermissionStatusCodeNames = map[PermissionStatusCode]string{ Granted: "Granted", Denied: "Denied", }
PermissionStatusCodeNames maps PermissionStatusCode to its string representation
Functions ¶
func HandleError ¶
HandleError will handle error in all places and log the error accordingly
func NewAuthHandler ¶
NewAuthHandler will create a new handler with use case and repo initialization
Types ¶
type AuthDataStore ¶
type AuthDataStore interface { // Principal GetPrincipal(UUID string) (Principal, error) AddPrincipal(principal Principal) (Principal, error) UpdatePrincipal(principal Principal) (Principal, error) DeletePrincipal(UUID string) error // Resource GetResource(UUID string) (Resource, error) AddResource(resource Resource) (Resource, error) UpdateResource(resource Resource) (Resource, error) DeleteResource(UUID string) error // Operation GetOperation(UUID string) (Operation, error) AddOperation(operation Operation) (Operation, error) UpdateOperation(operation Operation) (Operation, error) DeleteOperation(UUID string) error // Policy GetPolicy(UUID string) (Policy, error) GetPolicyForAllMatch(principalUUID string, resourceUUID string, operationUUID string) ([]Policy, error) AddPolicy(policy Policy) (Policy, error) UpdatePolicy(policy Policy) (Policy, error) DeletePolicy(UUID string) error LoadAccess() (map[string](map[string][]string), error) }
AuthDataStore defines operations expected from data storage entity
func NewAuthRepository ¶
func NewAuthRepository(conn *gorm.DB) AuthDataStore
NewAuthRepository To create new Repository with connection to DB
type AuthHandler ¶
type AuthHandler struct {
AuthUsecase AuthOpns
}
AuthHandler will handle all API request to Auth service
func (*AuthHandler) AddOperation ¶
func (h *AuthHandler) AddOperation(c *gin.Context)
AddOperation will add a new operation data to the system
func (*AuthHandler) AddPolicy ¶
func (h *AuthHandler) AddPolicy(c *gin.Context)
AddPolicy will add a new policy data to the system
func (*AuthHandler) AddPrincipal ¶
func (h *AuthHandler) AddPrincipal(c *gin.Context)
AddPrincipal will add a new principal data to the system
func (*AuthHandler) AddResource ¶
func (h *AuthHandler) AddResource(c *gin.Context)
AddResource will add a new resource data to the system
func (*AuthHandler) CheckPermission ¶
func (h *AuthHandler) CheckPermission(c *gin.Context)
CheckPermission will respond with the grant/deny for the principal, resource and operation requested
func (*AuthHandler) DeleteOperation ¶
func (h *AuthHandler) DeleteOperation(c *gin.Context)
DeleteOperation will delete the operation from system for the uuid
func (*AuthHandler) DeletePolicy ¶
func (h *AuthHandler) DeletePolicy(c *gin.Context)
DeletePolicy will delete the policy from system for the uuid
func (*AuthHandler) DeletePrincipal ¶
func (h *AuthHandler) DeletePrincipal(c *gin.Context)
DeletePrincipal will delete the principal from system for the uuid
func (*AuthHandler) DeleteResource ¶
func (h *AuthHandler) DeleteResource(c *gin.Context)
DeleteResource will delete the resource from system for the uuid
func (*AuthHandler) FetchOperation ¶
func (h *AuthHandler) FetchOperation(c *gin.Context)
FetchOperation will respond with the operation data for the uuid requested
func (*AuthHandler) FetchPrincipal ¶
func (h *AuthHandler) FetchPrincipal(c *gin.Context)
FetchPrincipal will respond with the principal data for the uuid requested
func (*AuthHandler) FetchResource ¶
func (h *AuthHandler) FetchResource(c *gin.Context)
FetchResource will respond with the resource data for the uuid requested
func (*AuthHandler) UpdateOperation ¶
func (h *AuthHandler) UpdateOperation(c *gin.Context)
UpdateOperation will update the operation data for the uuid provided
func (*AuthHandler) UpdatePrincipal ¶
func (h *AuthHandler) UpdatePrincipal(c *gin.Context)
UpdatePrincipal will update the principal data for the uuid provided
func (*AuthHandler) UpdateResource ¶
func (h *AuthHandler) UpdateResource(c *gin.Context)
UpdateResource will update the resource data for the uuid provided
type AuthLogic ¶
type AuthLogic struct {
AuthRepo AuthDataStore
}
AuthLogic represents the entity which has connection to dependent modules
func (AuthLogic) AddOperation ¶
AddOperation will add a new operation to the system
func (AuthLogic) AddPermission ¶
func (a AuthLogic) AddPermission(principalUUID string, resourceUUID string, operationUUID string, userName string, permission string) (Policy, error)
AddPermission will add a permission for the principal, operation and resource
func (AuthLogic) AddPrincipal ¶
AddPrincipal will add a new principal from system
func (AuthLogic) AddResource ¶
AddResource will add a new resource to the system
func (AuthLogic) DeleteOperation ¶
DeleteOperation will delete the operation from system
func (AuthLogic) DeletePermission ¶
DeletePermission will remove the permission of the respective UUID
func (AuthLogic) DeletePrincipal ¶
DeletePrincipal will delete the principal from system
func (AuthLogic) DeleteResource ¶
DeleteResource will delete the resource from system
func (AuthLogic) GetOperation ¶
GetOperation will get the operation matching with UUID
func (AuthLogic) GetPermission ¶
func (a AuthLogic) GetPermission(principalUUID string, resourceUUID string, operationUUID string) ( PermissionStatusCode, error)
GetPermission will get the permission for principal, resource and operation UUID
func (AuthLogic) GetPrincipal ¶
GetPrincipal will get the principal matching UUID
func (AuthLogic) GetResource ¶
GetResource will get a the resource matching the UUID
func (AuthLogic) UpdateOperation ¶
UpdateOperation will update the operation from system
func (AuthLogic) UpdatePrincipal ¶
UpdatePrincipal will update the principal in the system
type AuthOpns ¶
type AuthOpns interface { // Principal GetPrincipal(uuid string) (Principal, error) AddPrincipal(principal Principal) (Principal, error) UpdatePrincipal(principal Principal) (Principal, error) DeletePrincipal(uuid string) error // Resource GetResource(uuid string) (Resource, error) AddResource(resource Resource) (Resource, error) UpdateResource(resource Resource) (Resource, error) DeleteResource(uuid string) error // Operation GetOperation(uuid string) (Operation, error) AddOperation(operation Operation) (Operation, error) UpdateOperation(operation Operation) (Operation, error) DeleteOperation(uuid string) error // Permission AddPermission(principalUUID string, resourceUUID string, operationUUID string, userName string, permission string) (Policy, error) DeletePermission(uuid string) error // Verification Policy GetPermission(principalUUID string, resourceUUID string, operationUUID string) ( PermissionStatusCode, error) }
AuthOpns defines operations exposed from domain layer
func NewAuthLogic ¶
NewAuthLogic returns a service initialized with repository.
type Configuration ¶
type Configuration struct { ApplicationPort string Host string Port string Name string User string Password string Type string SSLMode string MaxDBConnections int AcquireConnTimeout int MailAPIKey string BaseURL string BasePort string BaseProtocol string S3Region string S3Endpoint string S3AccessKey string S3SecretKey string S3ReportBucket string S3UserImageBucket string S3UserFileBucket string JwtSecret string DatabaseURL string }
Configuration contains config settings read from env variable
func GetConfig ¶
func GetConfig() *Configuration
GetConfig will return configuration from env variables in singleton pattern
func GetConfiguration ¶
func GetConfiguration() *Configuration
GetConfiguration instantiates Configuration
func (*Configuration) Print ¶
func (c *Configuration) Print()
Print logs current configuration to stdout
type DBconn ¶
DBconn manages the db connection state
func GetDBInstance ¶
func GetDBInstance() *DBconn
GetDBInstance will get us the DB connection using singleton pattern
type MemLoad ¶
MemLoad represents data in memory for permission
func GetMemData ¶
func GetMemData() *MemLoad
GetMemData will get us the Data for permission in memory
type Operation ¶
type Operation struct { UUID string `json:"uuid"` Name string `json:"name"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `json:"deletedAt"` CreatedBy string `json:"createdBy"` UpdatedBy string `json:"updatedBy"` }
Operation is understood to be a specific function that may be performed by a Principal on a Resource
type PermissionStatusCode ¶
type PermissionStatusCode int
PermissionStatusCode is the code used for auth status
const ( // Granted is the state When principal is specifically granted permission // on resource for a operation Granted PermissionStatusCode = iota // Denied is the state When principal is specifically denied permission // on resource for a operation Denied )
func (PermissionStatusCode) String ¶
func (a PermissionStatusCode) String() string
String will convert PermissionStatusCode to string value
type Policy ¶
type Policy struct { UUID string `json:"uuid"` Principal Principal `gorm:"foreignkey:PrincipalUUID;association_foreignkey:UUID"` PrincipalUUID string `json:"principalUUID"` Resouce Resource `gorm:"foreignkey:ResourceUUID;association_foreignkey:UUID"` ResourceUUID string `json:"resourceUUID"` Operation Operation `gorm:"foreignkey:OperationUUID;association_foreignkey:UUID"` OperationUUID string `json:"operationUUID"` Permission string `json:"authStatus"` }
Policy that can be read as declarative statements using Principal, Resource and Operation
type Principal ¶
type Principal struct { UUID string `json:"uuid"` Name string `json:"name"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `json:"deletedAt"` CreatedBy string `json:"createdBy"` UpdatedBy string `json:"updatedBy"` }
Principal represents the identity of a specific user or group of users.
type Resource ¶
type Resource struct { UUID string `json:"uuid"` Name string `json:"name"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time `json:"updatedAt"` DeletedAt *time.Time `json:"deletedAt"` CreatedBy string `json:"createdBy"` UpdatedBy string `json:"updatedBy"` }
Resource is understood to be a specific entity or container upon which permissions may be applied.