user

package
v0.0.0-...-3c2629f Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2019 License: BSD-3-Clause Imports: 20 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateKey = errors.New("Duplicate key")
	ErrInvalidKey   = errors.New("Invalid key")
	ErrKeyNotFound  = errors.New("Key not found")
)
View Source
var (
	ErrUserAlreadyExists = errors.New("user already exists")
	ErrUserNotFound      = errors.New("user not found")
)

Functions

func AddKey

func AddKey(username string, k map[string]string) error

AddKey adds new SSH keys to the list of user keys for the provided username.

Returns an error in case the user does not exist.

func Remove

func Remove(name string) error

Removes a user. Also removes it's associated keys from authorized_keys and repositories It handles user with repositories specially when: - a user has at least one repository:

  • if he/she is the only one with access to the repository, the removal will stop and return an error
  • if there are more than one user with access to the repository, gandalf will first revoke user's access and then remove the user permanently

- a user has no repositories: gandalf will simply remove the user

func RemoveKey

func RemoveKey(username, keyname string) error

RemoveKey removes the key from the database and from authorized_keys file.

If the user or the key is not found, returns an error.

func UpdateKey

func UpdateKey(username string, k Key) error

UpdateKey updates the content of the given key.

Types

type InvalidUserError

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

func (*InvalidUserError) Error

func (err *InvalidUserError) Error() string

type Key

type Key struct {
	Name      string
	Body      string
	Comment   string
	UserName  string
	CreatedAt time.Time
}

func (*Key) String

func (k *Key) String() string

type KeyList

type KeyList []Key

func ListKeys

func ListKeys(uName string) (KeyList, error)

ListKeys lists all user's keys.

If the user is not found, returns an error

func (KeyList) MarshalJSON

func (keys KeyList) MarshalJSON() ([]byte, error)

type User

type User struct {
	Name string `bson:"_id"`
}

func New

func New(name string, keys map[string]string) (*User, error)

Creates a new user and write his/her keys into authorized_keys file.

The authorized_keys file belongs to the user running the process.

Jump to

Keyboard shortcuts

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