spiffeid

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: Apache-2.0 Imports: 4 Imported by: 314

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatPath

func FormatPath(format string, args ...interface{}) (string, error)

FormatPath builds a path by formatting the given formatting string with the given args (i.e. fmt.Sprintf). The resulting path must be valid or an error is returned.

func JoinPathSegments

func JoinPathSegments(segments ...string) (string, error)

JoinPathSegments joins one or more path segments into a slash separated path. Segments cannot contain slashes. The resulting path must be valid or an error is returned. If no segments are provided, an empty string is returned.

func RequireFormatPath

func RequireFormatPath(format string, args ...interface{}) string

RequireFormatPath builds a path by formatting the given formatting string with the given args (i.e. fmt.Sprintf). The resulting path must be valid or the function panics. It should only be used when the input is statically verifiable.

func RequireJoinPathSegments

func RequireJoinPathSegments(segments ...string) string

RequireJoinPathSegments joins one or more path segments into a slash separated path. Segments cannot contain slashes. The resulting path must be valid or the function panics. It should only be used when the input is statically verifiable.

func ValidatePath

func ValidatePath(path string) error

ValidatePath validates that a path string is a conformant path for a SPIFFE ID. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func ValidatePathSegment added in v2.1.3

func ValidatePathSegment(segment string) error

ValidatePathSegment validates that a string is a conformant segment for inclusion in the path for a SPIFFE ID. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

Types

type ID

type ID struct {
	// contains filtered or unexported fields
}

ID is a SPIFFE ID

func FromPath

func FromPath(td TrustDomain, path string) (ID, error)

FromPath returns a new SPIFFE ID in the given trust domain and with the given path. The supplied path must be a valid absolute path according to the SPIFFE specification. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func FromPathf

func FromPathf(td TrustDomain, format string, args ...interface{}) (ID, error)

FromPathf returns a new SPIFFE ID from the formatted path in the given trust domain. The formatted path must be a valid absolute path according to the SPIFFE specification. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func FromSegments

func FromSegments(td TrustDomain, segments ...string) (ID, error)

FromSegments returns a new SPIFFE ID in the given trust domain with joined path segments. The path segments must be valid according to the SPIFFE specification and must not contain path separators. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func FromString

func FromString(id string) (ID, error)

FromString parses a SPIFFE ID from a string.

func FromStringf

func FromStringf(format string, args ...interface{}) (ID, error)

FromStringf parses a SPIFFE ID from a formatted string.

func FromURI

func FromURI(uri *url.URL) (ID, error)

FromURI parses a SPIFFE ID from a URI.

func RequireFromPath

func RequireFromPath(td TrustDomain, path string) ID

RequireFromPath is similar to FromPath except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func RequireFromPathf

func RequireFromPathf(td TrustDomain, format string, args ...interface{}) ID

RequireFromPathf is similar to FromPathf except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func RequireFromSegments

func RequireFromSegments(td TrustDomain, segments ...string) ID

RequireFromSegments is similar to FromSegments except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func RequireFromString

func RequireFromString(s string) ID

RequireFromString is similar to FromString except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func RequireFromStringf

func RequireFromStringf(format string, args ...interface{}) ID

RequireFromStringf is similar to FromStringf except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func RequireFromURI

func RequireFromURI(uri *url.URL) ID

RequireFromURI is similar to FromURI except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func (ID) AppendPath

func (id ID) AppendPath(path string) (ID, error)

AppendPath returns an ID with the appended path. It will fail if called on a zero value. The path to append must be a valid absolute path according to the SPIFFE specification. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func (ID) AppendPathf

func (id ID) AppendPathf(format string, args ...interface{}) (ID, error)

AppendPathf returns an ID with the appended formatted path. It will fail if called on a zero value. The formatted path must be a valid absolute path according to the SPIFFE specification. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func (ID) AppendSegments

func (id ID) AppendSegments(segments ...string) (ID, error)

AppendSegments returns an ID with the appended joined path segments. It will fail if called on a zero value. The path segments must be valid according to the SPIFFE specification and must not contain path separators. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func (ID) IsZero

func (id ID) IsZero() bool

IsZero returns true if the SPIFFE ID is the zero value.

func (ID) MarshalText

func (id ID) MarshalText() ([]byte, error)

MarshalText returns a text representation of the ID. If the ID is the zero value, nil is returned.

func (ID) MemberOf

func (id ID) MemberOf(td TrustDomain) bool

MemberOf returns true if the SPIFFE ID is a member of the given trust domain.

func (ID) Path

func (id ID) Path() string

Path returns the path of the SPIFFE ID inside the trust domain.

func (ID) ReplacePath

func (id ID) ReplacePath(path string) (ID, error)

Replace path returns an ID with the given path in the same trust domain. It will fail if called on a zero value. The given path must be a valid absolute path according to the SPIFFE specification. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func (ID) ReplacePathf

func (id ID) ReplacePathf(format string, args ...interface{}) (ID, error)

ReplacePathf returns an ID with the formatted path in the same trust domain. It will fail if called on a zero value. The formatted path must be a valid absolute path according to the SPIFFE specification. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func (ID) ReplaceSegments

func (id ID) ReplaceSegments(segments ...string) (ID, error)

ReplaceSegments returns an ID with the joined path segments in the same trust domain. It will fail if called on a zero value. The path segments must be valid according to the SPIFFE specification and must not contain path separators. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#22-path

func (ID) String

func (id ID) String() string

String returns the string representation of the SPIFFE ID, e.g., "spiffe://example.org/foo/bar".

func (ID) TrustDomain

func (id ID) TrustDomain() TrustDomain

TrustDomain returns the trust domain of the SPIFFE ID.

func (ID) URL

func (id ID) URL() *url.URL

URL returns a URL for SPIFFE ID.

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(text []byte) error

UnmarshalText decodes a text representation of the ID. If the text is empty, the ID is set to the zero value.

type Matcher

type Matcher func(ID) error

Matcher is used to match a SPIFFE ID.

func MatchAny

func MatchAny() Matcher

MatchAny matches any SPIFFE ID.

func MatchID

func MatchID(expected ID) Matcher

MatchID matches a specific SPIFFE ID.

func MatchMemberOf

func MatchMemberOf(expected TrustDomain) Matcher

MatchMemberOf matches any SPIFFE ID in the given trust domain.

func MatchOneOf

func MatchOneOf(expected ...ID) Matcher

MatchOneOf matches any SPIFFE ID in the given list of IDs.

type TrustDomain

type TrustDomain struct {
	// contains filtered or unexported fields
}

TrustDomain represents the trust domain portion of a SPIFFE ID (e.g. example.org).

func RequireTrustDomainFromString

func RequireTrustDomainFromString(s string) TrustDomain

RequireTrustDomainFromString is similar to TrustDomainFromString except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func RequireTrustDomainFromURI

func RequireTrustDomainFromURI(uri *url.URL) TrustDomain

RequireTrustDomainFromURI is similar to TrustDomainFromURI except that instead of returning an error on malformed input, it panics. It should only be used when the input is statically verifiable.

func TrustDomainFromString

func TrustDomainFromString(idOrName string) (TrustDomain, error)

TrustDomainFromString returns a new TrustDomain from a string. The string can either be a trust domain name (e.g. example.org), or a valid SPIFFE ID URI (e.g. spiffe://example.org), otherwise an error is returned. See https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE-ID.md#21-trust-domain.

func TrustDomainFromURI

func TrustDomainFromURI(uri *url.URL) (TrustDomain, error)

TrustDomainFromURI returns a new TrustDomain from a URI. The URI must be a valid SPIFFE ID (see FromURI) or an error is returned. The trust domain is extracted from the host field.

func (TrustDomain) Compare

func (td TrustDomain) Compare(other TrustDomain) int

Compare returns an integer comparing the trust domain to another lexicographically. The result will be 0 if td==other, -1 if td < other, and +1 if td > other.

func (TrustDomain) ID

func (td TrustDomain) ID() ID

ID returns the SPIFFE ID of the trust domain.

func (TrustDomain) IDString

func (td TrustDomain) IDString() string

IDString returns a string representation of the the SPIFFE ID of the trust domain, e.g. "spiffe://example.org".

func (TrustDomain) IsZero

func (td TrustDomain) IsZero() bool

IsZero returns true if the trust domain is the zero value.

func (TrustDomain) MarshalText

func (td TrustDomain) MarshalText() ([]byte, error)

MarshalText returns a text representation of the trust domain. If the trust domain is the zero value, nil is returned.

func (TrustDomain) Name added in v2.1.6

func (td TrustDomain) Name() string

Name returns the trust domain name as a string, e.g. example.org.

func (TrustDomain) String

func (td TrustDomain) String() string

String returns the trust domain name as a string, e.g. example.org.

func (*TrustDomain) UnmarshalText

func (td *TrustDomain) UnmarshalText(text []byte) error

UnmarshalText decodes a text representation of the trust domain. If the text is empty, the trust domain is set to the zero value.

Jump to

Keyboard shortcuts

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