Documentation ¶
Overview ¶
Package utils defines several functions used across the Teleport API and other packages
Index ¶
- Constants
- func CopyStrings(in []string) []string
- func DecodeClusterName(serverName string) (string, error)
- func Deduplicate(in []string) []string
- func EncodeClusterName(clusterName string) string
- func GetDelegator(ctx context.Context) string
- func HumanTimeFormat(d time.Time) string
- func IsLoopback(host string) bool
- func JoinStrings[T ~string](elems []T, sep string) T
- func MapToStrings(m map[string]string) []string
- func ObjectToStruct(in interface{}, out interface{}) error
- func ParseBool(value string) (bool, error)
- func ParseSessionsURI(in string) (*url.URL, error)
- func StrictObjectToStruct(in interface{}, out interface{}) error
- func ToLowerStrings(strs []string) []string
- func UTC(t *time.Time)
- func WithDelegator(ctx context.Context, delegator string) context.Context
- type Strings
Constants ¶
const ( // ContextDelegator is a delegator for access requests set in the context // of the request ContextDelegator contextKey = "delegator" )
const HumanTimeFormatString = "Mon Jan _2 15:04 UTC"
HumanTimeFormatString is a human readable date formatting
Variables ¶
This section is empty.
Functions ¶
func CopyStrings ¶
CopyStrings makes a deep copy of the passed in string slice and returns the copy.
func DecodeClusterName ¶
DecodeClusterName decodes cluster name, returns NotFound if no cluster name is encoded (empty subdomain), so servers can detect cases when no server name passed returns BadParameter if encoding does not match
func EncodeClusterName ¶
EncodeClusterName encodes cluster name in the SNI hostname
func GetDelegator ¶
GetDelegator attempts to load the context value AccessRequestDelegator, returning the empty string if no value was found.
func HumanTimeFormat ¶
HumanTimeFormat formats time as recognized by humans
func IsLoopback ¶
IsLoopback returns 'true' if a given hostname resolves *only* to the local host's loopback interface
func JoinStrings ¶
JoinStrings returns a string that is all the elements in the slice `T[]` joined by `sep` This being generic allows for the usage of custom string times, without having to convert the elements to a string to be passed into `strings.Join`.
func MapToStrings ¶
MapToStrings collects keys and values of a map into a slice of strings.
func ObjectToStruct ¶
func ObjectToStruct(in interface{}, out interface{}) error
ObjectToStruct is converts any structure into JSON and then unmarshalls it into another structure.
Teleport configuration uses this (strange, at first) trick to convert from one struct type to another, if their fields are loosely compatible via their `json` tags
Example: assume you have two structs:
type A struct { Name string `json:"name"` Age int `json:"age"` } type B struct { FullName string `json:"name"` }
Now you can convert B to A:
b := &B{ FullName: "Bob Dilan"} var a *A utils.ObjectToStruct(b, &a) fmt.Println(a.Name) > "Bob Dilan"
func ParseBool ¶
ParseBool parses string as boolean value, returns error in case if value is not recognized
func ParseSessionsURI ¶
ParseSessionsURI parses uri per convention of session upload URIs file is a default scheme
func StrictObjectToStruct ¶
func StrictObjectToStruct(in interface{}, out interface{}) error
StrictObjectToStruct converts any structure into JSON and then unmarshalls it into another structure using a strict decoder.
func ToLowerStrings ¶
ToLowerStrings lower cases each string in a slice.
Types ¶
type Strings ¶
type Strings []string
Strings is a list of string that can unmarshal from list of strings or a scalar string from scalar yaml or json property
func (Strings) MarshalJSON ¶
MarshalJSON marshals to scalar value if there is only one value in the list to list otherwise
func (Strings) MarshalYAML ¶
MarshalYAML marshals to scalar value if there is only one value in the list, marshals to list otherwise
func (*Strings) UnmarshalJSON ¶
UnmarshalJSON unmarshals scalar string or strings slice to Strings
func (*Strings) UnmarshalYAML ¶
UnmarshalYAML is used to allow Strings to unmarshal from scalar string value or from the list
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package keypaths defines several keypaths used by multiple Teleport services.
|
Package keypaths defines several keypaths used by multiple Teleport services. |
Package keys defines common interfaces for Teleport client keys.
|
Package keys defines common interfaces for Teleport client keys. |
Package retryutils defines common retry and jitter logic.
|
Package retryutils defines common retry and jitter logic. |
Package sshutils defines several functions and types used across the Teleport API and other Teleport packages when working with SSH.
|
Package sshutils defines several functions and types used across the Teleport API and other Teleport packages when working with SSH. |
ppk
Package ppk provides functions implementing conversion between Teleport's native RSA keypairs and PuTTY's PPK format.
|
Package ppk provides functions implementing conversion between Teleport's native RSA keypairs and PuTTY's PPK format. |
Package tlsutils contains utilities for TLS configuration and formats.
|
Package tlsutils contains utilities for TLS configuration and formats. |