utils

package
v7.0.0-...-185e5fd Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package utils defines several functions used across the Teleport API and other packages

Index

Constants

View Source
const (
	// ContextDelegator is a delegator for access requests set in the context
	// of the request
	ContextDelegator contextKey = "delegator"
)
View Source
const HumanTimeFormatString = "Mon Jan _2 15:04 UTC"

HumanTimeFormatString is a human readable date formatting

Variables

This section is empty.

Functions

func CopyByteSlice

func CopyByteSlice(in []byte) []byte

CopyByteSlice returns a copy of the byte slice.

func CopyByteSlices

func CopyByteSlices(in [][]byte) [][]byte

CopyByteSlices returns a copy of the byte slices.

func CopyStrings

func CopyStrings(in []string) []string

CopyStrings makes a deep copy of the passed in string slice and returns the copy.

func Deduplicate

func Deduplicate(in []string) []string

Deduplicate deduplicates list of strings

func GetDelegator

func GetDelegator(ctx context.Context) string

GetDelegator attempts to load the context value AccessRequestDelegator, returning the empty string if no value was found.

func HumanTimeFormat

func HumanTimeFormat(d time.Time) string

HumanTimeFormat formats time as recognized by humans

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

func ParseBool(value string) (bool, error)

ParseBool parses string as boolean value, returns error in case if value is not recognized

func SliceContainsStr

func SliceContainsStr(slice []string, value string) bool

SliceContainsStr returns 'true' if the slice contains the given value

func StringSlicesEqual

func StringSlicesEqual(a, b []string) bool

StringSlicesEqual returns true if string slices equal

func UTC

func UTC(t *time.Time)

UTC converts time to UTC timezone

func WithDelegator

func WithDelegator(ctx context.Context, delegator string) context.Context

WithDelegator creates a child context with the AccessRequestDelegator value set. Optionally used by AuthServer.SetAccessRequestState to log a delegating identity.

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

func (s Strings) MarshalJSON() ([]byte, error)

MarshalJSON marshals to scalar value if there is only one value in the list to list otherwise

func (Strings) MarshalYAML

func (s Strings) MarshalYAML() (interface{}, error)

MarshalYAML marshals to scalar value if there is only one value in the list, marshals to list otherwise

func (*Strings) UnmarshalJSON

func (s *Strings) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals scalar string or strings slice to Strings

func (*Strings) UnmarshalYAML

func (s *Strings) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is used to allow Strings to unmarshal from scalar string value or from the list

Directories

Path Synopsis
Package keypaths defines several keypaths used by multiple Teleport services.
Package keypaths defines several keypaths used by multiple Teleport services.
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.
Package tlsutils contains utilities for TLS configuration and formats.
Package tlsutils contains utilities for TLS configuration and formats.

Jump to

Keyboard shortcuts

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