common

package
v0.0.0-...-293ef99 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

package common contains common types and functions used by implementations

Index

Constants

View Source
const AUTH_TOKEN_ENV_VAR = "BINDERHUB_AUTH_TOKEN" // #nosec G101 -- Name of an env-var, not a secret

Variables

This section is empty.

Functions

func CheckAuthorised

func CheckAuthorised(originalHandler http.Handler, authToken string) http.Handler

CheckAuthorised wraps originalHandler to check for a valid Authorization header and returns a http.Handler

func CreateServer

func CreateServer(mux *http.ServeMux, registryH IRegistryClient, authToken string, promRegistry *prometheus.Registry)

CreateServer configures a new http handler for the registry helper

func ImageGetNameAndTag

func ImageGetNameAndTag(r *http.Request) (string, string, error)

ImageGetNameAndTag extracts the repository name and tag from the request path

func InternalServerError

func InternalServerError(w http.ResponseWriter, r *http.Request, errorResponse error)

InternalServerError is a handler that returns a 500 HTTP error

func NotAuthorised

func NotAuthorised(w http.ResponseWriter, r *http.Request)

NotAuthorised is a handler that returns a 403 HTTP error

func NotFound

func NotFound(w http.ResponseWriter, r *http.Request)

NotFound is a handler that returns a 404 HTTP error

func RepoGetName

func RepoGetName(r *http.Request) (string, error)

RepoGetName extracts the repository name from the request path

func Run

func Run(registryH IRegistryClient, healthInfo map[string]string, listen string, promRegistry *prometheus.Registry)

The main entrypoint for the service

Types

type IRegistryClient

type IRegistryClient interface {
	ListRepositories(w http.ResponseWriter, r *http.Request)
	GetRepository(w http.ResponseWriter, r *http.Request)
	GetImage(w http.ResponseWriter, r *http.Request)
	CreateRepository(w http.ResponseWriter, r *http.Request)
	DeleteRepository(w http.ResponseWriter, r *http.Request)
	GetToken(w http.ResponseWriter, r *http.Request)
}

IRegistryClient is an interface that all registry helpers must implement

type RegistryServer

type RegistryServer struct {
	Client IRegistryClient
}

RegistryServer is http.handler that passes requests to the registry helper implementation

func (*RegistryServer) ServeHTTP

func (h *RegistryServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP passes requests to the registry helper implementation

type RegistryToken

type RegistryToken struct {
	Username string    `json:"username"`
	Password string    `json:"password"`
	Registry string    `json:"registry"`
	Expires  time.Time `json:"expires"`
}

RegistryToken is an object containing a username and password that can be used to login to a registry and an Expires time when the token will expire

Jump to

Keyboard shortcuts

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