repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/reversetunnel/agent.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/agent.go#L241-L248
go
train
// connectedToRightProxy returns true if it connected to a proxy in the // discover list.
func (a *Agent) connectedToRightProxy() bool
// connectedToRightProxy returns true if it connected to a proxy in the // discover list. func (a *Agent) connectedToRightProxy() bool
{ for _, proxy := range a.DiscoverProxies { if a.connectedTo(proxy) { return true } } return false }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/reversetunnel/agent.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/agent.go#L324-L376
go
train
// run is the main agent loop. It tries to establish a connection to the // remote proxy and then process requests that come over the tunnel. // // Once run connects to a proxy it starts processing requests from the proxy // via SSH channels opened by the remote Proxy. // // Agent sends periodic heartbeats back to the ...
func (a *Agent) run()
// run is the main agent loop. It tries to establish a connection to the // remote proxy and then process requests that come over the tunnel. // // Once run connects to a proxy it starts processing requests from the proxy // via SSH channels opened by the remote Proxy. // // Agent sends periodic heartbeats back to the ...
{ defer a.setState(agentStateDisconnected) if len(a.DiscoverProxies) != 0 { a.setStateAndPrincipals(agentStateDiscovering, nil) } else { a.setStateAndPrincipals(agentStateConnecting, nil) } // Try and connect to remote cluster. conn, err := a.connect() if err != nil || conn == nil { a.Warningf("Failed t...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/reversetunnel/agent.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/agent.go#L384-L454
go
train
// processRequests is a blocking function which runs in a loop sending heartbeats // to the given SSH connection and processes inbound requests from the // remote proxy
func (a *Agent) processRequests(conn *ssh.Client) error
// processRequests is a blocking function which runs in a loop sending heartbeats // to the given SSH connection and processes inbound requests from the // remote proxy func (a *Agent) processRequests(conn *ssh.Client) error
{ defer conn.Close() ticker := time.NewTicker(defaults.ReverseTunnelAgentHeartbeatPeriod) defer ticker.Stop() hb, reqC, err := conn.OpenChannel(chanHeartbeat, nil) if err != nil { return trace.Wrap(err) } newTransportC := conn.HandleChannelOpen(chanTransport) newDiscoveryC := conn.HandleChannelOpen(chanDisc...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/reversetunnel/agent.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/agent.go#L462-L492
go
train
// handleDisovery receives discovery requests from the reverse tunnel // server, that informs agent about proxies registered in the remote // cluster and the reverse tunnels already established // // ch : SSH channel which received "teleport-transport" out-of-band request // reqC : request payload
func (a *Agent) handleDiscovery(ch ssh.Channel, reqC <-chan *ssh.Request)
// handleDisovery receives discovery requests from the reverse tunnel // server, that informs agent about proxies registered in the remote // cluster and the reverse tunnels already established // // ch : SSH channel which received "teleport-transport" out-of-band request // reqC : request payload func (a *Agent) han...
{ a.Debugf("handleDiscovery") defer ch.Close() for { var req *ssh.Request select { case <-a.ctx.Done(): a.Infof("is closed, returning") return case req = <-reqC: if req == nil { a.Infof("connection closed, returning") return } r, err := unmarshalDiscoveryRequest(req.Payload) if er...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/retry.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/retry.go#L55-L63
go
train
// CheckAndSetDefaults checks and sets defaults
func (c *LinearConfig) CheckAndSetDefaults() error
// CheckAndSetDefaults checks and sets defaults func (c *LinearConfig) CheckAndSetDefaults() error
{ if c.Step == 0 { return trace.BadParameter("missing parameter Step") } if c.Max == 0 { return trace.BadParameter("missing parameter Max") } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/retry.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/retry.go#L66-L73
go
train
// NewLinear returns a new instance of linear retry
func NewLinear(cfg LinearConfig) (*Linear, error)
// NewLinear returns a new instance of linear retry func NewLinear(cfg LinearConfig) (*Linear, error)
{ if err := cfg.CheckAndSetDefaults(); err != nil { return nil, trace.Wrap(err) } closedChan := make(chan time.Time) close(closedChan) return &Linear{LinearConfig: cfg, closedChan: closedChan}, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/retry.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/retry.go#L98-L107
go
train
// Duration returns retry duration based on state
func (r *Linear) Duration() time.Duration
// Duration returns retry duration based on state func (r *Linear) Duration() time.Duration
{ a := r.First + time.Duration(r.attempt)*r.Step if a < 0 { return 0 } if a <= r.Max { return a } return r.Max }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/retry.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/retry.go#L112-L117
go
train
// After returns channel that fires with timeout // defined in Duration method, as a special case // if Duration is 0 returns a closed channel
func (r *Linear) After() <-chan time.Time
// After returns channel that fires with timeout // defined in Duration method, as a special case // if Duration is 0 returns a closed channel func (r *Linear) After() <-chan time.Time
{ if r.Duration() == 0 { return r.closedChan } return time.After(r.Duration()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/retry.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/retry.go#L120-L122
go
train
// String returns user-friendly representation of the LinearPeriod
func (r *Linear) String() string
// String returns user-friendly representation of the LinearPeriod func (r *Linear) String() string
{ return fmt.Sprintf("Linear(attempt=%v, duration=%v)", r.attempt, r.Duration()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/shell/shell_unix.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/shell/shell_unix.go#L46-L88
go
train
// getLoginShell determines the login shell for a given username
func getLoginShell(username string) (string, error)
// getLoginShell determines the login shell for a given username func getLoginShell(username string) (string, error)
{ // See if the username is valid. _, err := user.Lookup(username) if err != nil { return "", trace.Wrap(err) } // Based on stdlib user/lookup_unix.go packages which does not return // user shell: https://golang.org/src/os/user/lookup_unix.go var pwd C.struct_passwd var result *C.struct_passwd bufSize := ...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/fingerprint.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/fingerprint.go#L15-L21
go
train
// AuthorizedKeyFingerprint returns fingerprint from public key // in authorized key format
func AuthorizedKeyFingerprint(publicKey []byte) (string, error)
// AuthorizedKeyFingerprint returns fingerprint from public key // in authorized key format func AuthorizedKeyFingerprint(publicKey []byte) (string, error)
{ key, _, _, _, err := ssh.ParseAuthorizedKey(publicKey) if err != nil { return "", trace.Wrap(err) } return Fingerprint(key), nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/fingerprint.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/fingerprint.go#L25-L31
go
train
// PrivateKeyFingerprint returns fingerprint of the public key // extracted from the PEM encoded private key
func PrivateKeyFingerprint(keyBytes []byte) (string, error)
// PrivateKeyFingerprint returns fingerprint of the public key // extracted from the PEM encoded private key func PrivateKeyFingerprint(keyBytes []byte) (string, error)
{ signer, err := ssh.ParsePrivateKey(keyBytes) if err != nil { return "", trace.Wrap(err) } return Fingerprint(signer.PublicKey()), nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/environment.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/environment.go#L16-L71
go
train
// ReadEnvironmentFile will read environment variables from a passed in location. // Lines that start with "#" or empty lines are ignored. Assignments are in the // form name=value and no variable expansion occurs.
func ReadEnvironmentFile(filename string) ([]string, error)
// ReadEnvironmentFile will read environment variables from a passed in location. // Lines that start with "#" or empty lines are ignored. Assignments are in the // form name=value and no variable expansion occurs. func ReadEnvironmentFile(filename string) ([]string, error)
{ // open the users environment file. if we don't find a file, move on as // having this file for the user is optional. file, err := os.Open(filename) if err != nil { log.Warnf("Unable to open environment file %v: %v, skipping", filename, err) return []string{}, nil } defer file.Close() var lineno int var...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/anonymizer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/anonymizer.go#L41-L48
go
train
// NewHMACAnonymizer returns a new HMAC-based anonymizer
func NewHMACAnonymizer(key string) (*hmacAnonymizer, error)
// NewHMACAnonymizer returns a new HMAC-based anonymizer func NewHMACAnonymizer(key string) (*hmacAnonymizer, error)
{ if strings.TrimSpace(key) == "" { return nil, trace.BadParameter("HMAC key must not be empty") } return &hmacAnonymizer{ key: key, }, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/anonymizer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/anonymizer.go#L51-L55
go
train
// Anonymize anonymizes the provided data using HMAC
func (a *hmacAnonymizer) Anonymize(data []byte) string
// Anonymize anonymizes the provided data using HMAC func (a *hmacAnonymizer) Anonymize(data []byte) string
{ h := hmac.New(sha256.New, []byte(a.key)) h.Write(data) return base64.StdEncoding.EncodeToString(h.Sum(nil)) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/schema.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/schema.go#L28-L57
go
train
// UnmarshalWithSchema processes YAML or JSON encoded object with JSON schema, sets defaults // and unmarshals resulting object into given struct
func UnmarshalWithSchema(schemaDefinition string, object interface{}, data []byte) error
// UnmarshalWithSchema processes YAML or JSON encoded object with JSON schema, sets defaults // and unmarshals resulting object into given struct func UnmarshalWithSchema(schemaDefinition string, object interface{}, data []byte) error
{ schema, err := jsonschema.New([]byte(schemaDefinition)) if err != nil { return trace.Wrap(err) } jsonData, err := ToJSON(data) if err != nil { return trace.Wrap(err) } raw := map[string]interface{}{} if err := json.Unmarshal(jsonData, &raw); err != nil { return trace.Wrap(err) } // schema will check...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/archive.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/archive.go#L30-L49
go
train
// NewSessionArchive returns generated tar archive with all components
func NewSessionArchive(dataDir, serverID, namespace string, sessionID session.ID) (io.ReadCloser, error)
// NewSessionArchive returns generated tar archive with all components func NewSessionArchive(dataDir, serverID, namespace string, sessionID session.ID) (io.ReadCloser, error)
{ index, err := readSessionIndex( dataDir, []string{serverID}, namespace, sessionID) if err != nil { return nil, trace.Wrap(err) } // io.Pipe allows to generate the archive part by part // without writing to disk or generating it in memory // at the pace which reader is ready to consume it reader, writer :...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L36-L54
go
train
// ParseSigningKeyStore parses signing key store from PEM encoded key pair
func ParseSigningKeyStorePEM(keyPEM, certPEM string) (*SigningKeyStore, error)
// ParseSigningKeyStore parses signing key store from PEM encoded key pair func ParseSigningKeyStorePEM(keyPEM, certPEM string) (*SigningKeyStore, error)
{ _, err := ParseCertificatePEM([]byte(certPEM)) if err != nil { return nil, trace.Wrap(err) } key, err := ParsePrivateKeyPEM([]byte(keyPEM)) if err != nil { return nil, trace.Wrap(err) } rsaKey, ok := key.(*rsa.PrivateKey) if !ok { return nil, trace.BadParameter("key of type %T is not supported, only RS...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L105-L115
go
train
// ParseCertificateRequestPEM parses PEM-encoded certificate signing request
func ParseCertificateRequestPEM(bytes []byte) (*x509.CertificateRequest, error)
// ParseCertificateRequestPEM parses PEM-encoded certificate signing request func ParseCertificateRequestPEM(bytes []byte) (*x509.CertificateRequest, error)
{ block, _ := pem.Decode(bytes) if block == nil { return nil, trace.BadParameter("expected PEM-encoded block") } csr, err := x509.ParseCertificateRequest(block.Bytes) if err != nil { return nil, trace.BadParameter(err.Error()) } return csr, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L118-L128
go
train
// ParseCertificatePEM parses PEM-encoded certificate
func ParseCertificatePEM(bytes []byte) (*x509.Certificate, error)
// ParseCertificatePEM parses PEM-encoded certificate func ParseCertificatePEM(bytes []byte) (*x509.Certificate, error)
{ block, _ := pem.Decode(bytes) if block == nil { return nil, trace.BadParameter("expected PEM-encoded block") } cert, err := x509.ParseCertificate(block.Bytes) if err != nil { return nil, trace.BadParameter(err.Error()) } return cert, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L131-L137
go
train
// ParsePrivateKeyPEM parses PEM-encoded private key
func ParsePrivateKeyPEM(bytes []byte) (crypto.Signer, error)
// ParsePrivateKeyPEM parses PEM-encoded private key func ParsePrivateKeyPEM(bytes []byte) (crypto.Signer, error)
{ block, _ := pem.Decode(bytes) if block == nil { return nil, trace.BadParameter("expected PEM-encoded block") } return ParsePrivateKeyDER(block.Bytes) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L140-L161
go
train
// ParsePrivateKeyDER parses unencrypted DER-encoded private key
func ParsePrivateKeyDER(der []byte) (crypto.Signer, error)
// ParsePrivateKeyDER parses unencrypted DER-encoded private key func ParsePrivateKeyDER(der []byte) (crypto.Signer, error)
{ generalKey, err := x509.ParsePKCS8PrivateKey(der) if err != nil { generalKey, err = x509.ParsePKCS1PrivateKey(der) if err != nil { generalKey, err = x509.ParseECPrivateKey(der) if err != nil { logrus.Errorf("Failed to parse key: %v.", err) return nil, trace.BadParameter("failed parsing private ke...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L166-L196
go
train
// VerifyCertificateChain reads in chain of certificates and makes sure the // chain from leaf to root is valid. This ensures that clients (web browsers // and CLI) won't have problem validating the chain.
func VerifyCertificateChain(certificateChain []*x509.Certificate) error
// VerifyCertificateChain reads in chain of certificates and makes sure the // chain from leaf to root is valid. This ensures that clients (web browsers // and CLI) won't have problem validating the chain. func VerifyCertificateChain(certificateChain []*x509.Certificate) error
{ // chain needs at least one certificate if len(certificateChain) == 0 { return trace.BadParameter("need at least one certificate in chain") } // extract leaf of certificate chain. it is safe to index into the chain here // because readCertificateChain always returns a valid chain with at least // one certif...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L212-L222
go
train
// IsSelfSigned checks if the certificate is a self-signed certificate. To // check if a certificate is self signed, we make sure that only one // certificate is in the chain and that the SubjectKeyId and AuthorityKeyId // match. // // From RFC5280: https://tools.ietf.org/html/rfc5280#section-4.2.1.1 // // The signat...
func IsSelfSigned(certificateChain []*x509.Certificate) bool
// IsSelfSigned checks if the certificate is a self-signed certificate. To // check if a certificate is self signed, we make sure that only one // certificate is in the chain and that the SubjectKeyId and AuthorityKeyId // match. // // From RFC5280: https://tools.ietf.org/html/rfc5280#section-4.2.1.1 // // The signat...
{ if len(certificateChain) != 1 { return false } if bytes.Compare(certificateChain[0].SubjectKeyId, certificateChain[0].AuthorityKeyId) != 0 { return false } return true }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/certs.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/certs.go#L226-L260
go
train
// ReadCertificateChain parses PEM encoded bytes that can contain one or // multiple certificates and returns a slice of x509.Certificate.
func ReadCertificateChain(certificateChainBytes []byte) ([]*x509.Certificate, error)
// ReadCertificateChain parses PEM encoded bytes that can contain one or // multiple certificates and returns a slice of x509.Certificate. func ReadCertificateChain(certificateChainBytes []byte) ([]*x509.Certificate, error)
{ // build the certificate chain next var certificateBlock *pem.Block var remainingBytes []byte = bytes.TrimSpace(certificateChainBytes) var certificateChain [][]byte for { certificateBlock, remainingBytes = pem.Decode(remainingBytes) if certificateBlock == nil || certificateBlock.Type != pemBlockCertificate...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/timeout.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/timeout.go#L46-L52
go
train
// ObeyIdleTimeout wraps an existing network connection with timeout-obeying // Write() and Read() - it will drop the connection after 'timeout' on idle // // Example: // ObeyIdletimeout(conn, time.Second * 60, "api server").
func ObeyIdleTimeout(conn net.Conn, timeout time.Duration, ownerName string) net.Conn
// ObeyIdleTimeout wraps an existing network connection with timeout-obeying // Write() and Read() - it will drop the connection after 'timeout' on idle // // Example: // ObeyIdletimeout(conn, time.Second * 60, "api server"). func ObeyIdleTimeout(conn net.Conn, timeout time.Duration, ownerName string) net.Conn
{ return &TimeoutConn{ Conn: conn, TimeoutDuration: timeout, OwnerName: ownerName, } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L32-L52
go
train
// NewLoadBalancer returns new load balancer listening on frontend // and redirecting requests to backends using round robin algo
func NewLoadBalancer(ctx context.Context, frontend NetAddr, backends ...NetAddr) (*LoadBalancer, error)
// NewLoadBalancer returns new load balancer listening on frontend // and redirecting requests to backends using round robin algo func NewLoadBalancer(ctx context.Context, frontend NetAddr, backends ...NetAddr) (*LoadBalancer, error)
{ if ctx == nil { return nil, trace.BadParameter("missing parameter context") } waitCtx, waitCancel := context.WithCancel(ctx) return &LoadBalancer{ frontend: frontend, ctx: ctx, backends: backends, currentIndex: -1, waitCtx: waitCtx, waitCancel: waitCancel, Entry: log.WithF...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L72-L83
go
train
// trackeConnection adds connection to the connection tracker
func (l *LoadBalancer) trackConnection(backend NetAddr, conn net.Conn) int64
// trackeConnection adds connection to the connection tracker func (l *LoadBalancer) trackConnection(backend NetAddr, conn net.Conn) int64
{ l.Lock() defer l.Unlock() l.connID += 1 tracker, ok := l.connections[backend] if !ok { tracker = make(map[int64]net.Conn) l.connections[backend] = tracker } tracker[l.connID] = conn return l.connID }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L86-L94
go
train
// untrackConnection removes connection from connection tracker
func (l *LoadBalancer) untrackConnection(backend NetAddr, id int64)
// untrackConnection removes connection from connection tracker func (l *LoadBalancer) untrackConnection(backend NetAddr, id int64)
{ l.Lock() defer l.Unlock() tracker, ok := l.connections[backend] if !ok { return } delete(tracker, id) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L97-L103
go
train
// dropConnections drops connections associated with backend
func (l *LoadBalancer) dropConnections(backend NetAddr)
// dropConnections drops connections associated with backend func (l *LoadBalancer) dropConnections(backend NetAddr)
{ tracker := l.connections[backend] for _, conn := range tracker { conn.Close() } delete(l.connections, backend) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L106-L111
go
train
// AddBackend adds backend
func (l *LoadBalancer) AddBackend(b NetAddr)
// AddBackend adds backend func (l *LoadBalancer) AddBackend(b NetAddr)
{ l.Lock() defer l.Unlock() l.backends = append(l.backends, b) l.Debugf("backends %v", l.backends) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L114-L125
go
train
// RemoveBackend removes backend
func (l *LoadBalancer) RemoveBackend(b NetAddr)
// RemoveBackend removes backend func (l *LoadBalancer) RemoveBackend(b NetAddr)
{ l.Lock() defer l.Unlock() l.currentIndex = -1 for i := range l.backends { if l.backends[i].Equals(b) { l.backends = append(l.backends[:i], l.backends[i+1:]...) l.dropConnections(b) return } } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L162-L167
go
train
// ListenAndServe starts listening socket and serves connections on it
func (l *LoadBalancer) ListenAndServe() error
// ListenAndServe starts listening socket and serves connections on it func (l *LoadBalancer) ListenAndServe() error
{ if err := l.Listen(); err != nil { return trace.Wrap(err) } return l.Serve() }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L170-L178
go
train
// Listen creates a listener on the frontend addr
func (l *LoadBalancer) Listen() error
// Listen creates a listener on the frontend addr func (l *LoadBalancer) Listen() error
{ var err error l.listener, err = net.Listen(l.frontend.AddrNetwork, l.frontend.Addr) if err != nil { return trace.ConvertSystemError(err) } l.Debugf("created listening socket") return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/loadbalancer.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/loadbalancer.go#L181-L200
go
train
// Serve starts accepting connections
func (l *LoadBalancer) Serve() error
// Serve starts accepting connections func (l *LoadBalancer) Serve() error
{ defer l.waitCancel() backoffTimer := time.NewTicker(5 * time.Second) defer backoffTimer.Stop() for { conn, err := l.listener.Accept() if err != nil { if l.isClosed() { return trace.ConnectionProblem(nil, "listener is closed") } select { case <-backoffTimer.C: l.Debugf("backoff on network ...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L80-L107
go
train
// NewDiskSessionLogger creates new disk based session logger
func NewDiskSessionLogger(cfg DiskSessionLoggerConfig) (*DiskSessionLogger, error)
// NewDiskSessionLogger creates new disk based session logger func NewDiskSessionLogger(cfg DiskSessionLoggerConfig) (*DiskSessionLogger, error)
{ if err := cfg.CheckAndSetDefaults(); err != nil { return nil, trace.Wrap(err) } var err error sessionDir := filepath.Join(cfg.DataDir, cfg.ServerID, SessionLogsDir, cfg.Namespace) indexFile, err := os.OpenFile( filepath.Join(sessionDir, fmt.Sprintf("%v.index", cfg.SessionID.String())), os.O_WRONLY|os.O_CRE...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L163-L168
go
train
// Finalize is called by the session when it's closing. This is where we're // releasing audit resources associated with the session
func (sl *DiskSessionLogger) Finalize() error
// Finalize is called by the session when it's closing. This is where we're // releasing audit resources associated with the session func (sl *DiskSessionLogger) Finalize() error
{ sl.Lock() defer sl.Unlock() return sl.finalize() }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L172-L182
go
train
// flush is used to flush gzip frames to file, otherwise // some attempts to read the file could fail
func (sl *DiskSessionLogger) flush() error
// flush is used to flush gzip frames to file, otherwise // some attempts to read the file could fail func (sl *DiskSessionLogger) flush() error
{ var err, err2 error if sl.RecordSessions && sl.chunksFile != nil { err = sl.chunksFile.Flush() } if sl.eventsFile != nil { err2 = sl.eventsFile.Flush() } return trace.NewAggregate(err, err2) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L215-L217
go
train
// eventsFileName consists of session id and the first global event index recorded there
func eventsFileName(dataDir string, sessionID session.ID, eventIndex int64) string
// eventsFileName consists of session id and the first global event index recorded there func eventsFileName(dataDir string, sessionID session.ID, eventIndex int64) string
{ return filepath.Join(dataDir, fmt.Sprintf("%v-%v.events.gz", sessionID.String(), eventIndex)) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L220-L222
go
train
// chunksFileName consists of session id and the first global offset recorded
func chunksFileName(dataDir string, sessionID session.ID, offset int64) string
// chunksFileName consists of session id and the first global offset recorded func chunksFileName(dataDir string, sessionID session.ID, offset int64) string
{ return filepath.Join(dataDir, fmt.Sprintf("%v-%v.chunks.gz", sessionID.String(), offset)) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L292-L303
go
train
// PostSessionSlice takes series of events associated with the session // and writes them to events files and data file for future replays
func (sl *DiskSessionLogger) PostSessionSlice(slice SessionSlice) error
// PostSessionSlice takes series of events associated with the session // and writes them to events files and data file for future replays func (sl *DiskSessionLogger) PostSessionSlice(slice SessionSlice) error
{ sl.Lock() defer sl.Unlock() for i := range slice.Chunks { _, err := sl.writeChunk(slice.SessionID, slice.Chunks[i]) if err != nil { return trace.Wrap(err) } } return sl.flush() }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L306-L321
go
train
// EventFromChunk returns event converted from session chunk
func EventFromChunk(sessionID string, chunk *SessionChunk) (EventFields, error)
// EventFromChunk returns event converted from session chunk func EventFromChunk(sessionID string, chunk *SessionChunk) (EventFields, error)
{ var fields EventFields eventStart := time.Unix(0, chunk.Time).In(time.UTC).Round(time.Millisecond) err := json.Unmarshal(chunk.Data, &fields) if err != nil { return nil, trace.Wrap(err) } fields[SessionEventID] = sessionID fields[EventIndex] = chunk.EventIndex fields[EventTime] = eventStart fields[EventTy...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L421-L434
go
train
// Close closes gzip writer and file
func (f *gzipWriter) Close() error
// Close closes gzip writer and file func (f *gzipWriter) Close() error
{ var errors []error if f.Writer != nil { errors = append(errors, f.Writer.Close()) f.Writer.Reset(ioutil.Discard) writerPool.Put(f.Writer) f.Writer = nil } if f.file != nil { errors = append(errors, f.file.Close()) f.file = nil } return trace.NewAggregate(errors...) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/sessionlog.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/sessionlog.go#L463-L474
go
train
// Close closes file and gzip writer
func (f *gzipReader) Close() error
// Close closes file and gzip writer func (f *gzipReader) Close() error
{ var errors []error if f.ReadCloser != nil { errors = append(errors, f.ReadCloser.Close()) f.ReadCloser = nil } if f.file != nil { errors = append(errors, f.file.Close()) f.file = nil } return trace.NewAggregate(errors...) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L78-L85
go
train
// CheckAndSetDefaults checks values and sets defaults
func (h HeartbeatMode) CheckAndSetDefaults() error
// CheckAndSetDefaults checks values and sets defaults func (h HeartbeatMode) CheckAndSetDefaults() error
{ switch h { case HeartbeatModeNode, HeartbeatModeProxy, HeartbeatModeAuth: return nil default: return trace.BadParameter("unrecognized mode") } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L88-L99
go
train
// String returns user-friendly representation of the mode
func (h HeartbeatMode) String() string
// String returns user-friendly representation of the mode func (h HeartbeatMode) String() string
{ switch h { case HeartbeatModeNode: return "Node" case HeartbeatModeProxy: return "Proxy" case HeartbeatModeAuth: return "Auth" default: return fmt.Sprintf("<unknown: %v>", int(h)) } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L114-L132
go
train
// NewHeartbeat returns a new instance of heartbeat
func NewHeartbeat(cfg HeartbeatConfig) (*Heartbeat, error)
// NewHeartbeat returns a new instance of heartbeat func NewHeartbeat(cfg HeartbeatConfig) (*Heartbeat, error)
{ if err := cfg.CheckAndSetDefaults(); err != nil { return nil, trace.Wrap(err) } ctx, cancel := context.WithCancel(cfg.Context) h := &Heartbeat{ cancelCtx: ctx, cancel: cancel, HeartbeatConfig: cfg, Entry: log.WithFields(log.Fields{ trace.Component: teleport.Component(cfg.Component, "b...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L168-L201
go
train
// CheckAndSetDefaults checks and sets default values
func (cfg *HeartbeatConfig) CheckAndSetDefaults() error
// CheckAndSetDefaults checks and sets default values func (cfg *HeartbeatConfig) CheckAndSetDefaults() error
{ if err := cfg.Mode.CheckAndSetDefaults(); err != nil { return trace.Wrap(err) } if cfg.Context == nil { return trace.BadParameter("missing parameter Context") } if cfg.Announcer == nil { return trace.BadParameter("missing parameter Announcer") } if cfg.Component == "" { return trace.BadParameter("miss...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L233-L251
go
train
// Run periodically calls to announce presence, // should be called explicitly in a separate goroutine
func (h *Heartbeat) Run() error
// Run periodically calls to announce presence, // should be called explicitly in a separate goroutine func (h *Heartbeat) Run() error
{ defer func() { h.reset(HeartbeatStateInit) h.checkTicker.Stop() }() for { if err := h.fetchAndAnnounce(); err != nil { h.Warningf("Heartbeat failed %v.", err) } select { case <-h.checkTicker.C: case <-h.sendC: h.Debugf("Asked check out of cycle") case <-h.cancelCtx.Done(): h.Debugf("Heart...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L276-L287
go
train
// reset resets keep alive state // and sends the state back to the initial state // of sending full update
func (h *Heartbeat) reset(state KeepAliveState)
// reset resets keep alive state // and sends the state back to the initial state // of sending full update func (h *Heartbeat) reset(state KeepAliveState)
{ h.setState(state) h.nextAnnounce = time.Time{} h.nextKeepAlive = time.Time{} h.keepAlive = nil if h.keepAliver != nil { if err := h.keepAliver.Close(); err != nil { h.Warningf("Failed to close keep aliver: %v", err) } h.keepAliver = nil } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L291-L343
go
train
// fetch, if succeeded updates or sets current server // to the last received server
func (h *Heartbeat) fetch() error
// fetch, if succeeded updates or sets current server // to the last received server func (h *Heartbeat) fetch() error
{ // failed to fetch server info? // reset to init state regardless of the current state server, err := h.GetServerInfo() if err != nil { h.reset(HeartbeatStateInit) return trace.Wrap(err) } switch h.state { // in case of successfull state fetch, move to announce from init case HeartbeatStateInit: h.curr...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L433-L441
go
train
// fetchAndAnnounce fetches data about server // and announces it to the server
func (h *Heartbeat) fetchAndAnnounce() error
// fetchAndAnnounce fetches data about server // and announces it to the server func (h *Heartbeat) fetchAndAnnounce() error
{ if err := h.fetch(); err != nil { return trace.Wrap(err) } if err := h.announce(); err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/heartbeat.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/heartbeat.go#L445-L458
go
train
// ForceSend forces send cycle, used in tests, returns // nil in case of success, error otherwise
func (h *Heartbeat) ForceSend(timeout time.Duration) error
// ForceSend forces send cycle, used in tests, returns // nil in case of success, error otherwise func (h *Heartbeat) ForceSend(timeout time.Duration) error
{ timeoutC := time.After(timeout) select { case h.sendC <- struct{}{}: case <-timeoutC: return trace.ConnectionProblem(nil, "timeout waiting for send") } select { case <-h.announceC: return nil case <-timeoutC: return trace.ConnectionProblem(nil, "timeout waiting for announce to be sent") } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L65-L86
go
train
// CheckAndSetDefaults is a helper returns an error if the supplied configuration // is not enough to connect to DynamoDB
func (cfg *Config) CheckAndSetDefaults() error
// CheckAndSetDefaults is a helper returns an error if the supplied configuration // is not enough to connect to DynamoDB func (cfg *Config) CheckAndSetDefaults() error
{ // table is not configured? if cfg.Tablename == "" { return trace.BadParameter("DynamoDB: table_name is not specified") } if cfg.ReadCapacityUnits == 0 { cfg.ReadCapacityUnits = DefaultReadCapacityUnits } if cfg.WriteCapacityUnits == 0 { cfg.WriteCapacityUnits = DefaultWriteCapacityUnits } if cfg.Reten...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L148-L199
go
train
// New returns new instance of DynamoDB backend. // It's an implementation of backend API's NewFunc
func New(cfg Config) (*Log, error)
// New returns new instance of DynamoDB backend. // It's an implementation of backend API's NewFunc func New(cfg Config) (*Log, error)
{ l := log.WithFields(log.Fields{ trace.Component: teleport.Component(teleport.ComponentDynamoDB), }) l.Info("Initializing event backend.") if err := cfg.CheckAndSetDefaults(); err != nil { return nil, trace.Wrap(err) } b := &Log{ Entry: l, Config: cfg, } // create an AWS session using default SDK be...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L211-L254
go
train
// EmitAuditEvent emits audit event
func (l *Log) EmitAuditEvent(ev events.Event, fields events.EventFields) error
// EmitAuditEvent emits audit event func (l *Log) EmitAuditEvent(ev events.Event, fields events.EventFields) error
{ sessionID := fields.GetString(events.SessionEventID) eventIndex := fields.GetInt(events.EventIndex) // no session id - global event gets a random uuid to get a good partition // key distribution if sessionID == "" { sessionID = uuid.New() } err := events.UpdateEventFields(ev, fields, l.Clock, l.UIDGenerator...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L264-L314
go
train
// PostSessionSlice sends chunks of recorded session to the event log
func (l *Log) PostSessionSlice(slice events.SessionSlice) error
// PostSessionSlice sends chunks of recorded session to the event log func (l *Log) PostSessionSlice(slice events.SessionSlice) error
{ var requests []*dynamodb.WriteRequest for _, chunk := range slice.Chunks { // if legacy event with no type or print event, skip it if chunk.EventType == events.SessionPrintEvent || chunk.EventType == "" { continue } fields, err := events.EventFromChunk(slice.SessionID, chunk) if err != nil { return...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L325-L327
go
train
// GetSessionChunk returns a reader which can be used to read a byte stream // of a recorded session starting from 'offsetBytes' (pass 0 to start from the // beginning) up to maxBytes bytes. // // If maxBytes > MaxChunkBytes, it gets rounded down to MaxChunkBytes
func (l *Log) GetSessionChunk(namespace string, sid session.ID, offsetBytes, maxBytes int) ([]byte, error)
// GetSessionChunk returns a reader which can be used to read a byte stream // of a recorded session starting from 'offsetBytes' (pass 0 to start from the // beginning) up to maxBytes bytes. // // If maxBytes > MaxChunkBytes, it gets rounded down to MaxChunkBytes func (l *Log) GetSessionChunk(namespace string, sid sess...
{ return nil, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L336-L367
go
train
// Returns all events that happen during a session sorted by time // (oldest first). // // after tells to use only return events after a specified cursor Id // // This function is usually used in conjunction with GetSessionReader to // replay recorded session streams.
func (l *Log) GetSessionEvents(namespace string, sid session.ID, after int, inlcudePrintEvents bool) ([]events.EventFields, error)
// Returns all events that happen during a session sorted by time // (oldest first). // // after tells to use only return events after a specified cursor Id // // This function is usually used in conjunction with GetSessionReader to // replay recorded session streams. func (l *Log) GetSessionEvents(namespace string, si...
{ var values []events.EventFields query := "SessionID = :sessionID AND EventIndex >= :eventIndex" attributes := map[string]interface{}{ ":sessionID": string(sid), ":eventIndex": after, } attributeValues, err := dynamodbattribute.MarshalMap(attributes) input := dynamodb.QueryInput{ KeyConditionExpression: ...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L377-L437
go
train
// SearchEvents is a flexible way to find The format of a query string // depends on the implementing backend. A recommended format is urlencoded // (good enough for Lucene/Solr) // // Pagination is also defined via backend-specific query format. // // The only mandatory requirement is a date range (UTC). Results must...
func (l *Log) SearchEvents(fromUTC, toUTC time.Time, filter string, limit int) ([]events.EventFields, error)
// SearchEvents is a flexible way to find The format of a query string // depends on the implementing backend. A recommended format is urlencoded // (good enough for Lucene/Solr) // // Pagination is also defined via backend-specific query format. // // The only mandatory requirement is a date range (UTC). Results must...
{ g := l.WithFields(log.Fields{"From": fromUTC, "To": toUTC, "Filter": filter, "Limit": limit}) filterVals, err := url.ParseQuery(filter) if err != nil { return nil, trace.BadParameter("missing parameter query") } eventFilter, ok := filterVals[events.EventType] if !ok && len(filterVals) > 0 { return nil, nil...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L441-L449
go
train
// SearchSessionEvents returns session related events only. This is used to // find completed session.
func (l *Log) SearchSessionEvents(fromUTC time.Time, toUTC time.Time, limit int) ([]events.EventFields, error)
// SearchSessionEvents returns session related events only. This is used to // find completed session. func (l *Log) SearchSessionEvents(fromUTC time.Time, toUTC time.Time, limit int) ([]events.EventFields, error)
{ // only search for specific event types query := url.Values{} query[events.EventType] = []string{ events.SessionStartEvent, events.SessionEndEvent, } return l.SearchEvents(fromUTC, toUTC, query.Encode(), limit) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L479-L491
go
train
// getTableStatus checks if a given table exists
func (b *Log) getTableStatus(tableName string) (tableStatus, error)
// getTableStatus checks if a given table exists func (b *Log) getTableStatus(tableName string) (tableStatus, error)
{ _, err := b.svc.DescribeTable(&dynamodb.DescribeTableInput{ TableName: aws.String(tableName), }) err = convertError(err) if err != nil { if trace.IsNotFound(err) { return tableStatusMissing, nil } return tableStatusError, trace.Wrap(err) } return tableStatusOK, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L499-L569
go
train
// createTable creates a DynamoDB table with a requested name and applies // the back-end schema to it. The table must not exist. // // rangeKey is the name of the 'range key' the schema requires. // currently is always set to "FullPath" (used to be something else, that's // why it's a parameter for migration purposes)
func (b *Log) createTable(tableName string) error
// createTable creates a DynamoDB table with a requested name and applies // the back-end schema to it. The table must not exist. // // rangeKey is the name of the 'range key' the schema requires. // currently is always set to "FullPath" (used to be something else, that's // why it's a parameter for migration purposes)...
{ provisionedThroughput := dynamodb.ProvisionedThroughput{ ReadCapacityUnits: aws.Int64(b.ReadCapacityUnits), WriteCapacityUnits: aws.Int64(b.WriteCapacityUnits), } def := []*dynamodb.AttributeDefinition{ { AttributeName: aws.String(keySessionID), AttributeType: aws.String("S"), }, { AttributeNa...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L572-L602
go
train
// deleteAllItems deletes all items from the database, used in tests
func (b *Log) deleteAllItems() error
// deleteAllItems deletes all items from the database, used in tests func (b *Log) deleteAllItems() error
{ out, err := b.svc.Scan(&dynamodb.ScanInput{TableName: aws.String(b.Tablename)}) if err != nil { return trace.Wrap(err) } var requests []*dynamodb.WriteRequest for _, item := range out.Items { requests = append(requests, &dynamodb.WriteRequest{ DeleteRequest: &dynamodb.DeleteRequest{ Key: map[string]*...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L655-L657
go
train
// Swap is part of sort.Interface.
func (e eventlist) Swap(i, j int)
// Swap is part of sort.Interface. func (e eventlist) Swap(i, j int)
{ e[i], e[j] = e[j], e[i] }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/events/dynamoevents/dynamoevents.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/dynamoevents/dynamoevents.go#L660-L662
go
train
// Less is part of sort.Interface.
func (e eventlist) Less(i, j int) bool
// Less is part of sort.Interface. func (e eventlist) Less(i, j int) bool
{ return e[i].EventIndex < e[j].EventIndex }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/local/events.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/events.go#L39-L44
go
train
// NewEventsService returns new events service instance
func NewEventsService(b backend.Backend) *EventsService
// NewEventsService returns new events service instance func NewEventsService(b backend.Backend) *EventsService
{ return &EventsService{ Entry: logrus.WithFields(logrus.Fields{trace.Component: "Events"}), backend: b, } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/local/events.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/events.go#L47-L103
go
train
// NewWatcher returns a new event watcher
func (e *EventsService) NewWatcher(ctx context.Context, watch services.Watch) (services.Watcher, error)
// NewWatcher returns a new event watcher func (e *EventsService) NewWatcher(ctx context.Context, watch services.Watch) (services.Watcher, error)
{ if len(watch.Kinds) == 0 { return nil, trace.BadParameter("global watches are not supported yet") } var parsers []resourceParser var prefixes [][]byte for _, kind := range watch.Kinds { if kind.Name != "" && kind.Kind != services.KindNamespace { return nil, trace.BadParameter("watch with Name is only sup...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/local/events.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/events.go#L715-L721
go
train
// base returns last element delimited by separator, index is // is an index of the key part to get counting from the end
func base(key []byte, offset int) ([]byte, error)
// base returns last element delimited by separator, index is // is an index of the key part to get counting from the end func base(key []byte, offset int) ([]byte, error)
{ parts := bytes.Split(key, []byte{backend.Separator}) if len(parts) < offset+1 { return nil, trace.NotFound("failed parsing %v", string(key)) } return parts[len(parts)-offset-1], nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/local/events.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/local/events.go#L724-L730
go
train
// baseTwoKeys returns two last keys
func baseTwoKeys(key []byte) (string, string, error)
// baseTwoKeys returns two last keys func baseTwoKeys(key []byte) (string, string, error)
{ parts := bytes.Split(key, []byte{backend.Separator}) if len(parts) < 2 { return "", "", trace.NotFound("failed parsing %v", string(key)) } return string(parts[len(parts)-2]), string(parts[len(parts)-1]), nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/api.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/api.go#L142-L147
go
train
// NewWrapper returns new access point wrapper
func NewWrapper(writer AccessPoint, cache ReadAccessPoint) AccessPoint
// NewWrapper returns new access point wrapper func NewWrapper(writer AccessPoint, cache ReadAccessPoint) AccessPoint
{ return &Wrapper{ Write: writer, ReadAccessPoint: cache, } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/api.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/api.go#L158-L160
go
train
// UpsertNode is part of auth.AccessPoint implementation
func (w *Wrapper) UpsertNode(s services.Server) (*services.KeepAlive, error)
// UpsertNode is part of auth.AccessPoint implementation func (w *Wrapper) UpsertNode(s services.Server) (*services.KeepAlive, error)
{ return w.Write.UpsertNode(s) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/api.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/api.go#L163-L165
go
train
// UpsertAuthServer is part of auth.AccessPoint implementation
func (w *Wrapper) UpsertAuthServer(s services.Server) error
// UpsertAuthServer is part of auth.AccessPoint implementation func (w *Wrapper) UpsertAuthServer(s services.Server) error
{ return w.Write.UpsertAuthServer(s) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/api.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/api.go#L168-L170
go
train
// NewKeepAliver returns a new instance of keep aliver
func (w *Wrapper) NewKeepAliver(ctx context.Context) (services.KeepAliver, error)
// NewKeepAliver returns a new instance of keep aliver func (w *Wrapper) NewKeepAliver(ctx context.Context) (services.KeepAliver, error)
{ return w.Write.NewKeepAliver(ctx) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/api.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/api.go#L173-L175
go
train
// UpsertProxy is part of auth.AccessPoint implementation
func (w *Wrapper) UpsertProxy(s services.Server) error
// UpsertProxy is part of auth.AccessPoint implementation func (w *Wrapper) UpsertProxy(s services.Server) error
{ return w.Write.UpsertProxy(s) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/api.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/api.go#L178-L180
go
train
// UpsertTunnelConnection is a part of auth.AccessPoint implementation
func (w *Wrapper) UpsertTunnelConnection(conn services.TunnelConnection) error
// UpsertTunnelConnection is a part of auth.AccessPoint implementation func (w *Wrapper) UpsertTunnelConnection(conn services.TunnelConnection) error
{ return w.Write.UpsertTunnelConnection(conn) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/api.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/api.go#L183-L185
go
train
// DeleteTunnelConnection is a part of auth.AccessPoint implementation
func (w *Wrapper) DeleteTunnelConnection(clusterName, connName string) error
// DeleteTunnelConnection is a part of auth.AccessPoint implementation func (w *Wrapper) DeleteTunnelConnection(clusterName, connName string) error
{ return w.Write.DeleteTunnelConnection(clusterName, connName) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L113-L118
go
train
// SetShutdownPollPeriod sets a polling period for graceful shutdowns of SSH servers
func SetShutdownPollPeriod(period time.Duration) ServerOption
// SetShutdownPollPeriod sets a polling period for graceful shutdowns of SSH servers func SetShutdownPollPeriod(period time.Duration) ServerOption
{ return func(s *Server) error { s.shutdownPollPeriod = period return nil } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L268-L273
go
train
// Wait waits until server stops serving new connections // on the listener socket
func (s *Server) Wait(ctx context.Context)
// Wait waits until server stops serving new connections // on the listener socket func (s *Server) Wait(ctx context.Context)
{ select { case <-s.closeContext.Done(): case <-ctx.Done(): } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L277-L305
go
train
// Shutdown initiates graceful shutdown - waiting until all active // connections will get closed
func (s *Server) Shutdown(ctx context.Context) error
// Shutdown initiates graceful shutdown - waiting until all active // connections will get closed func (s *Server) Shutdown(ctx context.Context) error
{ // close listener to stop receiving new connections err := s.Close() s.Wait(ctx) activeConnections := s.trackConnections(0) if activeConnections == 0 { return err } s.Infof("Shutdown: waiting for %v connections to finish.", activeConnections) lastReport := time.Time{} ticker := time.NewTicker(s.shutdownPo...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L308-L330
go
train
// Close closes listening socket and stops accepting connections
func (s *Server) Close() error
// Close closes listening socket and stops accepting connections func (s *Server) Close() error
{ s.Lock() defer s.Unlock() // If no listener is set, the server is in tunnel mode which means // closeFunc has to be manually called. if s.listener == nil { s.closeFunc() return nil } // listener already closed, nothing to do if s.listenerClosed { return nil } s.listenerClosed = true if s.listener...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L368-L449
go
train
// HandleConnection is called every time an SSH server accepts a new // connection from a client. // // this is the foundation of all SSH connections in Teleport (between clients // and proxies, proxies and servers, servers and auth, etc). //
func (s *Server) HandleConnection(conn net.Conn)
// HandleConnection is called every time an SSH server accepts a new // connection from a client. // // this is the foundation of all SSH connections in Teleport (between clients // and proxies, proxies and servers, servers and auth, etc). // func (s *Server) HandleConnection(conn net.Conn)
{ s.trackConnections(1) defer s.trackConnections(-1) // initiate an SSH connection, note that we don't need to close the conn here // in case of error as ssh server takes care of this remoteAddr, _, err := net.SplitHostPort(conn.RemoteAddr().String()) if err != nil { log.Errorf(err.Error()) } if err := s.lim...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L506-L522
go
train
// validateHostSigner make sure the signer is a valid certificate.
func validateHostSigner(signer ssh.Signer) error
// validateHostSigner make sure the signer is a valid certificate. func validateHostSigner(signer ssh.Signer) error
{ cert, ok := signer.PublicKey().(*ssh.Certificate) if !ok { return trace.BadParameter("only host certificates supported") } if len(cert.ValidPrincipals) == 0 { return trace.BadParameter("at least one valid principal is required in host certificate") } certChecker := utils.CertChecker{} err := certChecker....
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L528-L532
go
train
// KeysEqual is constant time compare of the keys to avoid timing attacks
func KeysEqual(ak, bk ssh.PublicKey) bool
// KeysEqual is constant time compare of the keys to avoid timing attacks func KeysEqual(ak, bk ssh.PublicKey) bool
{ a := ssh.Marshal(ak) b := ssh.Marshal(bk) return (len(a) == len(b) && subtle.ConstantTimeCompare(a, b) == 1) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L568-L612
go
train
// Read implements io.Read() part of net.Connection which allows us // peek at the beginning of SSH handshake (that's why we're wrapping the connection)
func (c *connectionWrapper) Read(b []byte) (int, error)
// Read implements io.Read() part of net.Connection which allows us // peek at the beginning of SSH handshake (that's why we're wrapping the connection) func (c *connectionWrapper) Read(b []byte) (int, error)
{ // handshake already took place, forward upstream: if c.upstreamReader != nil { return c.upstreamReader.Read(b) } // inspect the client's hello message and see if it's a teleport // proxy connecting? buff := make([]byte, MaxVersionStringBytes) n, err := c.Conn.Read(buff) if err != nil { // EOF happens qu...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/sshutils/server.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/server.go#L616-L621
go
train
// wrapConnection takes a network connection, wraps it into connectionWrapper // object (which overrides Read method) and returns the wrapper.
func wrapConnection(conn net.Conn) net.Conn
// wrapConnection takes a network connection, wraps it into connectionWrapper // object (which overrides Read method) and returns the wrapper. func wrapConnection(conn net.Conn) net.Conn
{ return &connectionWrapper{ Conn: conn, clientAddr: conn.RemoteAddr(), } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L132-L134
go
train
// String returns a user-friendly description // of the watcher
func (w *Watch) String() string
// String returns a user-friendly description // of the watcher func (w *Watch) String() string
{ return fmt.Sprintf("Watcher(name=%v, prefixes=%v)", w.Name, string(bytes.Join(w.Prefixes, []byte(", ")))) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L229-L236
go
train
// GetString returns a string value stored in Params map, or an empty string // if nothing is found
func (p Params) GetString(key string) string
// GetString returns a string value stored in Params map, or an empty string // if nothing is found func (p Params) GetString(key string) string
{ v, ok := p[key] if !ok { return "" } s, _ := v.(string) return s }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L242-L254
go
train
// RangeEnd returns end of the range for given key
func RangeEnd(key []byte) []byte
// RangeEnd returns end of the range for given key func RangeEnd(key []byte) []byte
{ end := make([]byte, len(key)) copy(end, key) for i := len(end) - 1; i >= 0; i-- { if end[i] < 0xff { end[i] = end[i] + 1 end = end[:i+1] return end } } // next key does not exist (e.g., 0xffff); return noEnd }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L269-L271
go
train
// Swap is part of sort.Interface.
func (it Items) Swap(i, j int)
// Swap is part of sort.Interface. func (it Items) Swap(i, j int)
{ it[i], it[j] = it[j], it[i] }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L279-L285
go
train
// TTL returns TTL in duration units, rounds up to one second
func TTL(clock clockwork.Clock, expires time.Time) time.Duration
// TTL returns TTL in duration units, rounds up to one second func TTL(clock clockwork.Clock, expires time.Time) time.Duration
{ ttl := expires.Sub(clock.Now()) if ttl < time.Second { return time.Second } return ttl }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L289-L295
go
train
// EarliestExpiry returns first of the // otherwise returns empty
func EarliestExpiry(times ...time.Time) time.Time
// EarliestExpiry returns first of the // otherwise returns empty func EarliestExpiry(times ...time.Time) time.Time
{ if len(times) == 0 { return time.Time{} } sort.Sort(earliest(times)) return times[0] }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L299-L304
go
train
// Expiry converts ttl to expiry time, if ttl is 0 // returns empty time
func Expiry(clock clockwork.Clock, ttl time.Duration) time.Time
// Expiry converts ttl to expiry time, if ttl is 0 // returns empty time func Expiry(clock clockwork.Clock, ttl time.Duration) time.Time
{ if ttl == 0 { return time.Time{} } return clock.Now().UTC().Add(ttl) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/backend/backend.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/backend.go#L331-L333
go
train
// Key joins parts into path separated by Separator, // makes sure path always starts with Separator ("/")
func Key(parts ...string) []byte
// Key joins parts into path separated by Separator, // makes sure path always starts with Separator ("/") func Key(parts ...string) []byte
{ return []byte(strings.Join(append([]string{""}, parts...), string(Separator))) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/utils/agentconn/agent_unix.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/agentconn/agent_unix.go#L28-L35
go
train
// Dial creates net.Conn to a SSH agent listening on a Unix socket.
func Dial(socket string) (net.Conn, error)
// Dial creates net.Conn to a SSH agent listening on a Unix socket. func Dial(socket string) (net.Conn, error)
{ conn, err := net.Dial("unix", socket) if err != nil { return nil, trace.Wrap(err) } return conn, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/authentication.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/authentication.go#L77-L87
go
train
// NewAuthPreference is a convenience method to to create AuthPreferenceV2.
func NewAuthPreference(spec AuthPreferenceSpecV2) (AuthPreference, error)
// NewAuthPreference is a convenience method to to create AuthPreferenceV2. func NewAuthPreference(spec AuthPreferenceSpecV2) (AuthPreference, error)
{ return &AuthPreferenceV2{ Kind: KindClusterAuthPreference, Version: V2, Metadata: Metadata{ Name: MetaNameClusterAuthPreference, Namespace: defaults.Namespace, }, Spec: spec, }, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/authentication.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/authentication.go#L108-L110
go
train
// SetExpiry sets expiry time for the object
func (s *AuthPreferenceV2) SetExpiry(expires time.Time)
// SetExpiry sets expiry time for the object func (s *AuthPreferenceV2) SetExpiry(expires time.Time)
{ s.Metadata.SetExpiry(expires) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/authentication.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/authentication.go#L175-L180
go
train
// GetU2F gets the U2F configuration settings.
func (c *AuthPreferenceV2) GetU2F() (*U2F, error)
// GetU2F gets the U2F configuration settings. func (c *AuthPreferenceV2) GetU2F() (*U2F, error)
{ if c.Spec.U2F == nil { return nil, trace.NotFound("U2F configuration not found") } return c.Spec.U2F, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/authentication.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/authentication.go#L188-L212
go
train
// CheckAndSetDefaults verifies the constraints for AuthPreference.
func (c *AuthPreferenceV2) CheckAndSetDefaults() error
// CheckAndSetDefaults verifies the constraints for AuthPreference. func (c *AuthPreferenceV2) CheckAndSetDefaults() error
{ // if nothing is passed in, set defaults if c.Spec.Type == "" { c.Spec.Type = teleport.Local } if c.Spec.SecondFactor == "" { c.Spec.SecondFactor = teleport.OTP } // make sure type makes sense switch c.Spec.Type { case teleport.Local, teleport.OIDC, teleport.SAML, teleport.Github: default: return tra...
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/authentication.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/authentication.go#L215-L217
go
train
// String represents a human readable version of authentication settings.
func (c *AuthPreferenceV2) String() string
// String represents a human readable version of authentication settings. func (c *AuthPreferenceV2) String() string
{ return fmt.Sprintf("AuthPreference(Type=%q,SecondFactor=%q)", c.Spec.Type, c.Spec.SecondFactor) }