app

package
v0.0.0-...-81cff5b Latest Latest
Warning

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

Go to latest
Published: May 15, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoRecordFound  represents Empty SQL rows
	NoRecordFound = "sql: no rows in result set"
)
View Source
const (
	// ProductionEnv is the env value to denote Production environment
	ProductionEnv = "production"
)

Variables

View Source
var PermissionStatusCodeIDs = map[string]PermissionStatusCode{
	"Granted": Granted,
	"Denied":  Denied,
}

PermissionStatusCodeIDs maps string to PermissionStatusCode type

View Source
var PermissionStatusCodeNames = map[PermissionStatusCode]string{
	Granted: "Granted",
	Denied:  "Denied",
}

PermissionStatusCodeNames maps PermissionStatusCode to its string representation

Functions

func HandleError

func HandleError(err error, message string, args ...interface{})

HandleError will handle error in all places and log the error accordingly

func NewAuthHandler

func NewAuthHandler(r *gin.Engine, db *gorm.DB)

NewAuthHandler will create a new handler with use case and repo initialization

func NewUUID

func NewUUID() string

NewUUID will generate a new UUID and return back the value as string

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

func (a AuthLogic) AddOperation(operation Operation) (Operation, error)

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

func (a AuthLogic) AddPrincipal(principal Principal) (Principal, error)

AddPrincipal will add a new principal from system

func (AuthLogic) AddResource

func (a AuthLogic) AddResource(resource Resource) (Resource, error)

AddResource will add a new resource to the system

func (AuthLogic) DeleteOperation

func (a AuthLogic) DeleteOperation(UUID string) error

DeleteOperation will delete the operation from system

func (AuthLogic) DeletePermission

func (a AuthLogic) DeletePermission(UUID string) error

DeletePermission will remove the permission of the respective UUID

func (AuthLogic) DeletePrincipal

func (a AuthLogic) DeletePrincipal(UUID string) error

DeletePrincipal will delete the principal from system

func (AuthLogic) DeleteResource

func (a AuthLogic) DeleteResource(UUID string) error

DeleteResource will delete the resource from system

func (AuthLogic) GetOperation

func (a AuthLogic) GetOperation(UUID string) (Operation, error)

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

func (a AuthLogic) GetPrincipal(UUID string) (Principal, error)

GetPrincipal will get the principal matching UUID

func (AuthLogic) GetResource

func (a AuthLogic) GetResource(UUID string) (Resource, error)

GetResource will get a the resource matching the UUID

func (AuthLogic) UpdateOperation

func (a AuthLogic) UpdateOperation(operation Operation) (Operation, error)

UpdateOperation will update the operation from system

func (AuthLogic) UpdatePrincipal

func (a AuthLogic) UpdatePrincipal(principal Principal) (Principal, error)

UpdatePrincipal will update the principal in the system

func (AuthLogic) UpdateResource

func (a AuthLogic) UpdateResource(resource Resource) (Resource, error)

UpdateResource will update the resource from 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

func NewAuthLogic(db *gorm.DB) AuthOpns

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

type DBconn struct {
	DB *gorm.DB
}

DBconn manages the db connection state

func GetDBInstance

func GetDBInstance() *DBconn

GetDBInstance will get us the DB connection using singleton pattern

type MemLoad

type MemLoad struct {
	OperationAccess map[string]map[string][]string
}

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.

Jump to

Keyboard shortcuts

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