server

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// EndPointWhere is the endpoint for making where queries if authorization
	// isn't implemented.
	EndPointWhere = gas.EndPointREST + wherePath

	// EndPointAuthWhere is the endpoint for making where queries if
	// authorization is implemented.
	EndPointAuthWhere = gas.EndPointAuth + wherePath

	// EndPointAuthGroupAreas is the endpoint for making queries on what the
	// group areas are, which is available if authorization is implemented.
	EndPointAuthGroupAreas = gas.EndPointAuth + groupAreasPaths

	// TreePath is the path to the static tree website.
	TreePath = "/tree"

	// EndPointAuthTree is the endpoint for making treemap queries when
	// authorization is implemented.
	EndPointAuthTree = gas.EndPointAuth + TreePath
)
View Source
const ErrBadQuery = gas.Error("bad query; check dir, group, user and type")
View Source
const ErrNoDgutDBDirFound = gas.Error("dgut database directory not found")

Variables

This section is empty.

Functions

func FindLatestDgutDirs

func FindLatestDgutDirs(dir, suffix string) ([]string, error)

FindLatestDgutDirs finds the latest subdirectory of dir that has the given suffix, then returns that result's child directories.

func GetGroupAreas

func GetGroupAreas(url, cert, jwt string) (map[string][]string, error)

GetGroupAreas is a client call to a Server listening at the given domain:port url that queries its configured group area information. The returned map has area keys and group slices.

Provide a non-blank path to a certificate to force us to trust that certificate, eg. if the server was started with a self-signed certificate.

You must first Login() to get a JWT that you must supply here.

Types

type DirSummary

type DirSummary struct {
	Dir       string
	Count     uint64
	Size      uint64
	Atime     time.Time
	Users     []string
	Groups    []string
	FileTypes []string
}

DirSummary holds nested file count, size and atime information on a directory. It also holds which users and groups own files nested under the directory, and their file types. It differs from dgut.DirSummary in having string names for users, groups and types, instead of ids.

func GetWhereDataIs

func GetWhereDataIs(url, cert, jwt, dir, groups, users, types, splits string) ([]byte, []*DirSummary, error)

GetWhereDataIs is a client call to a Server listening at the given domain:port url that queries where data is and returns the raw response body (JSON string), and that body converted in to a slice of *DirSummary.

Provide a non-blank path to a certificate to force us to trust that certificate, eg. if the server was started with a self-signed certificate.

You must first Login() to get a JWT that you must supply here.

The other parameters correspond to arguments that dgut.Tree.Where() takes.

type Server

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

Server is used to start a web server that provides a REST API to the dgut package's database, and a website that displays the information nicely.

func New

func New(logWriter io.Writer) *Server

New creates a Server which can serve a REST API and website.

It logs to the given io.Writer, which could for example be syslog using the log/syslog pkg with syslog.new(syslog.LOG_INFO, "tag").

func (*Server) AddGroupAreas

func (s *Server) AddGroupAreas(areas map[string][]string)

AddGroupAreas takes a map of area keys and group slice values. Clients will then receive this map on TreeElements in the "areas" field.

If EnableAuth() has been called, also creates the /auth/group-areas endpoint that returns the given value.

func (*Server) AddTreePage

func (s *Server) AddTreePage() error

AddTreePage adds the /tree static web page to the server, along with the /rest/v1/auth/tree endpoint. It only works if EnableAuth() has been called first.

func (*Server) EnableDGUTDBReloading

func (s *Server) EnableDGUTDBReloading(watchPath, dir, suffix string, pollFrequency time.Duration) error

EnableDGUTDBReloading will wait for changes to the file at watchPath, then:

  1. close any previously loaded dgut database files
  2. find the latest sub-directory in the given directory with the given suffix
  3. set the dgut.db directory paths to children of 2) and load those
  4. delete the old dgut.db directory paths to save space, and their parent dir if now empty
  5. update the server's data-creation date to the mtime of the watchPath file

It will also do 5) immediately on calling this method.

It will only return an error if trying to watch watchPath immediately fails. Other errors (eg. reloading or deleting files) will be logged.

func (*Server) LoadDGUTDBs

func (s *Server) LoadDGUTDBs(paths ...string) error

LoadDGUTDBs loads the given dgut.db directories (as produced by one or more invocations of dgut.DB.Store()) and adds the /rest/v1/where GET endpoint to the REST API. If you call EnableAuth() first, then this endpoint will be secured and be available at /rest/v1/auth/where.

The where endpoint can take the dir, splits, groups, users and types parameters, which correspond to arguments that dgut.Tree.Where() takes.

func (*Server) WhiteListGroups

func (s *Server) WhiteListGroups(wcb WhiteListCallback)

WhiteListGroups sets the given callback on the server, which will now be used to check if any of the groups that a user belongs to have been whitelisted, giving that user unrestricted access to know about all groups.

Do NOT call this more than once or after the server has started responding to client queries.

type TreeElement

type TreeElement struct {
	Name        string              `json:"name"`
	Path        string              `json:"path"`
	Count       uint64              `json:"count"`
	Size        uint64              `json:"size"`
	Atime       string              `json:"atime"`
	Users       []string            `json:"users"`
	Groups      []string            `json:"groups"`
	FileTypes   []string            `json:"filetypes"`
	HasChildren bool                `json:"has_children"`
	Children    []*TreeElement      `json:"children,omitempty"`
	TimeStamp   string              `json:"timestamp"`
	Areas       map[string][]string `json:"areas"`
}

TreeElement holds tree.DirInfo type information in a form suited to passing to the treemap web interface. It also includes the server's dataTimeStamp so interfaces can report on how long ago the data forming the tree was captured.

type WhiteListCallback

type WhiteListCallback func(gid string) bool

WhiteListCallback is passed to WhiteListGroups() and is used by the server to determine if a given unix group ID is special, indicating that users belonging to it have permission to view information about all other unix groups. If it's a special group, return true; otherwise false.

Jump to

Keyboard shortcuts

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