rpc

package
v0.0.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenCertificate

func GenCertificate(dir string) (tls.Certificate, string, error)

GenCertificate generates a new TLS certificate or loads it from disk. The fingerprint text file will be regenerated if it's missing. The cert will be regenerated if it and/or the private key are invalid or missing.

func GetCertFingerprint

func GetCertFingerprint(cert []byte) string

GetCertFingerprint returns the sha256 fingerprint of a PEM-encoded x509 certificate. The return values corresponds with the fingerprint return value of GenCertificate.

func NewServer

func NewServer(addr string, cert tls.Certificate, handler http.Handler) *http.Server

func UrlPrefix

func UrlPrefix(host string) string

UrlPrefix returns the base URL used to reach the given coordinator host. The host can be specified as `hostname` or `hostname:port`. If port is not given, it will default to 8123 - the default listener port.

func WithAuth

func WithAuth(auth Authorizer, next httprouter.Handle) httprouter.Handle

func WithLogging

func WithLogging(next http.Handler) http.Handler

Types

type Authorizer

type Authorizer interface {
	TrustsCert(fingerprint string) bool
}

func TrustOneCert

func TrustOneCert(finger string) Authorizer

type AuthorizerFunc

type AuthorizerFunc func(fingerprint string) bool

func (AuthorizerFunc) TrustsCert

func (a AuthorizerFunc) TrustsCert(fingerprint string) bool

type Client

type Client struct {
	*http.Client
}

func NewClient

func NewClient(cert tls.Certificate, timeout time.Duration, auth Authorizer) *Client

func (*Client) GET

func (c *Client) GET(ctx context.Context, url string) (*http.Response, error)

func (*Client) POST

func (c *Client) POST(ctx context.Context, url string, body io.Reader) (*http.Response, error)

type ErrUntrustedClient

type ErrUntrustedClient struct {
	Fingerprint string
}

func (*ErrUntrustedClient) Error

func (e *ErrUntrustedClient) Error() string

type ErrUntrustedServer

type ErrUntrustedServer struct {
	Fingerprint string
}

func (*ErrUntrustedServer) Error

func (e *ErrUntrustedServer) Error() string

Jump to

Keyboard shortcuts

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