Documentation ¶
Index ¶
- type Favourite
- type Image
- type ImageInfo
- type ImageInfoList
- type ImageLayer
- type ImageList
- type ImageVersion
- type IsFavourite
- type IsNotification
- type License
- type Notification
- type NotificationList
- type NotificationMessage
- type NotificationMessageChanges
- type NotificationStatus
- type PgDB
- func (d *PgDB) CheckUserHasImagePermission(u *User, i *Image) (bool, error)
- func (d *PgDB) CheckUserImagePermission(u *User, imageName string) (result bool, err error)
- func (d *PgDB) CheckUserInspectionStatus(userID uint, namespace string, images []hub.ImageInfo) ([]hub.ImageInfo, error)
- func (d *PgDB) CreateNotification(user User, notify Notification) (Notification, error)
- func (d *PgDB) CreateNotificationMessage(msg *NotificationMessage) error
- func (d *PgDB) DeleteFavourite(user User, image string) error
- func (d *PgDB) DeleteImage(image string) (err error)
- func (d *PgDB) DeleteNotification(user User, id int) error
- func (d *PgDB) DeleteUserImagePermission(userID uint, image string) (err error)
- func (d *PgDB) DeleteUserRegistryCredential(registryID string, userID uint) (err error)
- func (d *PgDB) Exec(cmd string, params ...interface{})
- func (d *PgDB) FeatureImage(image string, featured bool) (err error)
- func (d *PgDB) GetAllImageVersions(img Image) (ivlist []ImageVersion, err error)
- func (d *PgDB) GetAllImageVersionsWithManifests(img Image) (ivlist []ImageVersion, err error)
- func (d *PgDB) GetBadgesInstalledCount() (badges int, images int, err error)
- func (d *PgDB) GetFavourite(user User, image string) (bool, error)
- func (d *PgDB) GetFavourites(user User) ImageList
- func (d *PgDB) GetFeaturedImages() ImageList
- func (d *PgDB) GetImage(image string) (img Image, err error)
- func (d *PgDB) GetImageForUser(image string, u *User) (img Image, permission bool, err error)
- func (d *PgDB) GetImageVersionBySHA(SHA string, image string, isPrivate bool) (iv ImageVersion, err error)
- func (d *PgDB) GetImageVersionByTag(image string, tag string) (iv ImageVersion, err error)
- func (d *PgDB) GetImageVersions(img Image) (ivlist []ImageVersion, err error)
- func (d *PgDB) GetImageVersionsByHash(hash string, SHA string, imageName string) (ivs []ImageVersion, err error)
- func (d *PgDB) GetLabelSchemaImageCount() int
- func (d *PgDB) GetLabelSchemaImages(pageNum int) ImageList
- func (d *PgDB) GetNotification(user User, id int) (notify Notification, err error)
- func (d *PgDB) GetNotificationCount(user User) (count int, err error)
- func (d *PgDB) GetNotificationForUser(user User, image string) (bool, Notification)
- func (d *PgDB) GetNotificationHistory(id int, image string, count int) (history []NotificationMessage, err error)
- func (d *PgDB) GetNotificationMessage(id uint) (NotificationMessage, error)
- func (d *PgDB) GetNotifications(user User) (list NotificationList, err error)
- func (d *PgDB) GetNotificationsForImage(imageName string) (n []Notification, err error)
- func (d *PgDB) GetOrCreateImage(image string) (img Image, err error)
- func (d *PgDB) GetOrCreateUser(existingUser User, gothUser goth.User) (u User, err error)
- func (d *PgDB) GetOrCreateUserImagePermission(userID uint, imageName string) (uip UserImagePermission, err error)
- func (d *PgDB) GetOrCreateUserRegistryCredential(registryID string, userID uint) (urc UserRegistryCredential, err error)
- func (d *PgDB) GetPageURL(image Image) (pageURL string)
- func (d *PgDB) GetRecentImages() ImageList
- func (d *PgDB) GetRegistry(id string) (reg *Registry, err error)
- func (d *PgDB) GetRegistryCredentialsForImage(imageName string) (registryCreds []UserRegistryCredential, err error)
- func (d *PgDB) GetTags(iv *ImageVersion) (tags []Tag, err error)
- func (d *PgDB) GetTagsList(iv *ImageVersion) (tags []Tag, err error)
- func (d *PgDB) GetUserEnabledImageCount(userID uint) (count int, err error)
- func (d *PgDB) GetUserImagePermission(userID uint, imageName string) (uip UserImagePermission, err error)
- func (d *PgDB) GetUserRegistries(userID uint) (registries []Registry, err error)
- func (d *PgDB) GetUserRegistryCredential(registryID string, userID uint) (urc UserRegistryCredential, err error)
- func (d *PgDB) GetUserSetting(user User) (us UserSetting, err error)
- func (d *PgDB) ImageSearch(search string) (images []string, err error)
- func (d *PgDB) ImageVersionNeedsSizeOrLayers(iv *ImageVersion) bool
- func (d *PgDB) PutFavourite(user User, image string) (fav Favourite, err error)
- func (d *PgDB) PutImage(img Image) (nmc NotificationMessageChanges, err error)
- func (d *PgDB) PutImageOnly(img Image) error
- func (d *PgDB) PutImageVersion(iv ImageVersion) (err error)
- func (d *PgDB) PutRegistry(reg *Registry) error
- func (d *PgDB) PutUserRegistryCredential(urc UserRegistryCredential) (err error)
- func (d *PgDB) PutUserSetting(us UserSetting) (err error)
- func (d *PgDB) SaveNotificationMessage(nm *NotificationMessage) error
- func (d *PgDB) UpdateNotification(user User, id int, input Notification) (Notification, error)
- type PostgresJSON
- type Registry
- type RegistryList
- type Tag
- type User
- type UserAuth
- type UserImagePermission
- type UserRegistryCredential
- type UserSetting
- type VersionControl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Favourite ¶
type Favourite struct { User User UserID uint `gorm:"primary_key"` ImageName string `gorm:"primary_key" sql:"REFERENCES images(name) ON DELETE RESTRICT"` }
Favourite is an image that a user wanted to keep track of
type Image ¶
type Image struct { // Fields managed by gorm Name string `gorm:"primary_key" json:"-"` Status string `json:"-"` Featured bool `json:"-"` Latest string `sql:"REFERENCES image_versions(sha) ON DELETE RESTRICT" json:"LatestSHA"` BadgeCount int `json:"-"` // Number of badges we can generate for this image AuthToken string `json:"-"` WebhookURL string `gorm:"column:web_hook_url" json:",omitempty"` CreatedAt time.Time `json:"-"` // Auto-updated UpdatedAt time.Time `json:"UpdatedAt"` // Auto-updated - This is used to show when we last inspected the image Description string `json:",omitempty"` IsPrivate bool `json:"-"` IsAutomated bool `json:"-"` LastUpdated time.Time `json:",omitempty"` // This is what the hub API tells us BadgesInstalled int `json:"-"` // Number of badges for this image we have found (so far we only look on Docker Hub) PullCount int StarCount int // Gorm auto-updating doesn't work well as we have our own primary key, so we handle this ourselves Versions []ImageVersion `gorm:"-" json:",omitempty"` // These are json-only fields that are copied from the latest version // TODO We could move more of these to ImageVersion ID string `gorm:"-" json:"Id,omitempty"` // SHA from latest version ImageName string `gorm:"-" json:",omitempty"` // Name but with library removed for base images ImageURL string `gorm:"-" json:",omitempty"` Author string `gorm:"-" json:",omitempty"` LayerCount int `gorm:"-" json:",omitempty"` DownloadSize int64 `gorm:"-" json:",omitempty"` Labels map[string]string `gorm:"-" json:",omitempty"` LatestTag string `gorm:"-" json:"LatestVersion,omitempty"` }
Image is an image
type ImageInfoList ¶
ImageInfo returns lists of images with pagination
type ImageLayer ¶
type ImageLayer struct { BlobSum string `gorm:"-"` // TODO! We need this in API for calculating hashes, but we don't want it travelling on the API Command string `gorm:"-" json:"Command"` DownloadSize int64 `gorm:"-" json:"DownloadSize"` }
ImageLayer is the detail of layers that make up an image version. TODO!! Consider storing these so we can pull them and store the details
type ImageList ¶
type ImageList struct { CurrentPage int `json:",omitempty"` PageCount int `json:",omitempty"` ImageCount int `json:",omitempty"` Images []string `json:",omitempty"` }
ImageList is used to send a list of images on the API. TODO We should probably move everything to use ImageInfoList
type ImageVersion ¶
type ImageVersion struct { SHA string `gorm:"primary_key"` Tags []Tag `json:"Tags"` ImageName string `gorm:"primary_key" sql:"REFERENCES images(name) ON DELETE RESTRICT"` Author string `` Labels string `json:"-"` LabelMap map[string]string `gorm:"-" json:"Labels,omitempty"` LayerCount int `sql:"DEFAULT:0"` DownloadSize int64 `sql:"DEFAULT:0"` Created time.Time // From Registry, tells us when this image version was created Layers string `json:"-"` LayersArray []ImageLayer `gorm:"-" json:"Layers,omitempty"` Manifest string `json:"-"` Hash string `gorm:"index" json:"-"` // Hash of the layers in this image Parents []ImageVersion `gorm:"-" json:",omitempty"` Identical []ImageVersion `gorm:"-" json:",omitempty"` MicrobadgerURL string `gorm:"-" json:",omitempty"` // JSON only fields for data parsed from the labels. License *License `gorm:"-" json:",omitempty"` VersionControl *VersionControl `gorm:"-" json:",omitempty"` }
ImageVersion is a version of an image
type IsFavourite ¶
type IsFavourite struct {
IsFavourite bool
}
type IsNotification ¶
type IsNotification struct { NotificationCount int NotificationLimit int Notification Notification }
IsNotification returns whether a notification exists as well as the current count and limit
type Notification ¶
type Notification struct { ID uint `json:",omitempty", gorm:"primary_key"` UserID uint `json:"-" gorm:"ForeignKey:UserID" sql:"REFERENCES users(id) ON DELETE RESTRICT"` ImageName string `json:",omitempty" gorm:"ForeignKey:ImageName" sql:"REFERENCES images(name) ON DELETE RESTRICT"` WebhookURL string `json:",omitempty"` PageURL string `json:",omitempty" gorm: "-"` HistoryArray []NotificationMessage `json:"History,omitempty", gorm:"-"` }
Notification is an image that a user wants to be notified when it changes
type NotificationList ¶
type NotificationList struct { NotificationCount int `gorm:"-"` NotificationLimit int `gorm:"-"` Notifications []NotificationStatus `gorm:"-"` }
NotificationList is a list of notifications with the count and limit for this user
type NotificationMessage ¶
type NotificationMessage struct { gorm.Model `json:"-"` NotificationID uint `json:"-" gorm:"ForeignKey:NotificationID" sql:"REFERENCES notifications(id) ON DELETE RESTRICT"` ImageName string `json:"-"` WebhookURL string Message PostgresJSON `gorm:"type:jsonb"` Attempts int StatusCode int Response string SentAt time.Time }
NotificationMessage is a message sent to a webhook
type NotificationStatus ¶
type NotificationStatus struct { ID int ImageName string WebhookURL string Message PostgresJSON StatusCode int Response string SentAt time.Time }
NotificationStatus is a notification with its most recently sent message
type PgDB ¶
type PgDB struct { SessionStore *gormstore.Store SiteURL string // contains filtered or unexported fields }
PgDB is our postgres database
func GetPostgres ¶
func GetPostgres(host string, user string, dbname string, password string, debug bool) (db PgDB, err error)
GetPostgres opens a database connection
func (*PgDB) CheckUserHasImagePermission ¶
CheckUserHasImagePermission checks whether the user has access
func (*PgDB) CheckUserImagePermission ¶
TODO!! Can we get to not needing this? CheckUserImagePermission checks whether the user has access
func (*PgDB) CheckUserInspectionStatus ¶
func (d *PgDB) CheckUserInspectionStatus(userID uint, namespace string, images []hub.ImageInfo) ([]hub.ImageInfo, error)
CheckUserInspectionStatus checks whether the images in this namespace have been inspected TODO!! Needs renaming as inspected is a bad name. Changed to enabled /disabled in the UI
func (*PgDB) CreateNotification ¶
func (d *PgDB) CreateNotification(user User, notify Notification) (Notification, error)
CreateNotification creates it
func (*PgDB) CreateNotificationMessage ¶
func (d *PgDB) CreateNotificationMessage(msg *NotificationMessage) error
CreateNotificationMessage saves whether a notification was sent successfully
func (*PgDB) DeleteFavourite ¶
DeleteFavourite deletes a favourite, returning an error if it doesn't exist
func (*PgDB) DeleteImage ¶
DeleteImage deletes it including all versions and tags
func (*PgDB) DeleteNotification ¶
DeleteNotification deletes a notification, returning an error if it doesn't exist
func (*PgDB) DeleteUserImagePermission ¶
DeleteUserImagePermission deletes it and the image if its not enabled by any other users TODO Will need updating when registry is added to images
func (*PgDB) DeleteUserRegistryCredential ¶
DeleteUserRegistryCredential deletes it and removes permission to all images TODO Will need updating when registry is added to images
func (*PgDB) GetAllImageVersions ¶
func (d *PgDB) GetAllImageVersions(img Image) (ivlist []ImageVersion, err error)
GetAllImageVersions returns all versions for this image, tagged or not
func (*PgDB) GetAllImageVersionsWithManifests ¶
func (d *PgDB) GetAllImageVersionsWithManifests(img Image) (ivlist []ImageVersion, err error)
GetAllImageVersionsWithManifests returns all versions for this image, tagged or not if they have manifest data. The manifest data is cleared once it has been processed.
func (*PgDB) GetBadgesInstalledCount ¶
GetBadgesInstalledCount tells us how many badges are installed, and how many images have badges installed. At the moment these are only taken from the full descriptions in Docker Hub. Badges for automated images are counted twice because they also appear in the user's GitHub readme.
func (*PgDB) GetFavourite ¶
GetFavourite returns true if this user favourited this image
func (*PgDB) GetFavourites ¶
GetFavourites returns a slice of image names that are favourites for this user
func (*PgDB) GetFeaturedImages ¶
GetFeaturedImages returns a list of images with the featured flag set
func (*PgDB) GetImage ¶
GetImage gets an image from the database. Error if it's not there Use GetImageForUser unless you are very sure this is what you want
func (*PgDB) GetImageForUser ¶
GetImageForUser gets an image from the database, checking that the user has permission. Error if it's not there
func (*PgDB) GetImageVersionBySHA ¶
func (*PgDB) GetImageVersionByTag ¶
func (d *PgDB) GetImageVersionByTag(image string, tag string) (iv ImageVersion, err error)
func (*PgDB) GetImageVersions ¶
func (d *PgDB) GetImageVersions(img Image) (ivlist []ImageVersion, err error)
GetImageVersions only returns versions that have a tag
func (*PgDB) GetImageVersionsByHash ¶
func (d *PgDB) GetImageVersionsByHash(hash string, SHA string, imageName string) (ivs []ImageVersion, err error)
GetImageVersionsByHash returns image versions that match this hash but not this SHA or image name
func (*PgDB) GetLabelSchemaImageCount ¶
func (*PgDB) GetLabelSchemaImages ¶
func (*PgDB) GetNotification ¶
func (d *PgDB) GetNotification(user User, id int) (notify Notification, err error)
GetNotification returns an image notification for this user
func (*PgDB) GetNotificationCount ¶
GetNotificationCount returns the number of notifications for a a user
func (*PgDB) GetNotificationForUser ¶
func (d *PgDB) GetNotificationForUser(user User, image string) (bool, Notification)
GetNotificationForUser returns true and the notification if it exists for this user and image
func (*PgDB) GetNotificationHistory ¶
func (d *PgDB) GetNotificationHistory(id int, image string, count int) (history []NotificationMessage, err error)
GetNotificationHistory returns a slice of the most recent notification messages
func (*PgDB) GetNotificationMessage ¶
func (d *PgDB) GetNotificationMessage(id uint) (NotificationMessage, error)
GetNotificationMessage saves whether a notification was sent successfully
func (*PgDB) GetNotifications ¶
func (d *PgDB) GetNotifications(user User) (list NotificationList, err error)
GetNotifications gets all image notifications for a user along with the most recently sent message
func (*PgDB) GetNotificationsForImage ¶
func (d *PgDB) GetNotificationsForImage(imageName string) (n []Notification, err error)
GetNotificationsForImage gets a list of notifications we need to make for this image
func (*PgDB) GetOrCreateImage ¶
GetOrCreateImage makes sure it's there
func (*PgDB) GetOrCreateUser ¶
GetOrCreateUser adds a user if they don't already exist TODO!! Finish and test adding multiple providers to the same user ID
func (*PgDB) GetOrCreateUserImagePermission ¶
func (d *PgDB) GetOrCreateUserImagePermission(userID uint, imageName string) (uip UserImagePermission, err error)
GetOrCreateUserImagePermission makes sure it's there
func (*PgDB) GetOrCreateUserRegistryCredential ¶
func (d *PgDB) GetOrCreateUserRegistryCredential(registryID string, userID uint) (urc UserRegistryCredential, err error)
GetOrCreateUserRegistryCredential makes sure it's there
func (*PgDB) GetPageURL ¶
GetPageURL returns the URL for the image on the MicroBadger site. TODO Support non Docker Hub registries
func (*PgDB) GetRecentImages ¶
GetRecentImages returns a list of public images with badges created in the last so-many days
func (*PgDB) GetRegistryCredentialsForImage ¶
func (d *PgDB) GetRegistryCredentialsForImage(imageName string) (registryCreds []UserRegistryCredential, err error)
GetRegistryCredentialsForImage gets auth creds for this image so it can be inspected
func (*PgDB) GetTagsList ¶
func (d *PgDB) GetTagsList(iv *ImageVersion) (tags []Tag, err error)
GetTagsList only fills in the tag name, so that when we pass the structure on the API it only includes the tags
func (*PgDB) GetUserEnabledImageCount ¶
GetUserEnabledImageCount returns how many enabled private images the user has
func (*PgDB) GetUserImagePermission ¶
func (d *PgDB) GetUserImagePermission(userID uint, imageName string) (uip UserImagePermission, err error)
GetUserImagePermission gets it
func (*PgDB) GetUserRegistries ¶
GetUserRegistries returns all registries and whether the user has saved credentials
func (*PgDB) GetUserRegistryCredential ¶
func (d *PgDB) GetUserRegistryCredential(registryID string, userID uint) (urc UserRegistryCredential, err error)
GetUserRegistryCredential gets it
func (*PgDB) GetUserSetting ¶
func (d *PgDB) GetUserSetting(user User) (us UserSetting, err error)
GetUserSetting returns extra user data that is not stored on the session.
func (*PgDB) ImageSearch ¶
ImageSearch returns the first 10 matching images ordered by number of pulls.
func (*PgDB) ImageVersionNeedsSizeOrLayers ¶
func (d *PgDB) ImageVersionNeedsSizeOrLayers(iv *ImageVersion) bool
Return true if either download size is 0 or layers is ” or the hash has not yet been calculated
func (*PgDB) PutFavourite ¶
PutFavourite saves it
func (*PgDB) PutImage ¶
func (d *PgDB) PutImage(img Image) (nmc NotificationMessageChanges, err error)
PutImage saves an image and its related image versions & tags
func (*PgDB) PutImageOnly ¶
PutImageOnly saves just the image, none of its related image versions or tags
func (*PgDB) PutImageVersion ¶
func (d *PgDB) PutImageVersion(iv ImageVersion) (err error)
func (*PgDB) PutRegistry ¶
func (*PgDB) PutUserRegistryCredential ¶
func (d *PgDB) PutUserRegistryCredential(urc UserRegistryCredential) (err error)
PutUserRegistryCredential saves it
func (*PgDB) PutUserSetting ¶
func (d *PgDB) PutUserSetting(us UserSetting) (err error)
PutUserSetting saves the extra user data
func (*PgDB) SaveNotificationMessage ¶
func (d *PgDB) SaveNotificationMessage(nm *NotificationMessage) error
SaveNotificationMessage updates an existing notification message
func (*PgDB) UpdateNotification ¶
func (d *PgDB) UpdateNotification(user User, id int, input Notification) (Notification, error)
UpdateNotification updates it
type PostgresJSON ¶
type PostgresJSON struct {
json.RawMessage
}
Implement sql.Scanner interface to save a json.RawMessage to the database
func (*PostgresJSON) Scan ¶
func (j *PostgresJSON) Scan(src interface{}) error
type Registry ¶
type Registry struct { ID string `gorm:"primary_key"` Name string Url string CredentialsName string `gorm:"-"` }
Registry is a supported docker registry
type RegistryList ¶
RegistryList lists the registries
type Tag ¶
type Tag struct { Tag string `gorm:"primary_key" json:"tag"` ImageName string `gorm:"primary_key" json:"-" sql:"REFERENCES images(name) ON DELETE RESTRICT" ` SHA string `gorm:"index" json:",omitempty" sql:"REFERENCES image_versions(sha) on DELETE RESTRICT"` }
Tag is assigned to an image version
type User ¶
type User struct { gorm.Model `json:"-"` Name string `json:",omitempty"` Email string `json:",omitempty"` AvatarURL string `json:",omitempty"` Auths []UserAuth `json:"-" gorm:"ForeignKey:UserID"` UserSetting *UserSetting `gorm:"ForeignKey:UserID" json:",omitempty"` }
User is a user, and has to refer to potentially multiple authorizations
type UserAuth ¶
type UserAuth struct { UserID uint `gorm:"primary_key"` Provider string `gorm:"primary_key"` NameFromAuth string IDFromAuth string NicknameFromAuth string }
UserAuth is the identify of this user for an OAuth provider
type UserImagePermission ¶
type UserImagePermission struct { UserID uint `gorm:"primary_key"` ImageName string `gorm:"primary_key"` CreatedAt time.Time `json:"-"` // Auto-updated UpdatedAt time.Time `json:"-"` // Auto-updated }
UserImagePermission holds permissions for user access to private images
type UserRegistryCredential ¶
type UserRegistryCredential struct { RegistryID string `gorm:"primary_key"` UserID uint `gorm:"primary_key"` User string Password string `gorm:"-"` EncryptedPassword string `json:"-"` EncryptedKey string `json:"-"` CreatedAt time.Time `json:"-"` // Auto-updated UpdatedAt time.Time `json:"-"` // Auto-updated }
UserRegistryCredential holds credentials for accessing private images
type UserSetting ¶
type UserSetting struct { gorm.Model `json:"-"` UserID uint `gorm:"primary_key" json:"-"` NotificationLimit int `json:",omitempty"` HasPrivateRegistrySupport bool `json:",omitempty"` }
UserSetting holds additional data that is not stored on the session.
type VersionControl ¶
VersionControl is parsed from the org.label-schema.vcs-* labels.