chartmuseum

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

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

Go to latest
Published: Oct 8, 2022 License: MIT Imports: 25 Imported by: 2

README

go-chartmuseum

go library for chartmuseum

English | 中文简体

✨ Features

  • 🌈 Wrap the chartmuseum api as a go library.
  • 📦 Plain and simple error handling.
  • 🛡 Perfect test cases.

API


Helm Chart Repository

  • GET /index.yaml - retrieved when you run helm repo add chartmuseum http://localhost:8080/
  • GET /charts/mychart-0.1.0.tgz retrieved when you run helm install chartmuseum/mychart
  • GET /charts/mychart-0.1.0.tgz.prov - retrieved when you run helm install with the --verify flag

Chart Manipulation

  • POST /api/charts - upload a new chart version
  • POST /api/prov - upload a new provenance file
  • DELETE /api/charts/<name>/<version> - delete a chart version (and corresponding provenance file)
  • GET /api/charts - list all charts
  • GET /api/charts/<name> - list all versions of a chart
  • GET /api/charts/<name>/<version> - describe a chart version
  • HEAD /api/charts/<name> - check if chart exists (any versions)
  • HEAD /api/charts/<name>/<version> - check if chart version exists

Server Info

  • GET / - HTML welcome page
  • GET /info - returns current ChartMuseum version
  • GET /health - returns 200 OK

📦 Install

go get github.com/yidaqiang/go-chartmuseum

🔨 Usage

package main

import (
	"fmt"
	"github.com/yidaqiang/go-chartmuseum"
)

const (
	chartmuseumServer = "https://chart.example.com"
	chartRepo         = "test/repo"
	username          = "admin"
	password          = "password"
)

func main() {
	client, err := chartmuseum.NewBasicAuthClient(username, password, chartmuseum.WithBaseURL(chartmuseumServer))
	if err != nil {
		fmt.Error(err)
	}
	charts, _, err := client.Charts.ListCharts(chartRepo)
	if err != nil {
		return
	}
	fmt.Printf("found %d charts", len(*charts))
}

⌨️ Development

clone locally:

$ git clone git@github.com:yidaqiang/go-chartmuseum.git
$ cd go-chartmuseum
$ go mod tidy

🤝 Contributing

Read our contributing guide and let's build a better antd together.

We welcome all contributions. Please read our CONTRIBUTING.md first. You can submit any ideas as pull requests or as GitHub issues. If you'd like to improve code, check out the Development Instructions and have a good time! :)

If you are a collaborator, please follow our Pull Request principle to create a Pull Request with collaborator template.

❤ Sponsors and Backers

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWriteFile

func AtomicWriteFile(filename string, reader io.Reader, mode os.FileMode) error

AtomicWriteFile atomically (as atomic as os.Rename allows) writes a file to a disk.

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present.

func CopyDir

func CopyDir(src, dst string) error

CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist.

func IsDir

func IsDir(name string) (bool, error)

IsDir determines is the path given is a directory or not.

func IsSymlink(path string) (bool, error)

IsSymlink determines if the given path is a symbolic link.

func RenameWithFallback

func RenameWithFallback(src, dst string) error

RenameWithFallback attempts to rename a file or directory, but falls back to copying in the event of a cross-device link error. If the fallback copy succeeds, src is still removed, emulating normal rename behavior.

func VersionOrdinal

func VersionOrdinal(version string) string

Types

type AuthType

type AuthType int

AuthType represents an authentication type within ChartMuseum.

const (
	DefaultNoAuth AuthType = iota
	BasicAuth
)

List of available authentication types.

type ChartOption

type ChartOption struct {
	Name *string `json:"chart-name,omitempty"`
}

func NewChartOption

func NewChartOption(name string) ChartOption

type ChartService

type ChartService struct {
	// contains filtered or unexported fields
}

func (*ChartService) DeleteChart

func (c *ChartService) DeleteChart(repo string, chartVersionOptions ChartVersionOption, options ...RequestOptionFunc) (*Response, error)

func (*ChartService) DownloadChart

func (c *ChartService) DownloadChart(repo string, dest string, chartVersionOptions ChartVersionOption, options ...RequestOptionFunc) (*Response, error)

func (*ChartService) GetLatestChartVersionWithRegex

func (c *ChartService) GetLatestChartVersionWithRegex(repo string, chart ChartOption, regex string, options ...RequestOptionFunc) (version string, err error)

func (*ChartService) GetVersion

func (c *ChartService) GetVersion(repo string, chartVersionOptions ChartVersionOption, options ...RequestOptionFunc) (*helmrepo.ChartVersion, *Response, error)

func (*ChartService) IsExist

func (c *ChartService) IsExist(repo string, chartOptions ChartOption, options ...RequestOptionFunc) (bool, *Response, error)

func (*ChartService) IsExistVersion

func (c *ChartService) IsExistVersion(repo string, chartVersionOptions ChartVersionOption, options ...RequestOptionFunc) (bool, *Response, error)

func (*ChartService) ListCharts

func (c *ChartService) ListCharts(repo string, options ...RequestOptionFunc) (*map[string]helmrepo.ChartVersions, *Response, error)

func (*ChartService) ListVersions

func (c *ChartService) ListVersions(repo string, chartOptions ChartOption, options ...RequestOptionFunc) (*helmrepo.ChartVersions, *Response, error)

func (*ChartService) UploadChart

func (c *ChartService) UploadChart(repo, chartFilePath string, options ...RequestOptionFunc) (*Response, error)

type ChartVersionOption

type ChartVersionOption struct {
	ChartOption
	Version *string `json:"chart-version,omitempty"`
}

func NewChartVersionOption

func NewChartVersionOption(name string, version string) ChartVersionOption

type Client

type Client struct {

	// User agent used when communicating with the GitHub API.
	UserAgent string

	// Services used for talking to different parts of the ChartMuseum API.
	//Repositories *RepositoriesService
	Charts *ChartService
	Info   *InfoService
	// contains filtered or unexported fields
}

func NewBasicAuthClient

func NewBasicAuthClient(username, password string, options ...ClientOptionFunc) (*Client, error)

NewBasicAuthClient returns a new GitLab API client. To use API methods which require authentication, provide a valid username and password.

func NewClient

func NewClient(options ...ClientOptionFunc) (*Client, error)

NewClient returns a new ChartMuseum API client.

func (*Client) BaseURL

func (c *Client) BaseURL() *url.URL

BaseURL return a copy of the baseURL.

func (*Client) Do

func (c *Client) Do(req *retryablehttp.Request, v interface{}) (*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, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

func (*Client) NewRequest

func (c *Client) NewRequest(method, path string, opt interface{}, options []RequestOptionFunc) (*retryablehttp.Request, error)

NewRequest creates a new API request. The method expects a relative URL path that will be resolved relative to the base URL of the Client. Relative URL paths should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as the request body.

type ClientOptionFunc

type ClientOptionFunc func(*Client) error

func WithBaseURL

func WithBaseURL(urlStr string) ClientOptionFunc

WithBaseURL sets the base URL for API requests to a custom endpoint.

type ErrorResponse

type ErrorResponse struct {
	Body     []byte
	Response *http.Response
	Message  string
}

An ErrorResponse reports one or more errors caused by an API request.

GitLab API docs: https://docs.gitlab.com/ce/api/README.html#data-validation-and-error-reporting

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

type Healthy

type Healthy struct {
	Healthy bool
}

type InfoService

type InfoService struct {
	// contains filtered or unexported fields
}

func (*InfoService) Health

func (s *InfoService) Health(options ...RequestOptionFunc) (*Healthy, error)

func (*InfoService) Index

func (s *InfoService) Index(options ...RequestOptionFunc) (string, error)

func (*InfoService) Info

func (s *InfoService) Info(options ...RequestOptionFunc) (*Version, error)

type RequestOptionFunc

type RequestOptionFunc func(*retryablehttp.Request) error

RequestOptionFunc can be passed to all API requests to customize the API request.

func WithContext

func WithContext(ctx context.Context) RequestOptionFunc

WithContext runs the request with the provided context

func WithUpload

func WithUpload(mediaType string, size int64) RequestOptionFunc

type Response

type Response struct {
	*http.Response

	Message string `json:"message,omitempty"`
	Error   string `json:"error,omitempty"`
	Saved   bool   `json:"saved,omitempty"`
	Deleted bool   `json:"deleted,omitempty"`
	Healthy bool   `json:"healthy,omitempty"`
}

Response wraps http.Response and decodes ChartMuseum response

type Version

type Version struct {
	Version string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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