forge

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

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

Go to latest
Published: Mar 30, 2024 License: Unlicense Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccessorTypes

func AccessorTypes() []string

func Arrange

func Arrange[T any, K comparable](elems []T, el T, idx int, key func(a T) K, override bool) []T

Arrange inserts/removes a element 'el' at index 'idx'.

It will perform equality check with 'key(el)'. When key function is nil, it cannot compare elements. So 'elems' will be returned as untouched.

If a key for 'el' already exists, it will override the value only if user set 'override' to true.

idx < 0 means remove the element. idx >= len(elems) means append it to the last.

ex) When elems is []string{"a", "b", "c"} with given arguments, results will be same as following.

elems = []string{"b", "c"}       where path = "a" and idx = -1
elems = []string{"a", "b", "c"}  where path = "a" and idx = 0
elems = []string{"b", "a", "c"}  where path = "a" and idx = 1
elems = []string{"b", "c", "a"}  where path = "a" and idx = 2

func CompareProperty

func CompareProperty(t string, a, b string) int

func ContextWithUserName

func ContextWithUserName(ctx context.Context, email string) context.Context

func PropertyTypes

func PropertyTypes() []string

func UserNameFromContext

func UserNameFromContext(ctx context.Context) string

Types

type APIResponse

type APIResponse struct {
	Msg any
	Err string
}

type Access

type Access struct {
	ID        int
	EntryPath string
	Name      string
	Type      string // Don't need when adding Access.
	Value     string
	RawValue  int
	UpdatedAt time.Time
}

func (*Access) MarshalJSON

func (p *Access) MarshalJSON() ([]byte, error)

type AccessFinder

type AccessFinder struct {
	EntryPath *string
	Name      *string
}

type AccessUpdater

type AccessUpdater struct {
	EntryPath string
	Name      string
	Value     *string
}

type Accessor

type Accessor struct {
	ID       int
	IsGroup  bool
	Name     string
	Called   string
	Disabled bool
}

Accessor is either a user or a group, that can be specified in entry access control list.

type Config

type Config struct {
	Forge     *ForgeConfig
	EntryType *EntryTypeConfig
}

func LoadConfig

func LoadConfig(configDir string) (*Config, error)

type Default

type Default struct {
	ID        int
	EntryType string
	Category  string
	Name      string
	Type      string
	Value     string
}

Default is property, environ or sub-entry defined for entry type, So it will be automatically created while creation of an entry of the entry type.

type DefaultFinder

type DefaultFinder struct {
	EntryType *string
	Category  *string
	Name      *string
}

type DefaultUpdater

type DefaultUpdater struct {
	EntryType string
	Category  string
	Name      string
	Type      *string
	Value     *string
}

type Entry

type Entry struct {
	ID           int
	Path         string
	Type         string
	Archived     bool
	CreatedAt    time.Time
	UpdatedAt    time.Time
	HasThumbnail bool
	Property     map[string]*Property
}

func (*Entry) MarshalJSON

func (e *Entry) MarshalJSON() ([]byte, error)

func (*Entry) Name

func (e *Entry) Name() string

type EntryFinder

type EntryFinder struct {
	ID           *int
	ParentPath   *string
	AncestorPath *string
	ChildPath    *string
	Path         *string
	Types        []string
	Archived     bool // Don't set manually, it will be automatically set.
}

type EntrySearcher

type EntrySearcher struct {
	SearchRoot string
	Keywords   []string
}

type EntryTypeConfig

type EntryTypeConfig struct {
	Types []EntryTypeInfo
}

type EntryTypeInfo

type EntryTypeInfo struct {
	Name       string
	SubEntries []KeyTypeValue `toml:"sub_entries"`
	Properties []KeyTypeValue
	Environs   []KeyTypeValue
}

type EntryTypeUpdater

type EntryTypeUpdater struct {
	ID   int
	Name *string
}

type ForgeConfig

type ForgeConfig struct {
	UserdataRoot string `toml:"userdata_root"`
}

type Global

type Global struct {
	ID        int
	EntryType string
	Name      string
	Type      string
	Value     string
}

Global is similar with Default in a sense that it is tied to an EntryType. But it won't be created for each entry. So it cannot be overrided as well.

type GlobalFinder

type GlobalFinder struct {
	EntryType *string
	Name      *string
}

type GlobalUpdater

type GlobalUpdater struct {
	EntryType string
	Name      string
	Type      *string
	Value     *string
}

type Group

type Group struct {
	ID     int
	Name   string
	Called string
}

type GroupFinder

type GroupFinder struct {
	Name   *string
	Called *string
}

type GroupUpdater

type GroupUpdater struct {
	Name    string
	NewName *string
	Called  *string
}

type KeyTypeValue

type KeyTypeValue struct {
	Key   string
	Type  string
	Value string
}

func (*KeyTypeValue) UnmarshalText

func (ktv *KeyTypeValue) UnmarshalText(text []byte) error

type KeyValue

type KeyValue struct {
	Key   string
	Value string
}

type Log

type Log struct {
	ID        int
	EntryPath string
	User      string
	Action    string
	Category  string
	Name      string
	Type      string
	Value     string
	When      time.Time
}

func (*Log) String

func (l *Log) String() string

type LogFinder

type LogFinder struct {
	EntryPath *string
	Category  *string
	Name      *string
}

type Member

type Member struct {
	Group  string
	Member string
}

type MemberFinder

type MemberFinder struct {
	Group  string
	Member *string
}

type NotFoundError

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

func NotFound

func NotFound(s string, is ...any) *NotFoundError

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

type OIDC

type OIDC struct {
	ClientID     string
	ClientSecret string
	RedirectURI  string
	HostDomain   string
}

OIDC stands for open id connect.

type Property

type Property struct {
	ID         int
	EntryPath  string
	Name       string
	Type       string
	Eval       string
	Value      string
	ValueError error
	RawValue   string
	UpdatedAt  time.Time
}

Property can be either a normal property or an environment.

func (*Property) MarshalJSON

func (p *Property) MarshalJSON() ([]byte, error)

type PropertyFinder

type PropertyFinder struct {
	EntryPath *string
	Name      *string
	DefaultID *int
}

type PropertyUpdater

type PropertyUpdater struct {
	EntryPath string
	Name      string
	Value     *string
}

type QuickSearchArranger

type QuickSearchArranger struct {
	KV    StringKV
	Index int
}

type Server

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

func NewServer

func NewServer(svc Service, cfg *Config) *Server

func (*Server) AddAccess

func (s *Server) AddAccess(ctx context.Context, path string, accessor, mode string) error

func (*Server) AddDefault

func (s *Server) AddDefault(ctx context.Context, entType, ctg, name, typ, value string) error

func (*Server) AddEntry

func (s *Server) AddEntry(ctx context.Context, path, typ string) error

func (*Server) AddEntryType

func (s *Server) AddEntryType(ctx context.Context, name string) error

func (*Server) AddEnviron

func (s *Server) AddEnviron(ctx context.Context, path string, name, typ, value string) error

func (*Server) AddGlobal

func (s *Server) AddGlobal(ctx context.Context, entType, name, typ, value string) error

func (*Server) AddGroup

func (s *Server) AddGroup(ctx context.Context, g *Group) error

func (*Server) AddGroupMember

func (s *Server) AddGroupMember(ctx context.Context, group, member string) error

func (*Server) AddThumbnail

func (s *Server) AddThumbnail(ctx context.Context, path string, img image.Image) error

AddThumbnail adds a thumbnail image to a entry.

func (*Server) AddUser

func (s *Server) AddUser(ctx context.Context, u *User) error

func (*Server) AddUserDataSection

func (s *Server) AddUserDataSection(ctx context.Context, user, section string) error

func (*Server) ArchiveEntry

func (s *Server) ArchiveEntry(ctx context.Context, path string) error

func (*Server) CountAllSubEntries

func (s *Server) CountAllSubEntries(ctx context.Context, path string) (int, error)

func (*Server) Defaults

func (s *Server) Defaults(ctx context.Context, entType string) ([]*Default, error)

func (*Server) DeleteAccess

func (s *Server) DeleteAccess(ctx context.Context, path string, accessor string) error

func (*Server) DeleteDefault

func (s *Server) DeleteDefault(ctx context.Context, entType, ctg, name string) error

func (*Server) DeleteEntry

func (s *Server) DeleteEntry(ctx context.Context, path string) error

func (*Server) DeleteEntryRecursive

func (s *Server) DeleteEntryRecursive(ctx context.Context, path string) error

func (*Server) DeleteEntryType

func (s *Server) DeleteEntryType(ctx context.Context, name string) error

func (*Server) DeleteEnviron

func (s *Server) DeleteEnviron(ctx context.Context, path string, name string) error

func (*Server) DeleteGlobal

func (s *Server) DeleteGlobal(ctx context.Context, entType, name string) error

func (*Server) DeleteGroupMember

func (s *Server) DeleteGroupMember(ctx context.Context, group, member string) error

func (*Server) DeleteThumbnail

func (s *Server) DeleteThumbnail(ctx context.Context, path string) error

func (*Server) DeleteUserData

func (s *Server) DeleteUserData(ctx context.Context, user, section, key string) error

func (*Server) DeleteUserDataSection

func (s *Server) DeleteUserDataSection(ctx context.Context, user, section string) error

func (*Server) DisabledUsers

func (s *Server) DisabledUsers(ctx context.Context) ([]*User, error)

func (*Server) EntryAccessList

func (s *Server) EntryAccessList(ctx context.Context, path string) ([]*Access, error)

func (*Server) EntryEnvirons

func (s *Server) EntryEnvirons(ctx context.Context, path string) ([]*Property, error)

func (*Server) EntryLogs

func (s *Server) EntryLogs(ctx context.Context, path string) ([]*Log, error)

func (*Server) EntryProperties

func (s *Server) EntryProperties(ctx context.Context, path string) ([]*Property, error)

func (*Server) FindAllGroups

func (s *Server) FindAllGroups(ctx context.Context) ([]*Group, error)

func (*Server) FindBaseEntryTypes

func (s *Server) FindBaseEntryTypes(ctx context.Context) ([]string, error)

func (*Server) FindEntries

func (s *Server) FindEntries(ctx context.Context, find EntryFinder) ([]*Entry, error)

func (*Server) FindEntryTypes

func (s *Server) FindEntryTypes(ctx context.Context) ([]string, error)

func (*Server) FindGroupMembers

func (s *Server) FindGroupMembers(ctx context.Context, group string) ([]*Member, error)

func (*Server) FindOverrideEntryTypes

func (s *Server) FindOverrideEntryTypes(ctx context.Context) ([]string, error)

func (*Server) FindUserData

func (s *Server) FindUserData(ctx context.Context, find UserDataFinder) ([]*UserDataSection, error)

func (*Server) GetAccess

func (s *Server) GetAccess(ctx context.Context, path string, accessor string) (*Access, error)

func (*Server) GetEntry

func (s *Server) GetEntry(ctx context.Context, path string) (*Entry, error)

func (*Server) GetEnviron

func (s *Server) GetEnviron(ctx context.Context, path, name string) (*Property, error)

func (*Server) GetGlobal

func (s *Server) GetGlobal(ctx context.Context, entType, name string) (*Global, error)

func (*Server) GetGroup

func (s *Server) GetGroup(ctx context.Context, group string) (*Group, error)

func (*Server) GetLogs

func (s *Server) GetLogs(ctx context.Context, path, ctg, name string) ([]*Log, error)

func (*Server) GetProperty

func (s *Server) GetProperty(ctx context.Context, path string, name string) (*Property, error)

func (*Server) GetThumbnail

func (s *Server) GetThumbnail(ctx context.Context, path string) (*Thumbnail, error)

GetThumbnail gets a thumbnail image of a entry.

func (*Server) GetUser

func (s *Server) GetUser(ctx context.Context, user string) (*User, error)

func (*Server) GetUserData

func (s *Server) GetUserData(ctx context.Context, user, section, key string) (string, error)

func (*Server) GetUserDataSection

func (s *Server) GetUserDataSection(ctx context.Context, user, section string) (*UserDataSection, error)

func (*Server) GetUserSetting

func (s *Server) GetUserSetting(ctx context.Context, user string) (*UserSetting, error)

func (*Server) Globals

func (s *Server) Globals(ctx context.Context, entType string) ([]*Global, error)

func (*Server) IsAdmin

func (s *Server) IsAdmin(ctx context.Context, user string) (bool, error)

func (*Server) ParentEntries

func (s *Server) ParentEntries(ctx context.Context, path string) ([]*Entry, error)

ParentEntries returns parent entries from root to a given entry (but without the entry).

func (*Server) RenameEntry

func (s *Server) RenameEntry(ctx context.Context, path, newName string) error

func (*Server) RenameEntryType

func (s *Server) RenameEntryType(ctx context.Context, name, newName string) error

func (*Server) RenameGroup

func (s *Server) RenameGroup(ctx context.Context, name string, newName string) error

func (*Server) SearchEntries

func (s *Server) SearchEntries(ctx context.Context, path, query string) ([]*Entry, error)

func (*Server) SetUserData

func (s *Server) SetUserData(ctx context.Context, user, section, key, value string) error

func (*Server) SubEntries

func (s *Server) SubEntries(ctx context.Context, path string) ([]*Entry, error)

func (*Server) UnarchiveEntry

func (s *Server) UnarchiveEntry(ctx context.Context, path string) error

func (*Server) UpdateAccess

func (s *Server) UpdateAccess(ctx context.Context, path, accessor, mode string) error

func (*Server) UpdateDefault

func (s *Server) UpdateDefault(ctx context.Context, entType, ctg, name, typ, value string) error

func (*Server) UpdateEnviron

func (s *Server) UpdateEnviron(ctx context.Context, path string, name, value string) error

func (*Server) UpdateGlobal

func (s *Server) UpdateGlobal(ctx context.Context, entType, name, typ, value string) error

func (*Server) UpdateProperties

func (s *Server) UpdateProperties(ctx context.Context, upds []PropertyUpdater) error

func (*Server) UpdateProperty

func (s *Server) UpdateProperty(ctx context.Context, path string, name, value string) error

func (*Server) UpdateThumbnail

func (s *Server) UpdateThumbnail(ctx context.Context, path string, img image.Image) error

func (*Server) UpdateUserCalled

func (s *Server) UpdateUserCalled(ctx context.Context, user, called string) error

func (*Server) UpdateUserDisabled

func (s *Server) UpdateUserDisabled(ctx context.Context, user string, disabled bool) error

func (*Server) UpdateUserSetting

func (s *Server) UpdateUserSetting(ctx context.Context, user, key string, value any) error

func (*Server) Users

func (s *Server) Users(ctx context.Context) ([]*User, error)

type Service

type Service interface {
	FindEntryTypes(ctx context.Context) ([]string, error)
	FindBaseEntryTypes(ctx context.Context) ([]string, error)
	FindOverrideEntryTypes(ctx context.Context) ([]string, error)
	AddEntryType(ctx context.Context, name string) error
	RenameEntryType(ctx context.Context, name, newName string) error
	DeleteEntryType(ctx context.Context, name string) error
	FindDefaults(ctx context.Context, find DefaultFinder) ([]*Default, error)
	AddDefault(ctx context.Context, d *Default) error
	UpdateDefault(ctx context.Context, upd DefaultUpdater) error
	DeleteDefault(ctx context.Context, entType, ctg, name string) error
	FindGlobals(ctx context.Context, find GlobalFinder) ([]*Global, error)
	GetGlobal(ctx context.Context, entType, name string) (*Global, error)
	AddGlobal(ctx context.Context, d *Global) error
	UpdateGlobal(ctx context.Context, upd GlobalUpdater) error
	DeleteGlobal(ctx context.Context, entType, name string) error
	FindEntries(ctx context.Context, find EntryFinder) ([]*Entry, error)
	SearchEntries(ctx context.Context, search EntrySearcher) ([]*Entry, error)
	CountAllSubEntries(ctx context.Context, path string) (int, error)
	GetEntry(ctx context.Context, path string) (*Entry, error)
	AddEntry(ctx context.Context, ent *Entry) error
	RenameEntry(ctx context.Context, path string, newName string) error
	ArchiveEntry(ctx context.Context, path string) error
	UnarchiveEntry(ctx context.Context, path string) error
	DeleteEntry(ctx context.Context, path string) error
	DeleteEntryRecursive(ctx context.Context, path string) error
	AddThumbnail(ctx context.Context, thumb *Thumbnail) error
	UpdateThumbnail(ctx context.Context, upd ThumbnailUpdater) error
	GetThumbnail(ctx context.Context, path string) (*Thumbnail, error)
	DeleteThumbnail(ctx context.Context, path string) error
	EntryProperties(ctx context.Context, path string) ([]*Property, error)
	GetProperty(ctx context.Context, path, name string) (*Property, error)
	UpdateProperty(ctx context.Context, upd PropertyUpdater) error
	UpdateProperties(ctx context.Context, upds []PropertyUpdater) error
	EntryEnvirons(ctx context.Context, path string) ([]*Property, error)
	GetEnviron(ctx context.Context, path, name string) (*Property, error)
	AddEnviron(ctx context.Context, p *Property) error
	UpdateEnviron(ctx context.Context, upd PropertyUpdater) error
	DeleteEnviron(ctx context.Context, path string, name string) error
	EntryAccessList(ctx context.Context, path string) ([]*Access, error)
	GetAccess(ctx context.Context, path, name string) (*Access, error)
	AddAccess(ctx context.Context, ac *Access) error
	UpdateAccess(ctx context.Context, upd AccessUpdater) error
	DeleteAccess(ctx context.Context, path string, name string) error
	IsAdmin(ctx context.Context, user string) (bool, error)
	FindLogs(ctx context.Context, find LogFinder) ([]*Log, error)
	GetLogs(ctx context.Context, path, ctg, name string) ([]*Log, error)
	FindUsers(ctx context.Context, find UserFinder) ([]*User, error)
	AddUser(ctx context.Context, u *User) error
	UpdateUser(ctx context.Context, upd UserUpdater) error
	GetUser(ctx context.Context, user string) (*User, error)
	GetUserSetting(ctx context.Context, user string) (*UserSetting, error)
	UpdateUserSetting(ctx context.Context, upd UserSettingUpdater) error
	FindUserData(ctx context.Context, find UserDataFinder) ([]*UserDataSection, error)
	AddUserDataSection(ctx context.Context, user, section string) error
	GetUserDataSection(ctx context.Context, user, section string) (*UserDataSection, error)
	DeleteUserDataSection(ctx context.Context, user, section string) error
	GetUserData(ctx context.Context, user, section, key string) (string, error)
	SetUserData(ctx context.Context, user, section, key, value string) error
	DeleteUserData(ctx context.Context, user, section, key string) error
	FindGroups(ctx context.Context, find GroupFinder) ([]*Group, error)
	AddGroup(ctx context.Context, g *Group) error
	UpdateGroup(ctx context.Context, upd GroupUpdater) error
	FindGroupMembers(ctx context.Context, find MemberFinder) ([]*Member, error)
	AddGroupMember(ctx context.Context, m *Member) error
	DeleteGroupMember(ctx context.Context, group, member string) error
}

type Status

type Status struct {
	Name  string
	Color string
}

Status indicates a status in an entry type. It should have css complient color information.

type StringKV

type StringKV struct {
	K string
	V string
}

type StringSliceArranger

type StringSliceArranger struct {
	Value string
	Index int
}

type Thumbnail

type Thumbnail struct {
	ID        int
	EntryPath string
	Data      []byte
}

type ThumbnailFinder

type ThumbnailFinder struct {
	EntryPath *string
}

type ThumbnailUpdater

type ThumbnailUpdater struct {
	EntryPath string
	Data      []byte
}

type UnauthorizedError

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

func Unauthorized

func Unauthorized(s string, is ...any) *UnauthorizedError

func (*UnauthorizedError) Error

func (e *UnauthorizedError) Error() string

type User

type User struct {
	ID       int
	Name     string
	Called   string
	Disabled bool
}

type UserDataFinder

type UserDataFinder struct {
	User    string
	Section *string
	Key     *string
}

type UserDataSection

type UserDataSection struct {
	Section string
	Data    map[string]string
}

UserDataSection includes some or all user data in a section. Unlike UserSetting, it could have arbitrary section and data, Parsing the data is left up to the clients.

type UserFinder

type UserFinder struct {
	ID       *int
	Name     *string
	Called   *string
	Disabled *bool
}

type UserSetting

type UserSetting struct {
	ID                          int
	User                        string
	EntryPageHideSideMenu       bool
	EntryPageSelectedCategory   string
	EntryPageShowHiddenProperty string
	EntryPageExpandProperty     bool
	EntryPageSearchEntryType    string
	EntryPagePropertyFilter     map[string]string
	EntryPageSortProperty       map[string]string
	PickedProperty              map[string]string
	PickedPropertyInputSize     [2]int
	QuickSearches               []StringKV
	PinnedPaths                 []string
	RecentPaths                 []string
	ProgramsInUse               []string
	UpdateMarkerLasts           int
	SearchView                  string
	EntryGroupBy                string
	CopyPathRemap               string
	ShowArchived                bool
}

type UserSettingFinder

type UserSettingFinder struct {
	User *string
}

type UserSettingUpdater

type UserSettingUpdater struct {
	User  string
	Key   string
	Value any
}

type UserUpdater

type UserUpdater struct {
	Name     string
	Called   *string
	Disabled *bool
}

Directories

Path Synopsis
cmd
service

Jump to

Keyboard shortcuts

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