spiffe

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IdAsString

func IdAsString(r *http.Request) string

IdAsString retrieves the SPIFFE ID from an HTTP request and returns it as a string.

Parameters: - cid: A string representing the context identifier. - r: A pointer to an http.Request from which the SPIFFE ID will be extracted.

Returns:

  • A string representing the SPIFFE ID if it can be successfully retrieved; otherwise, an empty string.

If the SPIFFE ID cannot be retrieved from the request, it logs an informational message and returns an empty string.

Example usage:

func handler(w http.ResponseWriter, r *http.Request) {
    cid := "exampleContextID"
    spiffeID := IdAsString(cid, r)
    fmt.Fprintf(w, "SPIFFE ID: %s", spiffeID)
}

func IdFromRequest

func IdFromRequest(r *http.Request) (*spiffeid.ID, error)

IdFromRequest extracts the SPIFFE ID from the TLS peer certificate of an HTTP request. It checks if the incoming request has a valid TLS connection and at least one peer certificate. The first certificate in the chain is used to extract the SPIFFE ID.

Params:

r *http.Request - The HTTP request from which the SPIFFE ID is to be
extracted.

Returns:

 *spiffeid.ID - The SPIFFE ID extracted from the first peer certificate,
 or nil if extraction fails.
 error - An error object indicating the failure reason. Possible errors
include the absence of peer certificates or a failure in extracting the
SPIFFE ID from the certificate.

Note:

This function assumes that the request is already over a secured TLS
connection and will fail if the TLS connection state is not available or
the peer certificates are missing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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