access: Restruct Access internal data struct.
Now data struct is represented with two maps, one for users lookup throught key fingerprint, one for patterns and its permissions indexed by user name.
Globals were dropped from the struct, since it's only needed while parsing, no point to keep it there.
Groups were dropped and has no special meaning for authentication struct anymore, it's just a sugar to slice of users.
packageaccess
import(
"bufio"
"bytes"
"fmt"
"io"
"os"
"path/filepath"
"sync"
"github.com/go-yaml/yaml"
log"github.com/sirupsen/logrus"
"golang.org/x/crypto/ssh"
)
const(
// AccessFile is the base name of an access control file.
AccessFile="access.yml"
// KeysDir is the base name of directory holding public keys
KeysDir="keys"
)
const(
// Public is a reserved hgkeeper name and is not valid in the patterns
// or keys of an access file.
Public="public"
)
varpublicBytes=[]byte(Public)
// set once at Init, after that it may stay read-only
var(
accessFilestring
keysDirstring
reposDirstring
)
type(
groupsmap[string][]string
permissions[numPerms][]string
)
// Access represents a parsed access file.
typeAccessstruct{
// keysMu controls access to the patterns map
keysMusync.RWMutex
// keys holds all users indexed by key fingerprint
keysmap[string]string
// usersMu controls access to the patterns map
usersMusync.RWMutex
// users holds its patterns permissions indexed
// by user name
usersmap[string]map[string]Perm
}
// parse calls inderectly UnmarshalYAML, it's caller's duty to control the access to a.
func(a*Access)parse(rio.Reader)error{
returnyaml.NewDecoder(r).Decode(a)
}
// UnmarshalYAML unmarshals access yaml into an internal access