whisper

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersionMajor         = 1
	VersionMinor         = 2
	VersionPatch         = 1
	VersionReleaseLevel  = ""
	VersionReleaseNumber = 6
)

Version component constants for the current build.

View Source
const DefaultSecretAccesses = 1

DefaultSecretAccesses ensures that once the secret is fetched it is destroyed

View Source
const DefaultSecretLifetime = time.Hour * 24 * 7

DefaultSecretLifetime is one week after which the secret will be destroyed.

View Source
const ServiceName = "whisper"

Variables

View Source
var (
	GitVersion string
	BuildDate  string
)

Set the GitVersion via -ldflags="-X 'github.com/rotationalio/whisper/pkg.GitVersion=$(git rev-parse --short HEAD)'"

Functions

func ErrorResponse

func ErrorResponse(err interface{}) v1.Reply

ErrorResponse constructs an new response from the error or returns a success: false.

func NotAllowed

func NotAllowed(c *gin.Context)

NotAllowed returns a JSON 405 response for the API.

func NotFound

func NotFound(c *gin.Context)

NotFound returns a JSON 404 response for the API.

func ParseBearerToken added in v1.1.1

func ParseBearerToken(header string) string

ParseBearerToken parses an Authorization: Bearer <token> header such that the token is the base64 encoded password. Basic auth not used here since there is no user.

func Version

func Version() string

Version returns the semantic version for the current build.

func VersionURL

func VersionURL() string

VersionURL returns the URL prefix for the API at the current version

Types

type Server

type Server struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func New

func New(conf config.Config) (s *Server, err error)

func (*Server) Available

func (s *Server) Available() gin.HandlerFunc

Available is middleware that uses the healthy boolean to return a service unavailable http status code if the server is shutting down. It does this before all routes to ensure that complex handling doesn't bog down the server.

func (*Server) CreateSecret added in v1.1.1

func (s *Server) CreateSecret(c *gin.Context)

CreateSecret handles an incoming CreateSecretRequest and attempts to create a new secret that will only be displayed when the correct link is retrieved.

func (*Server) DestroySecret added in v1.1.1

func (s *Server) DestroySecret(c *gin.Context)

DestroySecret handles an incoming destroy secret request and attempts to delete the secret from the database. This RPC is password protected in the same way fetch is.

func (*Server) FetchSecret added in v1.1.1

func (s *Server) FetchSecret(c *gin.Context)

FetchSecret handles an incoming fetch secret request and attempts to retrieve the secret from the database and return it to the user. This function also handles the password and ensures that a 404 is returned to obfuscate the existence of the secret on bad requests.

func (*Server) GenerateUniqueURL added in v1.1.1

func (s *Server) GenerateUniqueURL(ctx context.Context) (token string, err error)

GenerateUniqueURL is a helper function that uses crypto/rand to create a random URL-safe string and determines if it is in the database or not. If it finds a collision it attempts to find a unique string for a fixed number of attempts before quitting.

func (*Server) Healthz added in v1.2.0

func (s *Server) Healthz(c *gin.Context)

Healthz is used to alert k8s to the health/liveness status of the server.

func (*Server) Readyz added in v1.2.0

func (s *Server) Readyz(c *gin.Context)

Readyz is used to alert k8s to the readiness status of the server.

func (*Server) RedirectVersion

func (s *Server) RedirectVersion(c *gin.Context)

RedirectVersion sends the caller to the root of the current version

func (*Server) Routes

func (s *Server) Routes() http.Handler

Routes returns the API router and is primarily exposed for testing purposes.

func (*Server) Serve

func (s *Server) Serve() (err error)

func (*Server) SetStatus added in v1.2.0

func (s *Server) SetStatus(health, ready bool)

SetHealth sets the health status on the API server, putting it into unavailable mode if health is false, and removing maintenance mode if health is true. Here primarily for testing purposes since it is unlikely an outside caller can access this.

func (*Server) Shutdown

func (s *Server) Shutdown() (err error)

func (*Server) Status

func (s *Server) Status(c *gin.Context)

Status is an unauthenticated endpoint that returns the status of the api server and can be used for heartbeats and liveness checks. This status method is the global status method, meaning it returns the latest version of the whipser service, no matter how many API versions are available.

Directories

Path Synopsis
api
v1
Package api describes the JSON data structures for v1 requests and responses.
Package api describes the JSON data structures for v1 requests and responses.
Package config provides settings and configuration for the whipser server by loading the configuration from the environment and specifying reasonable defaults and required settings.
Package config provides settings and configuration for the whipser server by loading the configuration from the environment and specifying reasonable defaults and required settings.
Package logger adapts the zerolog package to use GCP serverity levels.
Package logger adapts the zerolog package to use GCP serverity levels.

Jump to

Keyboard shortcuts

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