ch

package
v3.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ch

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

Ch is used to chmod and chown files such that they match their desired group.

func New

func New(pc PathChecker, logger log15.Logger) *Ch

New returns a Ch what will check your pc callback to see what work needs to be done on the paths this Ch will receive when Do() is called on it.

Changes made will be logged to the given logger.

func (*Ch) Do

func (c *Ch) Do(path string, info fs.FileInfo) error

Do is a github.com/wtsi-ssg/wrstat/stat Operation that passes path to our PathCheck callback, and if it returns true, does the following chmod and chown-type behaviours, making use of the supplied Lstat info to avoid doing unnecessary repeated work:

1. Ensures that the GID of the path is the returned GID. 2. If path is a directory, ensures it has setgid applied (group sticky). 3. Ensures that User execute permission is set if group execute was set. 4. Ensures that group permissions match user permissions. 5. Forces user and group read and writeability.

Any errors are returned without logging them, except for "not exists" errors which are silently ignored since these are expected.

Any changes we do on disk are logged to our logger.

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type GIDFromSubDir

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

GIDFromSubDir provides a PathChecker that can decide if a path should be looked at based on matching a prefix followed by a certain sub directory (lookupDir or directDir), and also decides what the GID of that path should be based on the sub dir of that sub dir.

For subdirs of lookup directories, it that converts from directory name to desired unix group name using the lookup, then gets the GID for that unix group.

For subdirs of direct directories, it treats the directory name as a unix group name, and gets the GID of that unix group. You can supply exceptions where your own GID is used instead.

With prefixes: "/disk1", "/disk2/sub", "/disk3"

And a lookupDir of "teams" and a directDir of "projects"

And lookup: "ay": "dee"

And exceptions: "cee": 12345

Given the paths: 1) /disk1/teams/ay/file1.txt 2) /disk2/sub/projects/bee/file2.txt 3) /disk2/sub/projects/cee/file3.txt 4) /disk3/file4.txt 5) /disk1/teams/new/file5.txt 6) /disk2/sub/projects/not_a_unix_group_name/file6.txt

The .PathChecker() will return the following for each file: 1) true, [gid of unix group dee] 2) true, [gid of unix group bee] 3) true, 12345 4) false, n/a 5) false, n/a [and logs an error that "new" wasn't a known lookup] 6) false, n/a [and logs an error that "not_a_unix_group_name" has no GID].

func NewGIDFromSubDir

func NewGIDFromSubDir(prefixes []string, lookupDir string, lookup map[string]string,
	directDir string, exceptions map[string]int, logger log15.Logger) (*GIDFromSubDir, error)

NewGIDFromSubDir returns a GIDFromSubDir.

prefixes are absolute paths to directories that our PathChecker will return true for if the path matches a prefix and also contains a subdirectory named [lookupDir] or [directDir], and the path is for an entry located within a further subdirectory of that.

lookupDir is the name of a subdirectory of the prefix paths that contains further subdirectories that are keys in the given lookup map. The values in the map are the desired unix group names, which will be converted to GIDs.

directDir is the name of a subdirectory of the prefix paths that contains further subdirectories that are named after unix group names. Or their name is a key in the exceptions map, and the corresponding value will be the GID used. NB. unix group name to GID lookups are cached in the supplied exceptions map.

If lookupDir contains a subdirectory that isn't in your lookup, or directDir contains a subdirectory that isn't in your exceptions and isn't a unix group name, these issues are logged to the given logger, and the PathChecker will return false.

func NewGIDFromSubDirFromYAML

func NewGIDFromSubDirFromYAML(data []byte, logger log15.Logger) (*GIDFromSubDir, error)

NewGIDFromSubDirFromYAML is like NewGIDFromSubDir, but instead of supplying all the different args, you supply it YAML data in the following format:

prefixes: ["/disk1", "/disk2/sub", "/disk3"] lookupDir: subdir_name_of_prefixes_that_contains_subdirs_in_lookup lookup:

foo: unix_group_name

directDir: subdir_of_prefixes_with_unix_group_or_exception_subdirs exceptions:

bar: GID

func (*GIDFromSubDir) PathChecker

func (f *GIDFromSubDir) PathChecker() PathChecker

PathChecker returns a PathChecker that can be used with a Ch.

type PathChecker

type PathChecker func(path string) (change bool, gid int)

PathChecker is a callback used by Ch that will receive the absolute path to a file or directory and should return a boolean if this path is eligible for changing, and the desired group ID of this path.

Jump to

Keyboard shortcuts

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