users

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package users reads and writes the OpenArch users file (config/users.yml).

OpenArch has no API to manage users: it reads this file once, at startup. The admin entry belongs to the workspace (its password is in .env.local). Other users and groups are kept as they are when the file is written again.

Index

Constants

View Source
const (
	AdminID             = "00000000-0000-0000-0000-000000000001"
	AdministratorsGroup = "administrators"
	MembersGroup        = "members"
)

Fixed ids, the same as in the users file bundled in the OpenArch image.

View Source
const Path = "config/users.yml"

Path is the users file in a workspace.

Variables

This section is empty.

Functions

func Hash

func Hash(password string) (string, error)

Hash returns the users file form of a password hash.

func HashOf

func HashOf(password string) string

HashOf returns the bcrypt hash of a users file password, or "" when it is not bcrypt.

func NewID

func NewID() string

NewID returns a random UUID (version 4).

func Save

func Save(dir string, f File) error

Save writes the users file of a workspace. It is not secret: it holds only hashes.

func ValidateUsername

func ValidateUsername(name string) error

ValidateUsername checks a new user name.

Types

type File

type File struct {
	AdministratorsGroups []string `yaml:"administratorsGroups"`
	Groups               []Group  `yaml:"groups"`
	Users                []User   `yaml:"users"`
}

File is the content of the users file.

func Build

func Build(adminUser, adminHash string, old File) File

Build returns the users file with the workspace admin, plus the other users and groups of old (which may be the zero File).

func Load

func Load(dir string) (File, error)

Load reads the users file of a workspace. A missing file is the zero File.

func Parse

func Parse(data []byte) (File, error)

Parse decodes a users file.

func (*File) EnsureGroup

func (f *File) EnsureGroup(name string)

EnsureGroup adds a group with a new id when f does not have it.

func (File) Find

func (f File) Find(username string) int

Find returns the index of a user, or -1.

func (File) IsAdmin

func (f File) IsAdmin(u User) bool

IsAdmin reports whether u is in an administrators group.

func (File) Marshal

func (f File) Marshal() []byte

Marshal encodes f with a header comment.

type Group

type Group struct {
	ID   string `yaml:"id" json:"id"`
	Name string `yaml:"name" json:"name"`
}

Group is a group of the users file.

type User

type User struct {
	ID         string            `yaml:"id" json:"id"`
	Username   string            `yaml:"username" json:"username"`
	Password   string            `yaml:"password" json:"-"`
	FirstName  string            `yaml:"firstName,omitempty" json:"firstName,omitempty"`
	LastName   string            `yaml:"lastName,omitempty" json:"lastName,omitempty"`
	Email      string            `yaml:"email,omitempty" json:"email,omitempty"`
	Groups     []string          `yaml:"groups" json:"groups"`
	Attributes map[string]string `yaml:"attributes,omitempty" json:"attributes,omitempty"`
}

User is a user of the users file. Password is "{bcrypt}<hash>".

Jump to

Keyboard shortcuts

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