Documentation
¶
Index ¶
- Constants
- Variables
- func ErrorResponse(err interface{}) v1.Reply
- func NotAllowed(c *gin.Context)
- func NotFound(c *gin.Context)
- func ParseBearerToken(header string) string
- func Version() string
- func VersionURL() string
- type Server
- func (s *Server) Available() gin.HandlerFunc
- func (s *Server) CreateSecret(c *gin.Context)
- func (s *Server) DestroySecret(c *gin.Context)
- func (s *Server) FetchSecret(c *gin.Context)
- func (s *Server) GenerateUniqueURL(ctx context.Context) (token string, err error)
- func (s *Server) Healthz(c *gin.Context)
- func (s *Server) Readyz(c *gin.Context)
- func (s *Server) RedirectVersion(c *gin.Context)
- func (s *Server) Routes() http.Handler
- func (s *Server) Serve() (err error)
- func (s *Server) SetStatus(health, ready bool)
- func (s *Server) Shutdown() (err error)
- func (s *Server) Status(c *gin.Context)
Constants ¶
const ( VersionMajor = 1 VersionMinor = 2 VersionPatch = 1 VersionReleaseLevel = "" VersionReleaseNumber = 6 )
Version component constants for the current build.
const DefaultSecretAccesses = 1
DefaultSecretAccesses ensures that once the secret is fetched it is destroyed
const DefaultSecretLifetime = time.Hour * 24 * 7
DefaultSecretLifetime is one week after which the secret will be destroyed.
const ServiceName = "whisper"
Variables ¶
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 ¶
ErrorResponse constructs an new response from the error or returns a success: false.
func NotAllowed ¶
NotAllowed returns a JSON 405 response for the API.
func ParseBearerToken ¶ added in v1.1.1
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 VersionURL ¶
func VersionURL() string
VersionURL returns the URL prefix for the API at the current version
Types ¶
type Server ¶
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
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
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
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
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
Healthz is used to alert k8s to the health/liveness status of the server.
func (*Server) Readyz ¶ added in v1.2.0
Readyz is used to alert k8s to the readiness status of the server.
func (*Server) RedirectVersion ¶
RedirectVersion sends the caller to the root of the current version
func (*Server) Routes ¶
Routes returns the API router and is primarily exposed for testing purposes.
func (*Server) SetStatus ¶ added in v1.2.0
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) Status ¶
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. |