dockerhub

package module
v0.0.0-...-ca113a8 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2021 License: MIT Imports: 9 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
	// 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 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 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 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)

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) (*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 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"`
}

Jump to

Keyboard shortcuts

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