sprawl

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: MIT Imports: 11 Imported by: 0

README

Sprawl

A user account system, manager and SDK.

TODO

  • Finish making it a turnkey authentication/authorisation database SDK
  • Bulk import
  • Bulk export
  • Bulk delete

Documentation

Index

Constants

View Source
const (
	// EPAuth authenticates a user and returns a token.
	EPAuth = "/auth"
	// EPVerifyToken compares a username and token to stored tokens, then returns OK if valid.
	EPVerifyToken = "/verifytoken"

	// EPUsers is the bulk user endpoint.
	// GET lists all users.
	// POST creates multiple users.
	// PUT updates multiple users.
	// DELETE deletes multiple users.
	EPUsers = "/users"

	// EPUser is the single user endpoint.
	// GET returns a single user.
	// POST creates a single user.
	// PUT updates a single user.
	// DELETE deletes a single user.
	EPUser = "/user"

	// EPSetPassword sets the password for a user.
	EPSetPassword = "/password"

	// EPSites is the bulk site endpoint.
	// GET lists all sites.
	// POST creates multiple sites.
	// PUT updates multiple sites.
	// DELETE removes multiple sites.
	EPSites = "/sites"

	// EPSite is the single site endpoint.
	// POST creates a single site.
	// PUT updates a single site.
	// DELETE removes a single site.
	EPSite = "/site"

	// EPSetAdmin sets a user as an admin on a site.
	// PUT updates a single member.
	EPSetAdmin = "/setadmin"

	// EPSetProfile updates profike data for a user on a site.
	// PUT updates a single profile.
	EPSetProfile = "/updateprofile"

	//EPGroups is the bulk group endpoint.
	//GET lists all groups.
	//POST creates multiple groups.
	//DELETE removes multiple groups.
	EPGroups = "/groups"

	//EPGroup is the single group endpoint.
	//POST creates a single group.
	//DELETE removes a single group.
	EPGroup = "/group"

	// EPPermissions is the bulk permission endpoint.
	// GET lists all permissions.
	// POST creates multiple permissions.
	// DELETE removes multiple permissions.
	EPPermissions = "/permissions"

	// EPPermission is the single permission endpoint.
	// GET returns a single permission.
	// POST creates a single permission.
	// DELETE removes a single permission.
	EPPermission = "/permission"

	// EPMembers is the bulk member endpoint.
	// GET lists all members.
	// POST creates multiple members.
	// PUT updates multiple members.
	// DELETE removes multiple members.
	EPMembers = "/members"

	// EPMember is the single member endpoint.
	// POST creates a single member.
	// PUT updates a single member.
	// DELETE removes a single member.
	EPMember = "/member"

	// EPAdmin enables and disables admin status for a user on a site.
	// PUT enables admin status.
	// DELETE disables admin status.
	EPAdmin = "/admin"
)

Variables

This section is empty.

Functions

func RandString

func RandString(size int) string

RandString generates a random string suitable for passwords.

Types

type Database

type Database struct {
	*pgxpool.Pool
}

Database pools for Sprawl.

func NewDatabase

func NewDatabase(conn string) (*Database, error)

NewDatabase connects to the database and creates a connection pool.

func (*Database) AddGroupMember added in v0.2.0

func (db *Database) AddGroupMember(site, group, name string) error

AddGroupMember adds a user to a group.

func (*Database) AddGroupPermission added in v0.3.0

func (db *Database) AddGroupPermission(site, group, name string) error

AddGroupPermission adds a permission to a group.

func (*Database) AddSiteMember added in v0.2.0

func (db *Database) AddSiteMember(site, name, data, admin string) error

AddSiteMember adds a profile for a user.

func (*Database) AuthUser added in v0.11.0

func (db *Database) AuthUser(name, password string) bool

AuthUser returns true if the uwername and password match.

func (*Database) CreateGroup

func (db *Database) CreateGroup(name, site string) error

CreateGroup creates a new group.

func (*Database) CreatePermission added in v0.2.0

func (db *Database) CreatePermission(name, description string) error

CreatePermission adds a new keyword and optional description.

func (*Database) CreateProfile added in v0.2.0

func (db *Database) CreateProfile(username, site, data string, admin bool) error

CreateProfile both adds a user to a site and creates its site-specific profile entry.

func (*Database) CreateSite

func (db *Database) CreateSite(name string) error

Createsite in the database.

func (*Database) CreateTables

func (db *Database) CreateTables() error

CreateTables sets up the database.

func (*Database) CreateUser

func (db *Database) CreateUser(name, password string) error

CreateUser in database.

func (*Database) DeleteGroup

func (db *Database) DeleteGroup(name, site string) error

DeleteGroup deletes a group.

func (*Database) DeleteGroupByID

func (db *Database) DeleteGroupByID(id int64) error

DeleteGroupByID deletes a group by ID.

func (*Database) DeletePermission added in v0.2.0

func (db *Database) DeletePermission(name string) error

DeletePermission deletes a permission keyword.

func (*Database) DeleteSite

func (db *Database) DeleteSite(name string) error

DeleteSite from the database.

func (*Database) DeleteUser

func (db *Database) DeleteUser(name string) error

DeleteUser deletes a user from the database.

func (*Database) GenerateToken added in v0.8.0

func (db *Database) GenerateToken(name string) string

GenerateToken if needed.

func (*Database) GetGroupMembers added in v0.2.0

func (db *Database) GetGroupMembers(site, group string) (UserList, error)

GetGroupMembers returns a UserList.

func (*Database) GetGroupPermissions added in v0.3.0

func (db *Database) GetGroupPermissions(site, group string) (PermissionList, error)

func (*Database) GetGroups

func (db *Database) GetGroups(start, max int64, site string) (GroupList, error)

GetGroups returns many groups.

func (*Database) GetPermission added in v0.3.0

func (db *Database) GetPermission(name string) (Permission, error)

GetPermission returns a permission keyword and its description.

func (*Database) GetPermissions added in v0.2.0

func (db *Database) GetPermissions() (PermissionList, error)

GetPermissions returns all permission keywords and their descriptions.

func (*Database) GetSiteID

func (db *Database) GetSiteID(name string) (int64, error)

GetSiteID from a name.

func (*Database) GetSiteMembers added in v0.2.0

func (db *Database) GetSiteMembers(site string) ([]User, error)

GetSiteMembers returns a slice of users for a site.

func (*Database) GetSites

func (db *Database) GetSites(start, max int64) ([]Site, error)

GetSites in a string slice.

func (*Database) GetUser

func (db *Database) GetUser(name string) (User, error)

GetUser by name.

func (*Database) GetUsers

func (db *Database) GetUsers(start, max int64) ([]User, error)

GetUsers returns a range of users.

func (*Database) Has added in v0.4.0

func (db *Database) Has(name, permission string) bool

Has the user got a specific permission?

func (*Database) InitDatabase added in v0.9.0

func (db *Database) InitDatabase(pw string) error

InitDatabase sets up the system site and admin user.

func (*Database) IsSiteAdmin added in v0.9.0

func (db *Database) IsSiteAdmin(name, site string) bool

IsSiteAdmin returns true if the user is a site admin for the specified site.

func (*Database) RemoveGroupMember added in v0.2.0

func (db *Database) RemoveGroupMember(site, group, name string) error

RemoveGroupMember removes a user from a group.

func (*Database) RemoveGroupPermission added in v0.3.0

func (db *Database) RemoveGroupPermission(site, group, name string) error

func (*Database) RemoveProfile added in v0.2.0

func (db *Database) RemoveProfile(username, site string) error

RemoveProfile removes a user from a site.

func (*Database) RemoveSiteMember added in v0.2.0

func (db *Database) RemoveSiteMember(site, name string) error

RemoveSiteMember deletes a profile for a user.

func (*Database) SetPassword

func (db *Database) SetPassword(name, password string, c int) error

SetPassword sets the password.

func (*Database) ToggleSiteAdmin added in v0.2.0

func (db *Database) ToggleSiteAdmin(site, name string, on bool) error

ToggleSiteAdmin status of a user.

func (*Database) UpdatePermission added in v0.3.0

func (db *Database) UpdatePermission(name, description string) error

UpdatePermission updates a permission description.

func (*Database) UpdateProfile added in v0.2.0

func (db *Database) UpdateProfile(username, site, data string) error

UpdateProfile updates the profile for a user+site combination.

func (*Database) UpdateUser added in v0.3.0

func (db *Database) UpdateUser(name, newname, fullname, email string) error

UpdateUser with new details.

func (*Database) VerifyToken added in v0.8.0

func (db *Database) VerifyToken(username, token string) bool

VerifyToken against expiry.

type Group

type Group struct {
	ID   int64
	Name string
	Site string
}

Group has a name and site it belongs to.

type GroupList

type GroupList struct {
	// Groups on the site.
	Groups []Group `json:"groups"`
}

GroupList is returned from the list groups endpoint.

type Permission

type Permission struct {
	// ID is uthe unique identifier.
	ID int64
	// Name is the keyword of the permission.
	Name string
	// Description is optional.
	Description string
}

Permission is just a keyword with actual meaning defined by a client app.

type PermissionList added in v0.2.0

type PermissionList struct {
	Permissions []Permission `json:"permissions"`
}

PermissionList is a list of permissions.

type Profile

type Profile struct {
	// Site the profile is for.
	Site string
	// Data is a site-specific JSON structure.
	Data string
	// Groups for this site.
	Groups map[string]interface{}
}

Prfile for a user+site combination.

type Request

type Request map[string]string

Request contains the variables passed to endpoints.

type Site

type Site struct {
	// ID is auto-generated on insert.
	ID int64
	// Name is the domain name.
	Name string
}

Site is the struct for a domain.

type User

type User struct {
	// ID of the user (unique).
	ID int64 `json:"id"`
	// Name may be an e-mail address.
	Name string `json:"name"`
	// Fullname is the user's full name.
	Fullname string `json:"fullname,omitempty"`
	// Email is the user's e-mail address.
	Email string `json:"email"`
	// Password is a bcrypt hash.
	Password string `json:"password,omitempty"`
	// Profiles for different sites.
	Profile string `json:"profile,omitempty"`
	// Admin is true if the user is an admin.
	Admin bool `json:"admin,omitempty"`
}

User data contains the barebones login info and site membership.

func (*User) CheckPassword

func (u *User) CheckPassword(password string) bool

CheckPassword checks the password.

type UserList added in v0.2.0

type UserList struct {
	// Users is a list of users, possibly limited by search parameters.
	Users []User `json:"users"`
}

UserList is returned from lookup.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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