hub

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2023 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LoginURL path to the Hub login URL
	LoginURL = "/v2/users/login?refresh_token=true"
	// TwoFactorLoginURL path to the 2FA
	TwoFactorLoginURL = "/v2/users/2fa-login?refresh_token=true"
	// SecondFactorDetailMessage returned by login if 2FA is enabled
	SecondFactorDetailMessage = "Require secondary authentication on MFA enabled account"
)
View Source
const (
	//MembersURL path to the Hub API listing the members in an organization
	MembersURL = "/v2/orgs/%s/members/"
	//MembersPerTeamURL path to the Hub API listing the members in a team
	MembersPerTeamURL = "/v2/orgs/%s/groups/%s/members/"
)
View Source
const (
	// OrganizationsURL path to the Hub API listing the organizations
	OrganizationsURL = "/v2/user/orgs/"
	// OrganizationInfoURL path to the Hub API returning organization info
	OrganizationInfoURL = "/v2/orgs/%s"
)
View Source
const (
	//HubPlanURL path to the billing API returning the account hub plan
	HubPlanURL = "/api/billing/v4/accounts/%s/hub-plan"
	//TeamPlan refers to a hub team paid account
	TeamPlan = "team"
	//ProPlan refers to a hub individual paid account
	ProPlan = "pro"
	//FreePlan refers to a hub non-paid account
	FreePlan = "free"
)
View Source
const (
	// TagsURL path to the Hub API listing the tags
	TagsURL = "/v2/repositories/%s/tags/"
	// DeleteTagURL path to the Hub API to remove a tag
	DeleteTagURL = "/v2/repositories/%s/tags/%s/"
)
View Source
const (
	// TokensURL path to the Hub API listing the Personal Access Tokens
	TokensURL = "/v2/api_tokens"
	// TokenURL path to the Hub API Personal Access Token
	TokenURL = "/v2/api_tokens/%s"
)
View Source
const (
	//GroupsURL path to the Hub API listing the groups in an organization
	GroupsURL = "/v2/orgs/%s/groups/"
)
View Source
const (
	//ImageType is the classic image type
	ImageType = RepositoryType("image")
)
View Source
const (
	// RepositoriesURL is the Hub API base URL
	RepositoriesURL = "/v2/repositories/"
)
View Source
const (
	//UserURL path to user informations
	UserURL = "/v2/user/"
)

Variables

This section is empty.

Functions

func IsAuthenticationError

func IsAuthenticationError(err error) bool

IsAuthenticationError check if the error type is an authentication error

func IsForbiddenError

func IsForbiddenError(err error) bool

IsForbiddenError check if the error type is a forbidden error

func IsInvalidTokenError

func IsInvalidTokenError(err error) bool

IsInvalidTokenError check if the error type is an invalid token error

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError check if the error type is a not found error

func SetURLs

func SetURLs(newFirst, newSecond string)

SetURLs change the base urls used to check ratelimiting values

Types

type Account

type Account struct {
	ID       string
	Name     string
	FullName string
	Location string
	Company  string
	Joined   time.Time
}

Account represents a user or organization information

type Client

type Client struct {
	AuthConfig registry.AuthConfig
	Ctx        context.Context
	// contains filtered or unexported fields
}

Client sends authenticated calls to the Hub API

func NewClient

func NewClient(ctx context.Context, username, password string) *Client

NewClient prepares docker CLI and returns a Hub tool client

func (*Client) CreateToken

func (c *Client) CreateToken(description string) (*Token, error)

CreateToken creates a Personal Access Token and returns the token field only once

func (*Client) GetHubPlan

func (c *Client) GetHubPlan(accountID string) (*Plan, error)

GetHubPlan returns an account current Hub plan

func (*Client) GetMembers

func (c *Client) GetMembers(organization string) ([]Member, error)

GetMembers lists all the members in an organization

func (*Client) GetMembersCount

func (c *Client) GetMembersCount(organization string) (int, error)

GetMembersCount return the number of members in an organization

func (*Client) GetMembersPerTeam

func (c *Client) GetMembersPerTeam(organization, team string) (interface{}, error)

GetMembersPerTeam returns the members of a team in an organization

func (*Client) GetOrgConsumption

func (c *Client) GetOrgConsumption(org string) (*Consumption, error)

GetOrgConsumption return the current organization consumption

func (*Client) GetOrganizationInfo

func (c *Client) GetOrganizationInfo(orgname string) (*Account, error)

GetOrganizationInfo returns organization info

func (*Client) GetOrganizations

func (c *Client) GetOrganizations(ctx context.Context) ([]Organization, error)

GetOrganizations lists all the organizations a user has joined

func (*Client) GetRateLimits

func (c *Client) GetRateLimits() (*RateLimits, error)

GetRateLimits returns the rate limits for the user

func (*Client) GetRepositories

func (c *Client) GetRepositories(account string) ([]Repository, int, error)

GetRepositories lists all the repositories a user can access

func (*Client) GetTags

func (c *Client) GetTags(repository string, reqOps ...RequestOp) ([]Tag, int, error)

GetTags calls the hub repo API and returns all the information on all tags

func (*Client) GetTeams

func (c *Client) GetTeams(organization string) ([]Team, error)

GetTeams lists all the teams in an organization

func (*Client) GetTeamsCount

func (c *Client) GetTeamsCount(organization string) (int, error)

GetTeamsCount returns the number of teams in an organization

func (*Client) GetToken

func (c *Client) GetToken(tokenUUID string) (*Token, error)

GetToken calls the hub repo API and returns the information on one token

func (*Client) GetTokens

func (c *Client) GetTokens() ([]Token, int, error)

GetTokens calls the hub repo API and returns all the information on all tokens

func (*Client) GetUserConsumption

func (c *Client) GetUserConsumption(user string) (*Consumption, error)

GetUserConsumption return the current user consumption

func (*Client) GetUserInfo

func (c *Client) GetUserInfo() (*Account, error)

GetUserInfo returns the information on the user retrieved from Hub

func (*Client) Login

func (c *Client) Login(username string, password string, twoFactorCodeProvider func() (string, error)) (string, string, error)

Login tries to authenticate, it will call the twoFactorCodeProvider if the user has 2FA activated

func (*Client) RemoveRepository

func (c *Client) RemoveRepository(repository string) error

RemoveRepository removes a repository on Hub

func (*Client) RemoveTag

func (c *Client) RemoveTag(repository, tag string) error

RemoveTag removes a tag in a repository on Hub

func (*Client) RemoveToken

func (c *Client) RemoveToken(tokenUUID string) error

RemoveToken deletes a token from personal access token

func (*Client) Update

func (c *Client) Update(ops ...ClientOp) error

Update changes client behavior using ClientOp

func (*Client) UpdateToken

func (c *Client) UpdateToken(tokenUUID, description string, isActive bool) (*Token, error)

UpdateToken updates a token's description and activeness

type ClientOp

type ClientOp func(*Client) error

ClientOp represents an option given to NewClient constructor to customize client behavior.

func WithAllElements

func WithAllElements() ClientOp

WithAllElements makes the client fetch all the elements it can find, enabling pagination.

func WithContext

func WithContext(ctx context.Context) ClientOp

WithContext set the client context

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOp

WithHTTPClient sets the *http.Client for the client

func WithHubAccount

func WithHubAccount(account string) ClientOp

WithHubAccount sets the current account name

func WithHubToken

func WithHubToken(token string) ClientOp

WithHubToken sets the bearer token to the client

func WithInStream

func WithInStream(in io.Reader) ClientOp

WithInStream sets the input stream

func WithOutStream

func WithOutStream(out io.Writer) ClientOp

WithOutStream sets the output stream

func WithPassword

func WithPassword(password string) ClientOp

WithPassword sets the password to the client

func WithRefreshToken

func WithRefreshToken(refreshToken string) ClientOp

WithRefreshToken sets the refresh token to the client

type Consumption

type Consumption struct {
	Seats               int
	PrivateRepositories int
	Teams               int
}

Consumption represents current user or org consumption

type Image

type Image struct {
	Digest       string
	Architecture string
	Os           string
	Variant      string
	Size         int
	LastPulled   time.Time
	LastPushed   time.Time
	Status       string
}

Image represents the metadata of a manifest

type Instance

type Instance struct {
	APIHubBaseURL string
	RegistryInfo  *registry.IndexInfo
}

Instance stores all the specific pieces needed to dialog with Hub

type Limits

type Limits struct {
	Seats          int
	PrivateRepos   int
	Teams          int
	Collaborators  int
	ParallelBuilds int
}

Limits represents the current account limits

type Member

type Member struct {
	Username string `json:"username"`
	FullName string `json:"full_name"`
}

Member is a user part of an organization

type Organization

type Organization struct {
	Namespace string
	FullName  string
	Role      string
	Teams     []Team
	Members   []Member
}

Organization represents a Docker Hub organization

type Plan

type Plan struct {
	Name   string
	Limits Limits
}

Plan represents the current account Hub plan

type RateLimits

type RateLimits struct {
	Limit           *int    `json:",omitempty"`
	LimitWindow     *int    `json:",omitempty"`
	Remaining       *int    `json:",omitempty"`
	RemainingWindow *int    `json:",omitempty"`
	Source          *string `json:",omitempty"`
}

RateLimits ...

type Repository

type Repository struct {
	Name        string
	Description string
	LastUpdated time.Time
	PullCount   int
	StarCount   int
	IsPrivate   bool
}

Repository represents a Docker Hub repository

type RepositoryType

type RepositoryType string

RepositoryType lists all the different repository types handled by the Docker Hub

type RequestOp

type RequestOp func(r *http.Request) error

RequestOp represents an option to customize the request sent to the Hub API

func WithSortingOrder

func WithSortingOrder(order string) RequestOp

WithSortingOrder adds a sorting order query parameter to the request

type Tag

type Tag struct {
	Name                string
	FullSize            int
	LastUpdated         time.Time
	LastUpdaterUserName string
	Images              []Image
	LastPulled          time.Time
	LastPushed          time.Time
	Status              string
}

Tag can point to a manifest or manifest list

type Team

type Team struct {
	Name        string
	Description string
	Members     []Member
}

Team represents a hub group in an organization

type Token

type Token struct {
	UUID        uuid.UUID
	ClientID    string
	CreatorIP   string
	CreatorUA   string
	CreatedAt   time.Time
	LastUsed    time.Time
	GeneratedBy string
	IsActive    bool
	Token       string
	Description string
}

Token is a personal access token. The token field will only be filled at creation and can never been accessed again.

Jump to

Keyboard shortcuts

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