Documentation

Overview

Package `bcpcfg` contains a reader for a config file that describes the filesystem setup for a service facility tree and a research unit tree.

The file format uses HCL <https://github.com/hashicorp/hcl>.

`cmd/bcpfs-perms/generic-example-bcpfs.hcl` contains an example file with the available settings documented.

Use `Load()` to load a config file. Then use package `grp` to parse the available Unix groups and package `bcp` to combine the groups and the config and obtain a struct that represents the organization.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirWithPolicy

type DirWithPolicy struct {
	Name   string `hcl:"name"`
	Policy string `hcl:"policy"`
}

type Facility

type Facility struct {
	Name     string   `hcl:"name"`
	Services []string `hcl:"services"`
	Access   string   `hcl:"access"`
}

type FilterRule

type FilterRule struct {
	Services []string
	OrgUnits []string
	Action   string
}

func ValidateFilterRule

func ValidateFilterRule(r FilterRuleCfg) (rule FilterRule, err error)
Example

Code:

package main

import (
	"fmt"
	"github.com/nogproject/bcpfs/cmd/bcpfs-perms/bcpcfg"
)

func main() {
	srvOrg := "mic"
	srvOrgs := []string{"lab1", "lab2"}
	action := "accept"
	srvOrgEmpty := ""
	srvOrgsEmpty := []string{}
	actionWrong := "acceptt"

	var r bcpcfg.FilterRule
	var err error

	_, err = bcpcfg.ValidateFilterRule(bcpcfg.FilterRuleCfg{
		Service:  srvOrg,
		Services: srvOrgsEmpty,
		OrgUnit:  srvOrg,
		OrgUnits: srvOrgsEmpty,
		Action:   actionWrong,
	})
	fmt.Println(err)

	_, err = bcpcfg.ValidateFilterRule(bcpcfg.FilterRuleCfg{
		Service:  srvOrgEmpty,
		Services: srvOrgsEmpty,
		OrgUnit:  srvOrg,
		OrgUnits: srvOrgsEmpty,
		Action:   action,
	})
	fmt.Println(err)

	_, err = bcpcfg.ValidateFilterRule(bcpcfg.FilterRuleCfg{
		Service:  srvOrg,
		Services: srvOrgs,
		OrgUnit:  srvOrg,
		OrgUnits: srvOrgsEmpty,
		Action:   action,
	})
	fmt.Println(err)

	_, err = bcpcfg.ValidateFilterRule(bcpcfg.FilterRuleCfg{
		Service:  srvOrg,
		Services: srvOrgsEmpty,
		OrgUnit:  srvOrgEmpty,
		OrgUnits: srvOrgsEmpty,
		Action:   action,
	})
	fmt.Println(err)

	_, err = bcpcfg.ValidateFilterRule(bcpcfg.FilterRuleCfg{
		Service:  srvOrg,
		Services: srvOrgsEmpty,
		OrgUnit:  srvOrg,
		OrgUnits: srvOrgs,
		Action:   action,
	})
	fmt.Println(err)

	r, _ = bcpcfg.ValidateFilterRule(bcpcfg.FilterRuleCfg{
		Service:  srvOrg,
		Services: srvOrgsEmpty,
		OrgUnit:  srvOrgEmpty,
		OrgUnits: srvOrgs,
		Action:   action,
	})
	fmt.Println(r)

}
Invalid action!
No service defined!
Use either `service` or `services`!
No orgUnit defined!
Use either `orgUnit` or `orgUnits`!
{[mic] [lab1 lab2] accept}

type FilterRuleCfg

type FilterRuleCfg struct {
	Service  string   `hcl:"service"`
	Services []string `hcl:"services"`
	OrgUnit  string   `hcl:"orgUnit"`
	OrgUnits []string `hcl:"orgUnits"`
	Action   string   `hcl:"action"`
}

type OrgUnit

type OrgUnit struct {
	Name    string          `hcl:"name"`
	Subdirs []DirWithPolicy `hcl:"subdirs"`
	// `ExtraDirs` is kept for compatibility; prefer `Subdirs`; see NOE-11.
	ExtraDirs []string `hcl:"extraDirs"`
}

type Root

type Root struct {
	Rootdir        string       `hcl:"rootdir"`
	ServiceDir     string       `hcl:"serviceDir"`
	OrgUnitDir     string       `hcl:"orgUnitDir"`
	SuperGroup     string       `hcl:"superGroup"`
	OrgUnitPrefix  string       `hcl:"orgUnitPrefix"`
	ServicePrefix  string       `hcl:"servicePrefix"`
	OpsSuffix      string       `hcl:"opsSuffix"`
	FacilitySuffix string       `hcl:"facilitySuffix"`
	Facilities     []Facility   `hcl:"-"`
	OrgUnits       []OrgUnit    `hcl:"-"`
	Filter         []FilterRule `hcl:"-"`
	Symlinks       []Symlink    `hcl:"-"`
	Sharing        *Sharing     `hcl:"-" yaml:",omitempty"`
}

`Root` contains the filesystem config. See example `generic-example-bcpfs.hcl` for a description of the available settings.

The `hcl:"<key>"` fields are handled by the HCL decoder. The ignored `hcl:"-"` fields are explicitly decoded in `Parse()`.

func Load

func Load(path string) (*Root, error)

`Load()` loads a config from `path`.

func Parse

func Parse(d string) (*Root, error)

`Parse()` parses the config from a string. External users usually should use `Load()`.

type Sharing

type Sharing struct {
	NamingPolicies []SharingNamingPolicy `hcl:"-" yaml:"namingPolicies"`
	Exports        []SharingExport       `hcl:"-" yaml:"exports"`
	Imports        []SharingImport       `hcl:"-" yaml:"imports"`
}

type SharingExport

type SharingExport struct {
	Path string   `hcl:"path" yaml:"path"`
	Acl  []string `hcl:"acl" yaml:"acl"`
}

type SharingImport

type SharingImport struct {
	Action string `hcl:"action" yaml:"action"`
	Group  string `hcl:"group" yaml:"group"`
	Match  string `hcl:"match" yaml:"match"`
}

type SharingNamingPolicy

type SharingNamingPolicy struct {
	Action string `hcl:"action" yaml:"action"`
	Match  string `hcl:"match" yaml:"match"`
}
type Symlink struct {
	Path   string `hcl:"path"`
	Target string `hcl:"target"`
}

Source Files