dockerhub

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 11 Imported by: 0

README

dockerhub-go Build Status GoDoc

A Dockerhub client for Go

Usage

import "github.com/charliekenney23/dockerhub-go"

Construct a new DockerHub client, then use various services on the client to access different parts of the DockerHub API.

client := dockerhub.NewClient(nil)

// login to Dockerhub
err := client.Auth.Login(context.Background(), "username", "password")

// or set an auth token directly
client.SetAuthToken(os.Getenv("DOCKERHUB_API_TOKEN"))

License

MIT © 2019 Charles Kenney

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func String

func String(s string) *string

String returns a pointer to a string for configuration.

func StringValue

func StringValue(s *string) string

StringValue returns the value of a String pointer

Types

type AuthService

type AuthService service

AuthService handles communication with the auth related methods of the Dockerhub API.

func (*AuthService) Login

func (s *AuthService) Login(ctx context.Context, username, password string) error

Login authenticates with the Dockerhub API with the given given username and password.

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string

	Auth         *AuthService
	Repositories *RepositoriesService
	User         *UserService
	Webhook      *WebhookService
	Organization *OrganizationService
	Tag          *TagService
	// contains filtered or unexported fields
}

A Client manages communication with the Dockerhub API.

func NewClient

func NewClient(httpClient *http.Client) *Client

NewClient returns a new Dockerhub client. If an httpClient is not provided, a new http.Client will be used.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v.

func (*Client) NewRequest

func (c *Client) NewRequest(method, url string, body interface{}) (*http.Request, error)

NewRequest creates an API request. The given URL is relative to the Client's BaseURL.

func (*Client) SetAuthToken

func (c *Client) SetAuthToken(token string)

SetAuthToken sets the Authorization token on the client to be sent with API requests.

type CreateOrganizationRequest added in v1.0.2

type CreateOrganizationRequest struct {
	Orgname string `json:"orgname"`
	Company string `json:"company"`
}

CreateOrganizationRequest struct

type CreateRepositoryRequest

type CreateRepositoryRequest struct {
	Namespace     string        `json:"namespace"`
	Registry      string        `json:"registry"`
	Image         string        `json:"image"`
	Name          string        `json:"name"`
	Description   string        `json:"description"`
	Privacy       string        `json:"privacy"`
	BuildSettings []interface{} `json:"build_settings"`
	IsPrivate     bool          `json:"is_private"`
}

type ListOptions

type ListOptions struct {
	// For paginated result sets, page of results to retrieve.
	Page int `url:"page,omitempty"`

	// For paginated result sets, the number of results to include per page.
	PageSize int `url:"page_size,omitempty"`
}

ListOptions specifies the optional parameters to various List methods that support pagination.

type LoginRequest

type LoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

LoginRequest represents the payload to be sent to login to the Dockerhub API.

type LoginResponse

type LoginResponse struct {
	Token string `json:"token"`
}

LoginResponse represents the payload to be responded to a successful Dockerhub API login request.

type Organization added in v1.0.2

type Organization struct {
	ID            string    `json:"id"`
	Orgname       string    `json:"orgname"`
	FullName      string    `json:"full_name"`
	Location      string    `json:"location"`
	Company       string    `json:"company"`
	ProfileURL    string    `json:"profile_url"`
	DateJoined    time.Time `json:"date_joined"`
	GravatarURL   string    `json:"gravatar_url"`
	GravatarEmail string    `json:"gravatar_email"`
	Type          string    `json:"type"`
}

Organization struct

type OrganizationList added in v1.0.2

type OrganizationList struct {
	Count    int         `json:"count"`
	Next     interface{} `json:"next"`
	Previous interface{} `json:"previous"`
	Results  []struct {
		ID            string    `json:"id"`
		Orgname       string    `json:"orgname"`
		FullName      string    `json:"full_name"`
		Location      string    `json:"location"`
		Company       string    `json:"company"`
		ProfileURL    string    `json:"profile_url"`
		DateJoined    time.Time `json:"date_joined"`
		GravatarURL   string    `json:"gravatar_url"`
		GravatarEmail string    `json:"gravatar_email"`
		Type          string    `json:"type"`
	} `json:"results"`
}

OrganizationList Struct

type OrganizationService added in v1.0.2

type OrganizationService service

OrganizationService Type Service

func (*OrganizationService) CreateOrganization added in v1.0.2

func (s *OrganizationService) CreateOrganization(ctx context.Context, organization, company string) (*Organization, error)

CreateOrganization Create new Organization

func (*OrganizationService) GetOrganizations added in v1.0.2

func (s *OrganizationService) GetOrganizations(ctx context.Context, pageSize int) (*OrganizationList, error)

GetOrganizations all organizations of user

type RepositoriesService

type RepositoriesService service

RepositoriesService handles communication with the repository related methods of the Dockerhub API.

func (*RepositoriesService) CreateRepository

func (s *RepositoriesService) CreateRepository(ctx context.Context, namespace, name, description string, isPrivate bool) (*Repository, error)

CreateRepository create a repository.

func (*RepositoriesService) EditRepository

func (s *RepositoriesService) EditRepository(ctx context.Context, namespace, repo string, patch *RepositoryPatch) (*Repository, error)

EditRepository updates a repository.

func (*RepositoriesService) GetRepositories

func (s *RepositoriesService) GetRepositories(ctx context.Context, namespace string, opt *ListOptions) (*RepositoryList, error)

GetRepositories gets all repositories from a given Dockerhub namespace.

func (*RepositoriesService) GetRepository

func (s *RepositoriesService) GetRepository(ctx context.Context, namespace, repo string) (*Repository, error)

GetRepository gets details for a given repository.

func (*RepositoriesService) SetRepositoryPrivacy

func (s *RepositoriesService) SetRepositoryPrivacy(ctx context.Context, namespace, repo string, isPrivate bool) error

SetRepositoryPrivacy sets the privacy status of a repository.

type Repository

type Repository struct {
	User            string  `json:"user"`
	Name            string  `json:"name"`
	Namespace       string  `json:"namespace"`
	RepositoryType  string  `json:"repository_type"`
	Status          int     `json:"status"`
	Description     string  `json:"description"`
	IsPrivate       bool    `json:"is_private"`
	IsAutomated     bool    `json:"is_automated"`
	CanEdit         bool    `json:"can_edit"`
	StarCount       int     `json:"star_count"`
	PullCount       int     `json:"pull_count"`
	LastUpdated     string  `json:"last_updated"`
	IsMigrated      bool    `json:"is_migrated"`
	HasStarred      bool    `json:"has_starred"`
	FullDescription string  `json:"full_description"`
	Affiliation     *string `json:"affiliation"`

	Permissions RepositoryPermissions `json:"repository_permissions"`
}

Repository represents a Dockerhub repository.

type RepositoryList

type RepositoryList struct {
	Count    int     `json:"count"`
	Next     *string `json:"next"`
	Previous *string `json:"previous"`

	Results []Repository `json:"results"`
}

RepositoryList represents a list of repositories with pagination details.

type RepositoryPatch

type RepositoryPatch struct {
	FullDescription string `json:"full_description,omitempty"`
	Description     string `json:"description,omitempty"`
}

RepositoryPatch represents payload to patch a Repository.

type RepositoryPermissions

type RepositoryPermissions struct {
	Read  bool `json:"read"`
	Write bool `json:"write"`
	Admin bool `json:"admin"`
}

RepositoryPermissions specifies the permissions of the requesting user to the given Repository.

type RepositoryPrivacyPatch

type RepositoryPrivacyPatch struct {
	IsPrivate bool `json:"is_private"`
}

RepositoryPrivacyPatch represents payload to patch a Repository's privacy mode.

type TagService added in v1.0.2

type TagService service

TagService Type

func (*TagService) GetTags added in v1.0.2

func (s *TagService) GetTags(ctx context.Context, namespace, repo string, page int) (*Tags, error)

GetTags of the repo

type Tags added in v1.0.2

type Tags struct {
	Count    int         `json:"count"`
	Next     interface{} `json:"next"`
	Previous interface{} `json:"previous"`
	Results  []struct {
		Creator int         `json:"creator"`
		ID      int         `json:"id"`
		ImageID interface{} `json:"image_id"`
		Images  []struct {
			Architecture string      `json:"architecture"`
			Features     string      `json:"features"`
			Variant      interface{} `json:"variant"`
			Digest       string      `json:"digest"`
			Os           string      `json:"os"`
			OsFeatures   string      `json:"os_features"`
			OsVersion    interface{} `json:"os_version"`
			Size         int         `json:"size"`
			Status       string      `json:"status"`
			LastPulled   time.Time   `json:"last_pulled"`
			LastPushed   time.Time   `json:"last_pushed"`
		} `json:"images"`
		LastUpdated         time.Time `json:"last_updated"`
		LastUpdater         int       `json:"last_updater"`
		LastUpdaterUsername string    `json:"last_updater_username"`
		Name                string    `json:"name"`
		Repository          int       `json:"repository"`
		FullSize            int       `json:"full_size"`
		V2                  bool      `json:"v2"`
		TagStatus           string    `json:"tag_status"`
		TagLastPulled       time.Time `json:"tag_last_pulled"`
		TagLastPushed       time.Time `json:"tag_last_pushed"`
	} `json:"results"`
}

Tags response

type User

type User struct {
	ID            string    `json:"id"`
	Username      string    `json:"username"`
	FullName      string    `json:"full_name"`
	Location      string    `json:"location"`
	Company       string    `json:"company"`
	GravatarEmail string    `json:"gravatar_email"`
	IsStaff       bool      `json:"is_staff"`
	IsAdmin       bool      `json:"is_admin"`
	ProfileURL    string    `json:"profile_url"`
	DateJoined    time.Time `json:"date_joined"`
	GravatarURL   string    `json:"gravatar_url"`
	Type          string    `json:"type"`
}

type UserService

type UserService service

func (*UserService) GetLoggedInUser

func (s *UserService) GetLoggedInUser(ctx context.Context) (*User, error)

type Webhook

type Webhook struct {
	Name                string     `json:"name"`
	Slug                string     `json:"slug"`
	ExpectFinalCallback bool       `json:"expect_final_callback"`
	Webhooks            []Webhooks `json:"webhooks"`
	Created             time.Time  `json:"created"`
	LastUpdated         time.Time  `json:"last_updated"`
}

type WebhookRequest

type WebhookRequest struct {
	Name                string     `json:"name"`
	ExpectFinalCallback bool       `json:"expect_final_callback"`
	Webhooks            []Webhooks `json:"webhooks"`
	Registry            string     `json:"registry"`
}

type WebhookService

type WebhookService service

func (*WebhookService) CreateWebhook

func (s *WebhookService) CreateWebhook(ctx context.Context, namespace, repo, name, url string) (*Webhook, error)

func (*WebhookService) GetWebhooks

func (s *WebhookService) GetWebhooks(ctx context.Context, namespace, repo string) (*Webhook, error)

type Webhooks

type Webhooks struct {
	Name        string    `json:"name"`
	HookURL     string    `json:"hook_url"`
	Created     time.Time `json:"created"`
	LastUpdated time.Time `json:"last_updated"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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