models

package
v0.0.0-...-96fe679 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2014 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const TokenDuration = 1 * time.Hour

TokenDuration is the default token expiration time

Variables

View Source
var OwnerPattern = `[a-zA-Z0-9\._]{4,30}`

OwnerPattern is a regexp for matching and validating repository owners

View Source
var RepositoryPattern = `[a-zA-Z0-9\._]{4,30}`

RepositoryPattern is a regexp that can be used for matching and validating repository names.

View Source
var TokenPattern = `[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}`

TokenPattern is a regexp pattern that can be used for matching tokens (UUIDs)

Functions

This section is empty.

Types

type Image

type Image struct {
	ID              bson.ObjectId `bson:"_id,omitempty"`
	Identifier      string        `json:"id"`
	Checksum        string
	Author          string
	Parent          string
	Created         time.Time
	Container       string
	DockerVersion   string
	Tag             string
	Architecture    string
	OperatingSystem string
	Size            int64
	Config          interface{} `json:"config"`
	ContainerConfig interface{} `json:"container_config"`
}

Image stores a Docker image and it's checksum

func LoadImage

func LoadImage(session *mgo.Session, identifier string) (*Image, error)

LoadImage loads an image from the database based on the provided identifier. Returns the loaded image if successful otherwise returns an error.

func (*Image) Create

func (i *Image) Create(session *mgo.Session) error

Create saves the image to the database

func (*Image) Exists

func (i *Image) Exists(session *mgo.Session) bool

Exists checks if an image already exists in our database

func (*Image) Update

func (i *Image) Update(session *mgo.Session) error

Update is just a semantic shortcut to create, as create uses an upsert anyway

type Organisation

type Organisation struct {
	ID   bson.ObjectId `bson:"_id,omitempty"`
	Path string
	Name string
}

func (*Organisation) GetID

func (o *Organisation) GetID() bson.ObjectId

func (*Organisation) String

func (o *Organisation) String() string

type Owner

type Owner interface {
	GetID() bson.ObjectId
	fmt.Stringer
}

Owner is somebody who can access a repository. Either a user, or maybe in the future an organisation.

func LoadOwnerByID

func LoadOwnerByID(session *mgo.Session, id bson.ObjectId) (Owner, error)

LoadOwner loads an owner from either a username or organisation name

func LoadOwnerByName

func LoadOwnerByName(session *mgo.Session, name string) (Owner, error)

LoadOwner loads an owner from either a username or organisation name

type Repository

type Repository struct {
	ID       bson.ObjectId `bson:"_id,omitempty"`
	Created  time.Time
	Modified time.Time
	Public   bool
	Name     string
	Owner    bson.ObjectId `bson:"owner_id"`
	Images   []string
	Tags     map[string]string
}

Repository is a docker repository. It is owned by either a user or an organisation.

func LoadRepository

func LoadRepository(session *mgo.Session, owner Owner, name string) (*Repository, error)

LoadRepository loads a repository based on the provided owner and repository name

func NewRepository

func NewRepository(owner Owner, name string) *Repository

NewRepository creates a new repository object

func (*Repository) Create

func (r *Repository) Create(session *mgo.Session) error

Create saves a repository to the database

func (*Repository) Exists

func (r *Repository) Exists(session *mgo.Session) bool

Exists checks if a repository already exists

func (*Repository) String

func (r *Repository) String() string

String provides a textual representation of the repository

func (*Repository) Update

func (r *Repository) Update(session *mgo.Session) error

Update is a semantic shortcut to Create() as that just runs an upsert operation anyway

type Token

type Token struct {
	ID          bson.ObjectId `bson:"_id,omitempty"`
	Created     time.Time
	Modified    time.Time
	User        bson.ObjectId `bson:"user_id"`
	Path        string
	Signature   string
	ReadAccess  bool
	WriteAccess bool
	Expires     time.Time
}

Token provides access for a user to a repository

func LoadTokenBySignature

func LoadTokenBySignature(session *mgo.Session, signature string) (*Token, error)

LoadTokenBySignature loads a token from the database

func NewToken

func NewToken(user *User, path string, db *mgo.Session) (*Token, error)

NewToken creates a new access token for a given user + repository path. This will be automatically served by the Authenticate middleware.

func (*Token) String

func (t *Token) String() string

String returns the token ready to be placed in a HTTP header

type User

type User struct {
	ID              bson.ObjectId `bson:"_id,omitempty"`
	Created         time.Time
	Modified        time.Time
	Email           string
	Username        string
	Password        string
	StorageProvider int
	AwsAccessKey    string
	AwsSecretKey    string
	AwsBucket       string
	Organisations   []bson.ObjectId
}

User encapulates an authenticated user and is used by the various contexts/handlers

func AuthenticateUser

func AuthenticateUser(session *mgo.Session, username, password string) (*User, error)

AuthenticateUser loads a user from the database session provided, queryinng by username and verifies the password. Returns an error if the user is unable to be authenticated.

func LoadUser

func LoadUser(session *mgo.Session, id bson.ObjectId) (*User, error)

LoadUser fetches a user from the database based on it's ObjectId

func (*User) Create

func (u *User) Create(session *mgo.Session) error

Create creates a new user in the database via the provided Mongo session

func (*User) EncryptPassword

func (u *User) EncryptPassword() error

EncryptPassword converts a plaintext password (as delivered by the 'docker login' program) to a bcrypted one, ready for storing in our DB.

func (*User) Exists

func (u *User) Exists(session *mgo.Session) bool

Exists checks if a user exists in the database via the provided Mongo session

func (*User) GetAccessToken

func (u *User) GetAccessToken(session *mgo.Session, path string) (*Token, error)

GetAccessToken fetches a previously created token that allows this user access to the provided repository path - if it finds a valid one in the database that hasn't expired.

func (*User) GetID

func (u *User) GetID() bson.ObjectId

GetID is a helper function that satisfies the Owner interface

func (*User) GetOrganisations

func (u *User) GetOrganisations(session *mgo.Session) (*[]Organisation, error)

GetOrganisations returns the organisations that this user is a member of

func (*User) GetStorageProvider

func (u *User) GetStorageProvider() storage.StorageProvider

GetStorageProvider fetches a storage provider configured to the user's preference (eg: AWS S3)

func (*User) String

func (u *User) String() string

String prints a textual representation of the user

func (*User) Validate

func (u *User) Validate(session *mgo.Session) error

Validate checks that a user meets the following requirements as defined bny the Docker Registry & Index Spec * Username minimum of 4 characters * Username must match [a-z0-9]{4,30} * Username/email not already in use * Password between 5-30 characters

Jump to

Keyboard shortcuts

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