tsatsubii

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: MIT Imports: 14 Imported by: 0

README

#+TITLE: Tsatsubii Service README

* About
This is meant to become a reusable module for Tsatsubii components. It should
be considered unstable until v1.0.
* Using
Currently, the best way to figure out how to use it is to read the code.

Documentation

Index

Constants

View Source
const (
	// TODO: this should not be hard-coded
	AuthUrl string = "http://auth:8000/sys"
)
View Source
const (
	// TODO: set this from the build system
	SystemSecret = "%*TyBvO0bcBaaAkds93#mJ7&dokdyY0_23gHnqzpMM312"
)

Variables

This section is empty.

Functions

func AddAuthRoute

func AddAuthRoute(
	method string,
	path string,
	key PermissionKey,
	handler gin.HandlerFunc,
)

func AddRoute

func AddRoute(method string, path string, handler gin.HandlerFunc)

func AmqpConnection

func AmqpConnection() *amqp.Connection

func Database

func Database() *gorm.DB

func EnsureEnv

func EnsureEnv(key string)

func GrantPermission

func GrantPermission(roleID uuid.UUID, key PermissionKey)

func HasPermission

func HasPermission(roleID uuid.UUID, key PermissionKey) bool

func Init

func Init()

func Logger

func Logger() *zap.Logger

func PermissionMiddleware

func PermissionMiddleware(key PermissionKey) gin.HandlerFunc

func PublishOnQueue

func PublishOnQueue(queueName string, data []byte) error

func RevokePermission

func RevokePermission(roleID uuid.UUID, key PermissionKey)

func Start

func Start()

func SubscribeToQueue

func SubscribeToQueue(
	queueName string,
	consumerName string,
	handlerFunc func(amqp.Delivery),
) error

func SysAdminRoleID

func SysAdminRoleID() uuid.UUID

func SystemRoleID

func SystemRoleID() uuid.UUID

Types

type ApiCaller

type ApiCaller struct {
	Token        string
	RefreshToken string
}

func (*ApiCaller) Call

func (a *ApiCaller) Call(method string, url string, data []byte) *http.Response

func (*ApiCaller) CallAs

func (a *ApiCaller) CallAs(
	token string,
	method string,
	url string,
	data []byte,
) *http.Response

func (*ApiCaller) Login

func (a *ApiCaller) Login()

func (*ApiCaller) Refresh

func (a *ApiCaller) Refresh()

type IForm

type IForm interface{}

type IModel

type IModel interface {
	Prepare()
	Validate() error
}

type IRepository

type IRepository interface {
	Get(id uuid.UUID)
	Save(form IForm) (IModel, error)
	FindAll() []IModel
}

type InternalError

type InternalError struct{}

func (*InternalError) Error

func (e *InternalError) Error() string

type Model

type Model struct {
	ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey;default:uuid_generate_v4()"`
}

type Permission

type Permission struct {
	Model
	RoleID uuid.UUID     `gorm:"type:uuid;uniqueIndex:permindex" json:"role_id"`
	Key    PermissionKey `gorm:"uniqueIndex:permindex" json:"permission"`
}

type PermissionKey

type PermissionKey string
const (
	PermNone PermissionKey = "none"
)

type Permissions

type Permissions []Permission

type SysResponse

type SysResponse struct {
	Token        string `json:"token"`
	RefreshToken string `json:"refresh_token"`
}

type SystemForm

type SystemForm struct {
	Secret string `json:"secret" binding:"required"`
}

type ValidationError

type ValidationError struct {
	Errors []string
}

func (*ValidationError) AddError

func (e *ValidationError) AddError(err string)

func (*ValidationError) Error

func (e *ValidationError) Error() string

func (*ValidationError) HasErrors

func (e *ValidationError) HasErrors() bool

Jump to

Keyboard shortcuts

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