ensweb

package
v0.0.18 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: GPL-3.0 Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserEntity     string = "UserEntity"
	RoleEntity     string = "RoleEntity"
	UserRoleEntity string = "UserRoleEntity"
	TenantEntity   string = "TenantEntity"
	DefaultEntity  string = "DefaultEntity"
)
View Source
const (
	DefaultTokenHdr  string = "X-Token"
	DefaultRawErrHdr string = "X-Raw"
)
View Source
const (
	StatusSuccess string = "Success"
	StatusFailed  string = "Failed"
	StatusError   string = "Error"
	StatusBusy    string = "Busy"
	StatusNone    string = "None"
)
View Source
const (
	APIKeyHeader string = "X-API-Key"
)
View Source
const DefaultTimeout = 60 * time.Second
View Source
const (
	JSONContentType string = "application/json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthFunc

type AuthFunc func(req *Request) bool

type Base

type Base struct {
	ID                   uuid.UUID `gorm:"column:Id;primary_key;type:uniqueidentifier"`
	CreationTime         time.Time `gorm:"column:CreationTime;not null"`
	CreatorID            uuid.UUID `gorm:"column:CreatorId;type:uniqueidentifier"`
	LastModificationTime time.Time `gorm:"column:LastModificationTime"`
	LastModifierID       uuid.UUID `gorm:"column:LastModifierId;type:uniqueidentifier"`
	TenantID             uuid.UUID `gorm:"column:TenantId;type:uniqueidentifier"`
}

Base contains common columns for all tables.

func (*Base) BeforeCreate

func (b *Base) BeforeCreate(scope *gorm.Scope) error

BeforeCreate will set a UUID rather than numeric ID.

func (*Base) BeforeSave

func (b *Base) BeforeSave(scope *gorm.Scope) error

BeforeCreate will set a UUID rather than numeric ID.

func (*Base) BeforeUpdate

func (b *Base) BeforeUpdate(scope *gorm.Scope) error

BeforeCreate will set a UUID rather than numeric ID.

type BasicToken

type BasicToken struct {
	UserName string `json:"username"`
	UserID   string `json:"user_id"`
	Role     string `json:"role"`
	jwt.StandardClaims
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client : Client struct

func NewClient

func NewClient(config *config.Config, log logger.Logger, options ...ClientOptions) (Client, error)

NewClient : Create new client handle

func (*Client) Do

func (c *Client) Do(req *http.Request, timeout ...time.Duration) (*http.Response, error)

func (*Client) GetCookies

func (c *Client) GetCookies() []*http.Cookie

func (*Client) GetToken

func (c *Client) GetToken() string

func (*Client) JSONRequest

func (c *Client) JSONRequest(method string, requestPath string, model interface{}) (*http.Request, error)

func (*Client) JSONRequestForExplorer

func (c *Client) JSONRequestForExplorer(method string, requestPath string, model interface{}, explorerURL string) (*http.Request, error)

func (*Client) MultiFormRequest

func (c *Client) MultiFormRequest(method string, requestPath string, field map[string]string, files map[string]string) (*http.Request, error)

func (*Client) ParseMutilform

func (c *Client) ParseMutilform(resp *http.Response, dirPath string) ([]string, map[string]string, error)

func (*Client) SetAuthorization

func (c *Client) SetAuthorization(req *http.Request, token string)

func (*Client) SetCookies

func (c *Client) SetCookies(cookies []*http.Cookie)

func (*Client) SetToken

func (c *Client) SetToken(token string) error

type ClientOptions

type ClientOptions = func(*Client) error

func SetClientDefaultTimeout

func SetClientDefaultTimeout(timeout time.Duration) ClientOptions

func SetClientTokenHelper

func SetClientTokenHelper(filename string) ClientOptions

type ClientToken

type ClientToken struct {
	Token          string
	BearerToken    bool
	APIKeyVerified bool
	Verified       bool
	Model          interface{}
}

type Connection

type Connection struct {
	// RemoteAddr is the network address that sent the request.
	RemoteAddr string `json:"remote_addr"`

	// ConnState is the TLS connection state if applicable.
	ConnState *tls.ConnectionState `sentinel:""`
}

Connection represents the connection information for a request.

type CookiesType

type CookiesType map[interface{}]interface{}

type Entity

type Entity struct {
	EntityName  string
	EntityModel interface{}
}

type EntityConfig

type EntityConfig struct {
	DefaultTenantName    string
	DefaultAdminName     string
	DefaultAdminPassword string
	TenantTableName      string
	UserTableName        string
	RoleTableName        string
	UserRoleTableName    string
}

type ErrMessage

type ErrMessage struct {
	Error string `json:"Message"`
}

ErrMessage example

func JSONDecodeErr

func JSONDecodeErr(resp *http.Response) (*ErrMessage, error)

type GetTenantCBFunc

type GetTenantCBFunc func(tenantName string) uuid.UUID

type HandlerFunc

type HandlerFunc func(req *Request) *Result

type InternalTokenHelper

type InternalTokenHelper struct {
	// contains filtered or unexported fields
}

InternalTokenHelper fulfills the TokenHelper interface when no external token-helper is configured, and avoids shelling out

func NewInternalTokenHelper

func NewInternalTokenHelper(filename string) (*InternalTokenHelper, error)

func (*InternalTokenHelper) Erase

func (i *InternalTokenHelper) Erase() error

Erase erases the value of the token

func (*InternalTokenHelper) Get

func (i *InternalTokenHelper) Get() (string, error)

Get gets the value of the stored token, if any

func (*InternalTokenHelper) Path

func (i *InternalTokenHelper) Path() string

func (*InternalTokenHelper) Store

func (i *InternalTokenHelper) Store(input string) error

Store stores the value of the token to the file. We always overwrite any existing file atomically to ensure that ownership and permissions are set appropriately.

type LoginRequest

type LoginRequest struct {
	UserName string `json:"userName"`
	Password string `json:"password"`
}

type LoginResponse

type LoginResponse struct {
	Status  bool   `json:"status"`
	Message string `json:"message"`
	Token   string `json:"token"`
	Role    string `json:"role"`
	User    *User  `json:"user"`
}

type Operation

type Operation string

Operation is an enum that is used to specify the type of request being made

type Request

type Request struct {
	ID          string
	Method      string
	Path        string
	TimeIn      time.Time
	ClientToken ClientToken
	Connection  *Connection
	Data        map[string]interface{} `json:"data" structs:"data" mapstructure:"data"`
	Model       interface{}
	Headers     http.Header
	TenantID    uuid.UUID
	// contains filtered or unexported fields
}

func (*Request) GetHTTPRequest

func (req *Request) GetHTTPRequest() *http.Request

func (*Request) GetHTTPWritter

func (req *Request) GetHTTPWritter() http.ResponseWriter

type Result

type Result struct {
	Status int
	Done   bool
}

type Role

type Role struct {
	ID               uuid.UUID `gorm:"column:Id;primary_key;type:uniqueidentifier"`
	ConcurrencyStamp string    `gorm:"column:ConcurrencyStamp"`
	ExtraProperties  string    `gorm:"column:ExtraProperties"`
	TenantID         uuid.UUID `gorm:"column:TenantId;type:uniqueidentifier"`
	Name             string    `gorm:"column:Name;not null" json:"Name"`
	NormalizedName   string    `gorm:"column:NormalizedName;not null" json:"NormalizedName"`
	IsDefault        bool      `gorm:"column:IsDefault;type:bit;not null"`
	IsStatic         bool      `gorm:"column:IsStatic;type:bit;not null"`
	IsPublic         bool      `gorm:"column:IsPublic;type:bit;not null"`
	DeleterUserID    int64     `gorm:"column:DeleterUserID"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server defines server

func NewServer

func NewServer(cfg *config.Config, serverCfg *ServerConfig, log logger.Logger, options ...ServerOptions) (Server, error)

NewServer create new server instances

func (*Server) APIKeyAuthHandle

func (s *Server) APIKeyAuthHandle(hf HandlerFunc, ef HandlerFunc) HandlerFunc

func (*Server) AddEntity

func (s *Server) AddEntity(entitytName string, entityModel interface{}) error

func (*Server) AddExtension

func (s *Server) AddExtension(fileExtension string, fileType string)

func (*Server) AddForienKey

func (s *Server) AddForienKey(entitytName string, entityModel interface{}, column string, forienEntityName string, forienEntityColumn string) error

DropTable drop the table

func (*Server) AddPrefixRoute

func (s *Server) AddPrefixRoute(prefix string, dirpath string, hf HandlerFunc)

func (*Server) AddRoute

func (s *Server) AddRoute(path string, method string, hf HandlerFunc)

func (*Server) BasicAuthHandle

func (s *Server) BasicAuthHandle(claims jwt.Claims, hf HandlerFunc, af AuthFunc, ef HandlerFunc) HandlerFunc

func (*Server) CreateEntity

func (s *Server) CreateEntity(entitytName string, value interface{}) error

func (*Server) CreateRole

func (s *Server) CreateRole(r *Role) error

CreateRole will create role

func (*Server) CreateSessionStore

func (s *Server) CreateSessionStore(name string, secret string, option sessions.Options)

func (*Server) CreateTenant

func (s *Server) CreateTenant(t *Tenant) error

CreateTenant will create tenant

func (*Server) CreateUser

func (s *Server) CreateUser(u *User) error

func (*Server) CreateUserRole

func (s *Server) CreateUserRole(ur *UserRole) error

CreateUserRole will create user role

func (*Server) DeleteEntity

func (s *Server) DeleteEntity(entitytName string, tenantID interface{}, format string, item interface{}, value ...interface{}) error

func (*Server) DeleteUser

func (s *Server) DeleteUser(tenantID interface{}, id uuid.UUID) error

func (*Server) EmptySessionCookies

func (s *Server) EmptySessionCookies(req *Request, sessionName string) error

func (*Server) EnableSWagger

func (s *Server) EnableSWagger(url string)

func (*Server) GenerateJWTToken

func (s *Server) GenerateJWTToken(claims jwt.Claims) string

GenerateJWTToken will generate JWT token

func (*Server) GetDB

func (s *Server) GetDB() *adapter.Adapter

GetDB will return DB

func (*Server) GetEntity

func (s *Server) GetEntity(entitytName string, tenantID interface{}, format string, item interface{}, value ...interface{}) error

func (*Server) GetQuerry

func (s *Server) GetQuerry(req *Request, key string) string

func (*Server) GetReqHeader

func (s *Server) GetReqHeader(req *Request, key string) string

func (*Server) GetRole

func (s *Server) GetRole(name string) (*Role, error)

GetRole will get role

func (*Server) GetRouteVar

func (s *Server) GetRouteVar(req *Request, key string) string

func (*Server) GetServerURL

func (s *Server) GetServerURL() string

GetDB will return DB

func (*Server) GetSessionCookies

func (s *Server) GetSessionCookies(req *Request, sessionName string, key interface{}) interface{}

func (*Server) GetTenant

func (s *Server) GetTenant(name string) (*Tenant, error)

GetTenant will get tenant

func (*Server) GetUser

func (s *Server) GetUser(tenantID interface{}, userName string) (*User, error)

func (*Server) GetUserByID

func (s *Server) GetUserByID(tenantID interface{}, id uuid.UUID) (*User, error)

func (*Server) GetUserRole

func (s *Server) GetUserRole(u *User) ([]UserRole, error)

GetUserRole will get user role

func (*Server) GetUsers

func (s *Server) GetUsers(tenantID interface{}, format string, value ...interface{}) ([]User, error)

func (*Server) IsFORM

func (s *Server) IsFORM(req *Request) (bool, error)

func (*Server) LoginUser

func (s *Server) LoginUser(tenantID interface{}, req *LoginRequest) *LoginResponse

func (*Server) ParseFORM

func (s *Server) ParseFORM(req *Request) (map[string]interface{}, error)

func (*Server) ParseJSON

func (s *Server) ParseJSON(req *Request, model interface{}) error

func (*Server) ParseMultiPartForm

func (s *Server) ParseMultiPartForm(req *Request, dirPath string) ([]string, map[string][]string, error)

func (*Server) ParseMultiPartFormFile

func (s *Server) ParseMultiPartFormFile(req *Request, paramName string) (*os.File, *multipart.FileHeader, error)

func (*Server) Redirect

func (s *Server) Redirect(req *Request, url string) *Result

func (*Server) RenderFile

func (s *Server) RenderFile(req *Request, fileName string, attachment bool) *Result

func (*Server) RenderImage

func (s *Server) RenderImage(req *Request, contentType string, img string) *Result

func (*Server) RenderJSON

func (s *Server) RenderJSON(req *Request, model interface{}, status int) *Result

func (*Server) RenderJSONError

func (s *Server) RenderJSONError(req *Request, status int, errMsg string, logMsg string, args ...interface{}) *Result

func (*Server) RenderJSONStatus

func (s *Server) RenderJSONStatus(req *Request, status string, message string, logMsg string, args ...interface{}) *Result

func (*Server) RenderMultiFormFile

func (s *Server) RenderMultiFormFile(req *Request, field map[string]string, fileName map[string]string) *Result

func (*Server) RenderTemplate

func (s *Server) RenderTemplate(req *Request, renderPath string, model interface{}, status int) *Result

func (*Server) SaveEntity

func (s *Server) SaveEntity(entitytName string, tenantID interface{}, item interface{}, format string, value ...interface{}) error

func (*Server) ServerStatic

func (s *Server) ServerStatic(req *Request) *Result

func (*Server) SessionAuthHandle

func (s *Server) SessionAuthHandle(claims jwt.Claims, sessionName string, sessionKey string, hf HandlerFunc, ef HandlerFunc) HandlerFunc

func (*Server) SetAPIKey

func (s *Server) SetAPIKey(apiKey string)

func (*Server) SetAuditLog

func (s *Server) SetAuditLog(log logger.Logger)

func (*Server) SetDebugMode

func (s *Server) SetDebugMode()

func (*Server) SetDefaultTenant

func (s *Server) SetDefaultTenant(id uuid.UUID)

func (*Server) SetSessionCookies

func (s *Server) SetSessionCookies(req *Request, sessionName string, key interface{}, value interface{}) error

func (*Server) SetShutdown

func (s *Server) SetShutdown(sf ShutdownFunc)

func (*Server) SetStatic

func (s *Server) SetStatic(prefix string, dir string)

func (*Server) SetTenantCBFunc

func (s *Server) SetTenantCBFunc(tcb GetTenantCBFunc)

func (*Server) SetupEntity

func (s *Server) SetupEntity(cfg EntityConfig) error

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown attempts to gracefully shutdown the underlying HTTP server.

func (*Server) Start

func (s *Server) Start() error

Start starts the underlying HTTP server

func (*Server) UpdateEntity

func (s *Server) UpdateEntity(entitytName string, tenantID interface{}, item interface{}, format string, value ...interface{}) error

func (*Server) UpdateUser

func (s *Server) UpdateUser(u *User) error

func (*Server) ValidateJWTToken

func (s *Server) ValidateJWTToken(token string, claims jwt.Claims) error

ValidateJWTToken verify token

type ServerConfig

type ServerConfig struct {
	AuthHeaderName   string
	RawErrHeaderName string
}

type ServerOptions

type ServerOptions = func(*Server) error

func SetServerTimeout

func SetServerTimeout(timeout time.Duration) ServerOptions

type SessionStore

type SessionStore struct {
	// contains filtered or unexported fields
}

type ShutdownFunc

type ShutdownFunc func() error

type StatusMsg

type StatusMsg struct {
	Status  string `json:"Status"`
	Message string `json:"Message"`
}

type Tenant

type Tenant struct {
	Base
	ExtraProperties  string    `gorm:"column:ExtraProperties"`
	ConcurrencyStamp string    `gorm:"column:ConcurrencyStamp"`
	IsDeleted        bool      `gorm:"column:IsDeleted;not null;type:bit"`
	DeleterID        uuid.UUID `gorm:"column:DeleterId;type:uniqueidentifier"`
	DeletionTime     time.Time `gorm:"column:DeletionTime"`
	Name             string    `gorm:"column:Name;not null" json:"Name"`
	EditionID        uuid.UUID `gorm:"column:EditionId;type:uniqueidentifier"`
}

Tenant List

type TokenHelper

type TokenHelper interface {
	Path() string
	Erase() error
	Get() (string, error)
	Store(string) error
}

type TokenType

type TokenType uint8
const (
	// TokenTypeDefault means "use the default, if any, that is currently set
	// on the mount". If not set, results in a Service token.
	TokenTypeDefault TokenType = iota

	// TokenTypeService is a "normal" Vault token for long-lived services
	TokenTypeService

	// TokenTypeBatch is a batch token
	TokenTypeBatch
)

func (TokenType) String

func (t TokenType) String() string

type User

type User struct {
	Base
	ConcurrencyStamp     string    `gorm:"column:ConcurrencyStamp"`
	IsDeleted            bool      `gorm:"column:IsDeleted;not null;type:bit"`
	DeleterID            uuid.UUID `gorm:"column:DeleterId;type:uniqueidentifier"`
	DeletionTime         time.Time `gorm:"column:DeletionTime"`
	UserName             string    `gorm:"column:UserName;not null" json:"UserName"`
	NormalizedUserName   string    `gorm:"column:NormalizedUserName;not null" json:"NormalizedUserName"`
	Name                 string    `gorm:"column:Name;size:64;not null" json:"Name"`
	Surname              string    `gorm:"column:Surname;size:64;not null" json:"Surname"`
	Email                string    `gorm:"column:Email;size:256;not null" json:"Email"`
	NormalizedEmail      string    `gorm:"column:NormalizedEmail;size:256;not null" json:"NormalizedEmail"`
	EmailConfirmed       bool      `gorm:"column:EmailConfirmed;not null;type:bit"`
	PasswordHash         string    `gorm:"column:PasswordHash;not null" json:"PasswordHash"`
	SecurityStamp        string    `gorm:"column:SecurityStamp"`
	IsExternal           bool      `gorm:"column:IsExternal;type:bit"`
	PhoneNumber          string    `gorm:"column:PhoneNumber"`
	PhoneNumberConfirmed bool      `gorm:"column:PhoneNumberConfirmed;not null;type:bit"`
	TwoFactorEnabled     bool      `gorm:"column:TwoFactorEnabled;not null;type:bit"`
	LockoutEnd           time.Time `gorm:"column:LockoutEnd"`
	LockoutEnabled       bool      `gorm:"column:LockoutEnabled;not null;type:bit"`
	AccessFailedCount    int       `gorm:"column:AccessFailedCount;not null"`
	ExtraProperties      string    `gorm:"column:ExtraProperties;not null"`
	Roles                []Role
}

User user table

type UserRole

type UserRole struct {
	UserID   uuid.UUID `gorm:"column:UserId;not null;type:uniqueidentifier"`
	RoleID   uuid.UUID `gorm:"column:RoleId;not null;type:uniqueidentifier"`
	TenantID uuid.UUID `gorm:"column:TenantId;type:uniqueidentifier"`
}

UserRole user role table

Jump to

Keyboard shortcuts

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