apperix

package module
v0.0.0-...-be39475 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 License: MIT Imports: 21 Imported by: 0

README

apperix

Apperix is web framework for building secure and scalable web applications in Go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConcatStrings

func ConcatStrings(base string, append ...string) string

Types

type AuthenticationConfig

type AuthenticationConfig struct {
	Path            string
	TokenExpiry     time.Duration
	SignatureSecret string
}

AuthenticationConfig bundles authentication related configurations.

type Client

type Client struct {
	Identifier *Identifier
}

type DatabaseConfig

type DatabaseConfig struct {
	Location string
	Cache    int
}

AuthenticationConfig bundles database related configurations.

type DatabaseFailureError

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

DatabaseFailureError represents error cases where either the database is unreachable or the database query was faulty.

func (DatabaseFailureError) Error

func (err DatabaseFailureError) Error() string

type DefaultResourcePermissions

type DefaultResourcePermissions struct {
	UserPermissions  Permissions
	GuestPermissions Permissions
	Inheritance      PermissionInheritance
}

type DefaultsConfig

type DefaultsConfig struct {
	MaxUploadSize    int64
	UploadDirectory  string
	AutoCleanUploads bool
}

DefaultsConfig bundles default values and directories.

type Handler

type Handler func(*Client, *Request, *Service) Response

type HashAlgorithm

type HashAlgorithm int
const (
	HS256 HashAlgorithm = iota
	HS384
	HS512
	RS256
	RS384
	RS512
	ES256
	ES384
	ES512
)

type Identifier

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

func GenerateUniqueIdentifier

func GenerateUniqueIdentifier() Identifier

func (*Identifier) Bytes

func (identifier *Identifier) Bytes() []byte

func (*Identifier) FromBytes

func (identifier *Identifier) FromBytes(str []byte)

func (*Identifier) FromString

func (identifier *Identifier) FromString(str string)

func (*Identifier) String

func (identifier *Identifier) String() string

type Method

type Method int
const (
	CREATE Method = iota
	READ
	UPDATE
	DELETE
	PATCH
	READ_HEADERS
	READ_OPTIONS
	PURGE
	COPY
	MOVE
	LINK
	UNLINK
	LOCK
	UNLOCK
	READ_PROPERTIES
	UPDATE_PROPERTIES
	CREATE_COLLECTION
)

type NetworkConfig

type NetworkConfig struct {
	HttpPort  uint16
	HttpsPort uint16
}

NetworkConfig bundles network related configurations.

type NotFoundError

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

NotFoundError represents error cases where the requested object was not found.

func (NotFoundError) Error

func (err NotFoundError) Error() string

type PermissionInheritance

type PermissionInheritance struct {
	Owner                bool
	UserPermissions      bool
	OtherUserPermissions bool
	GuestPermissions     bool
}

type Permissions

type Permissions struct {
	Create           bool
	Read             bool
	Update           bool
	Delete           bool
	Patch            bool
	ReadHeaders      bool
	ReadOptions      bool
	Purge            bool
	Copy             bool
	Move             bool
	Link             bool
	Unlink           bool
	Lock             bool
	Unlock           bool
	ReadProperties   bool
	UpdateProperties bool
	CreateCollection bool
}

func (*Permissions) AllowAll

func (perm *Permissions) AllowAll()

func (*Permissions) Deserialize

func (perm *Permissions) Deserialize(mask uint32)

func (*Permissions) ForbidAll

func (perm *Permissions) ForbidAll()

func (*Permissions) Serialize

func (perm *Permissions) Serialize() (mask uint32)

type Request

type Request struct {
	Parameters url.Values
	// contains filtered or unexported fields
}

func (*Request) Data

func (req *Request) Data(key string) string

func (*Request) File

func (req *Request) File(key string) (
	metadata map[string]string,
	data bytes.Buffer,
	err error,
)

type Resource

type Resource struct {
	Permissions   DefaultResourcePermissions
	Handlers      map[Method]Handler
	Name          string
	Parent        string
	MaxUploadSize int64
	Type          ResourceType
	Pattern       string
}

type ResourceIdentifier

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

func (*ResourceIdentifier) HasParent

func (resId *ResourceIdentifier) HasParent() bool

func (*ResourceIdentifier) Identifier

func (resId *ResourceIdentifier) Identifier() string

func (*ResourceIdentifier) Parent

func (resId *ResourceIdentifier) Parent() (
	parentId ResourceIdentifier,
	err error,
)

func (*ResourceIdentifier) Serialize

func (resId *ResourceIdentifier) Serialize() string

func (*ResourceIdentifier) String

func (resId *ResourceIdentifier) String() string

func (*ResourceIdentifier) Url

func (resId *ResourceIdentifier) Url() string

func (*ResourceIdentifier) VariableValues

func (resId *ResourceIdentifier) VariableValues() map[string]string

type ResourceType

type ResourceType int
const (
	STATIC ResourceType = iota
	VARIABLE
)

type Response

type Response interface {
	String() *[]byte
	Status() int
	Header(string, string)
	//server side error
	ReplyServerError(string, string)
	ReplyNotImplemented(string)
	//client side error
	ReplyClientError(string, string)
	ReplyForbidden(string)
	ReplyNotFound(string)
	//success
	ReplyCreated()
	//custom
	ReplyCustom(int)
	ReplyCustomError(int, string, string)
}

type ResponseJson

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

func (*ResponseJson) Data

func (response *ResponseJson) Data(key string, value interface{})

func (*ResponseJson) Header

func (response *ResponseJson) Header(head string, value string)

func (*ResponseJson) ReplyClientError

func (response *ResponseJson) ReplyClientError(code string, message string)

func (*ResponseJson) ReplyCreated

func (response *ResponseJson) ReplyCreated()

func (*ResponseJson) ReplyCustom

func (response *ResponseJson) ReplyCustom(status int)

func (*ResponseJson) ReplyCustomError

func (response *ResponseJson) ReplyCustomError(status int, code string, message string)

func (*ResponseJson) ReplyForbidden

func (response *ResponseJson) ReplyForbidden(message string)

func (*ResponseJson) ReplyNotFound

func (response *ResponseJson) ReplyNotFound(message string)

func (*ResponseJson) ReplyNotImplemented

func (response *ResponseJson) ReplyNotImplemented(message string)

func (*ResponseJson) ReplyServerError

func (response *ResponseJson) ReplyServerError(code string, message string)

func (*ResponseJson) Status

func (response *ResponseJson) Status() int

func (*ResponseJson) String

func (response *ResponseJson) String() *[]byte

type SecurityConfig

type SecurityConfig struct {
	Https         bool
	Certificate   string
	PrivateKey    string
	HashAlgorithm HashAlgorithm
}

SecurityConfig bundles security related configurations.

type Service

type Service struct {
	Config configuration
	// contains filtered or unexported fields
}

The Service type represents an actual apperix service.

func CreateService

func CreateService(conf ServiceConfig) (
	service *Service,
)

CreateService constructs and returns an initialized apperix service.

CAUTION: Faulty configuration will cause panic!

func (*Service) AssignOwner

func (service *Service) AssignOwner(
	resourceId ResourceIdentifier,
	userId Identifier,
) (
	err error,
)

AssignOwner transfers ownership of the given resource to the given user. The new owner will be defined in case there is yet no one owning the given resource.

func (*Service) AssignPermissions

func (service *Service) AssignPermissions(
	resourceId ResourceIdentifier,
	user interface{},
	permissions Permissions,
) (
	err error,
)

AssignPermissions assigns provided permissions for the given user on the given resource. Already registered entries will be overwritten.

NOTICE: The user argument accepts both a certain user identifier or an abstract user like other users (OTHERS) and guests (GUESTS).

CAUTION: passing user identifier of unsupported type will cause panic!

func (*Service) CreateUser

func (service *Service) CreateUser(
	username string,
	password string,
) (
	assignedId Identifier,
	err error,
)

CreateUser registeres a new user account identified by the given username and returns its generated unique identifier. The given password will later be associated with the given username and encrypted using a cryptographic hash function. An error will be returned in either of the cases: 1) Either username, password or both do not match minimal requirements. 2) The given username is already taken by another account.

func (*Service) FindUserById

func (service *Service) FindUserById(
	identifier Identifier,
) (
	account UserAccount,
	err error,
)

FindUserById returns a user account identified by the given identifier. An error will be returned in case no user was found.

func (*Service) FindUserByUsername

func (service *Service) FindUserByUsername(
	username string,
) (
	account UserAccount,
	err error,
)

FindUserByUsername returns a user account identified by the given username. An error will be returned in case no user was found.

func (*Service) GetPermissionsFor

func (service *Service) GetPermissionsFor(
	resourceId ResourceIdentifier,
	user interface{},
) (
	permissions Permissions,
	err error,
)

GetPermissionsFor returns directly assigned permissions and inheritance flags for the user and resource. Its not recommended to use this method to get actual permissions of a user for the final resource as it doesnt resolve permissions by taking the inherited ones into account, to resolve final permissions use ResolvePermissionsFor instead.

CAUTION: passing user identifier of unsupported type will cause panic!

func (*Service) GetResourceIdentifier

func (service *Service) GetResourceIdentifier(
	identifier string,
	variables map[string]string,
) (
	resourceId ResourceIdentifier,
	err error,
)

GetResourceIdentifier returns a resource identifier object representing the resource given its identifier and path of variable values. An error will be returned in the following 3 cases: 1) the identifier is not registered therefore invalid. 2) one or multiple required variable values are missing. 3) one or multiple required variable values do not match assigned pattern.

func (*Service) ResolvePermissionsFor

func (service *Service) ResolvePermissionsFor(
	resourceId ResourceIdentifier,
	user interface{},
) (
	isOwner bool,
	permissions Permissions,
	err error,
)

ResolvePermissionsFor returns actual permissions of the given user for the given resource resolving inherited permissions.

CAUTION: passing user identifier of unsupported type will cause panic!

func (*Service) RevokePermissions

func (service *Service) RevokePermissions(
	resourceId ResourceIdentifier,
	user interface{},
) (
	err error,
)

RevokePermissions revokes permission entries for for the given user on the given resource.

NOTICE: The user argument accepts both a certain user identifier or an abstract user like other users (OTHERS) and guests (GUESTS).

CAUTION: passing user identifier of unsupported type will cause panic!

func (*Service) Run

func (service *Service) Run()

Run will start the service server and block until its shutdown

func (*Service) Shutdown

func (service *Service) Shutdown()

Shutdown gracefully stops the service

type ServiceConfig

type ServiceConfig struct {
	Name           string
	Database       DatabaseConfig
	Authentication AuthenticationConfig
	Network        NetworkConfig
	Security       SecurityConfig
	Defaults       DefaultsConfig
	Resources      map[string]Resource
}

ServiceConfig bundles all required configuration bundles.

type TargetUser

type TargetUser int

The TargetUser type represents an enumeration of special users like: OTHERS and GUESTS. Just like certain user identifiers these special users can be used for identification.

const (
	OTHERS TargetUser = iota
	GUESTS
)

type UserAccount

type UserAccount struct {
	Identifier Identifier
	Username   string
	Password   string
}

The UserAccount type represents bundled information about a user registered in the apperix service.

Jump to

Keyboard shortcuts

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