hello

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hello is the REST/JSON service the purser examples authenticate.

It is deliberately dull. The service is one GET returning who the caller is, because the interesting part of the examples is the credential that got them in, not what they asked for.

Nothing here is part of purser's exported API. It is internal to the module and exists so the server and client binaries share one wire contract rather than two hand-written ones that can disagree.

Index

Constants

View Source
const Path = "/hello"

Path is the one endpoint the service serves.

Variables

This section is empty.

Functions

func Authenticate

func Authenticate(a authn.Authenticator, log *slog.Logger, next http.Handler) http.Handler

Authenticate resolves the caller with a and puts it on the request context, or answers 401.

This is what purser's httpmw package will eventually provide. Until it does, every consumer writes these fifteen lines, so the example writes them where they can be read:

  • The Caller and the AuthSource go on the context together. The source is taken from the authenticator that verified the request — a.Source() — and never from anything the client sent.
  • An error means no identity. There is no partial success to fall through on, so the handler below never runs.

func Handler

func Handler(servedBy string, log *slog.Logger) http.Handler

Handler serves Path from the Caller on the request context.

It assumes Authenticate ran ahead of it. A missing Caller is a wiring bug in the server, not an unauthenticated request, and is reported as one: returning a cheerful anonymous greeting instead would make an unauthenticated surface look like a working one.

Types

type Fault

type Fault struct {
	Error string `json:"error"`
}

Fault is the error body.

It carries a category rather than the underlying error text. An authentication failure's detail — which field was missing, which matcher rejected — is for the server's log, not for the peer that failed it: a client that can enumerate why it was rejected can enumerate its way to a credential that is not.

type Greeting

type Greeting struct {
	// Greeting is the human-readable line.
	Greeting string `json:"greeting"`
	// Caller is purser.Caller.Identity — a SPIFFE ID under the SPIFFE
	// profile, whatever SubjectSource names under the PKI one.
	Caller string `json:"caller"`
	// AuthSource is how the server authenticated the request. It comes
	// from the authenticator that did the verifying, never from a
	// request header.
	AuthSource string `json:"auth_source"`
	// Labels is the credential metadata purser attached — issuer DN and
	// serial for PKI, trust domain and path for SPIFFE.
	Labels map[string]string `json:"labels,omitempty"`
	// ServedBy names the server instance, so a reader can tell which
	// replica answered.
	ServedBy string `json:"served_by"`
}

Greeting is the success body: the identity purser resolved, and the evidence it resolved it from.

func Greet

func Greet(ctx context.Context, c *http.Client, baseURL string) (Greeting, error)

Greet performs the one request the service serves.

baseURL is the scheme and authority, e.g. "https://127.0.0.1:8443".

Jump to

Keyboard shortcuts

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