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/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1136-L1142
go
train
// DeleteRemoteCluster deletes remote cluster by name
func (c *Client) DeleteRemoteCluster(clusterName string) error
// DeleteRemoteCluster deletes remote cluster by name func (c *Client) DeleteRemoteCluster(clusterName string) error
{ if clusterName == "" { return trace.BadParameter("missing parameter cluster name") } _, err := c.Delete(c.Endpoint("remoteclusters", clusterName)) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1151-L1161
go
train
// CreateRemoteCluster creates remote cluster resource
func (c *Client) CreateRemoteCluster(rc services.RemoteCluster) error
// CreateRemoteCluster creates remote cluster resource func (c *Client) CreateRemoteCluster(rc services.RemoteCluster) error
{ data, err := services.MarshalRemoteCluster(rc) if err != nil { return trace.Wrap(err) } args := &createRemoteClusterRawReq{ RemoteCluster: data, } _, err = c.PostJSON(c.Endpoint("remoteclusters"), args) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1178-L1196
go
train
// GetAuthServers returns the list of auth servers registered in the cluster.
func (c *Client) GetAuthServers() ([]services.Server, error)
// GetAuthServers returns the list of auth servers registered in the cluster. func (c *Client) GetAuthServers() ([]services.Server, error)
{ out, err := c.Get(c.Endpoint("authservers"), url.Values{}) if err != nil { return nil, trace.Wrap(err) } var items []json.RawMessage if err := json.Unmarshal(out.Bytes(), &items); err != nil { return nil, trace.Wrap(err) } re := make([]services.Server, len(items)) for i, raw := range items { server, err := services.GetServerMarshaler().UnmarshalServer(raw, services.KindAuthServer, services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } re[i] = server } return re, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1210-L1220
go
train
// UpsertProxy is used by proxies to report their presence // to other auth servers in form of hearbeat expiring after ttl period.
func (c *Client) UpsertProxy(s services.Server) error
// UpsertProxy is used by proxies to report their presence // to other auth servers in form of hearbeat expiring after ttl period. func (c *Client) UpsertProxy(s services.Server) error
{ data, err := services.GetServerMarshaler().MarshalServer(s) if err != nil { return trace.Wrap(err) } args := &upsertServerRawReq{ Server: data, } _, err = c.PostJSON(c.Endpoint("proxies"), args) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1244-L1250
go
train
// DeleteAllProxies deletes all proxies
func (c *Client) DeleteAllProxies() error
// DeleteAllProxies deletes all proxies func (c *Client) DeleteAllProxies() error
{ _, err := c.Delete(c.Endpoint("proxies")) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1278-L1289
go
train
// UpsertPassword updates web access password for the user
func (c *Client) UpsertPassword(user string, password []byte) error
// UpsertPassword updates web access password for the user func (c *Client) UpsertPassword(user string, password []byte) error
{ _, err := c.PostJSON( c.Endpoint("users", user, "web", "password"), upsertPasswordReq{ Password: string(password), }) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1292-L1299
go
train
// UpsertUser user updates or inserts user entry
func (c *Client) UpsertUser(user services.User) error
// UpsertUser user updates or inserts user entry func (c *Client) UpsertUser(user services.User) error
{ data, err := services.GetUserMarshaler().MarshalUser(user) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("users"), &upsertUserRawReq{User: data}) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1302-L1305
go
train
// ChangePassword changes user password
func (c *Client) ChangePassword(req services.ChangePasswordReq) error
// ChangePassword changes user password func (c *Client) ChangePassword(req services.ChangePasswordReq) error
{ _, err := c.PutJSON(c.Endpoint("users", req.User, "web", "password"), req) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1308-L1316
go
train
// CheckPassword checks if the suplied web access password is valid.
func (c *Client) CheckPassword(user string, password []byte, otpToken string) error
// CheckPassword checks if the suplied web access password is valid. func (c *Client) CheckPassword(user string, password []byte, otpToken string) error
{ _, err := c.PostJSON( c.Endpoint("users", user, "web", "password", "check"), checkPasswordReq{ Password: string(password), OTPToken: otpToken, }) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1319-L1334
go
train
// GetU2FSignRequest generates request for user trying to authenticate with U2F token
func (c *Client) GetU2FSignRequest(user string, password []byte) (*u2f.SignRequest, error)
// GetU2FSignRequest generates request for user trying to authenticate with U2F token func (c *Client) GetU2FSignRequest(user string, password []byte) (*u2f.SignRequest, error)
{ out, err := c.PostJSON( c.Endpoint("u2f", "users", user, "sign"), signInReq{ Password: string(password), }, ) if err != nil { return nil, trace.Wrap(err) } var signRequest *u2f.SignRequest if err := json.Unmarshal(out.Bytes(), &signRequest); err != nil { return nil, err } return signRequest, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1338-L1349
go
train
// ExtendWebSession creates a new web session for a user based on another // valid web session
func (c *Client) ExtendWebSession(user string, prevSessionID string) (services.WebSession, error)
// ExtendWebSession creates a new web session for a user based on another // valid web session func (c *Client) ExtendWebSession(user string, prevSessionID string) (services.WebSession, error)
{ out, err := c.PostJSON( c.Endpoint("users", user, "web", "sessions"), createWebSessionReq{ PrevSessionID: prevSessionID, }, ) if err != nil { return nil, trace.Wrap(err) } return services.GetWebSessionMarshaler().UnmarshalWebSession(out.Bytes()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1365-L1374
go
train
// AuthenticateWebUser authenticates web user, creates and returns web session // in case if authentication is successful
func (c *Client) AuthenticateWebUser(req AuthenticateUserRequest) (services.WebSession, error)
// AuthenticateWebUser authenticates web user, creates and returns web session // in case if authentication is successful func (c *Client) AuthenticateWebUser(req AuthenticateUserRequest) (services.WebSession, error)
{ out, err := c.PostJSON( c.Endpoint("users", req.Username, "web", "authenticate"), req, ) if err != nil { return nil, trace.Wrap(err) } return services.GetWebSessionMarshaler().UnmarshalWebSession(out.Bytes()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1378-L1391
go
train
// AuthenticateSSHUser authenticates SSH console user, creates and returns a pair of signed TLS and SSH // short lived certificates as a result
func (c *Client) AuthenticateSSHUser(req AuthenticateSSHRequest) (*SSHLoginResponse, error)
// AuthenticateSSHUser authenticates SSH console user, creates and returns a pair of signed TLS and SSH // short lived certificates as a result func (c *Client) AuthenticateSSHUser(req AuthenticateSSHRequest) (*SSHLoginResponse, error)
{ out, err := c.PostJSON( c.Endpoint("users", req.Username, "ssh", "authenticate"), req, ) if err != nil { return nil, trace.Wrap(err) } var re SSHLoginResponse if err := json.Unmarshal(out.Bytes(), &re); err != nil { return nil, trace.Wrap(err) } return &re, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1395-L1402
go
train
// GetWebSessionInfo checks if a web sesion is valid, returns session id in case if // it is valid, or error otherwise.
func (c *Client) GetWebSessionInfo(user string, sid string) (services.WebSession, error)
// GetWebSessionInfo checks if a web sesion is valid, returns session id in case if // it is valid, or error otherwise. func (c *Client) GetWebSessionInfo(user string, sid string) (services.WebSession, error)
{ out, err := c.Get( c.Endpoint("users", user, "web", "sessions", sid), url.Values{}) if err != nil { return nil, trace.Wrap(err) } return services.GetWebSessionMarshaler().UnmarshalWebSession(out.Bytes()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1405-L1408
go
train
// DeleteWebSession deletes a web session for this user by id
func (c *Client) DeleteWebSession(user string, sid string) error
// DeleteWebSession deletes a web session for this user by id func (c *Client) DeleteWebSession(user string, sid string) error
{ _, err := c.Delete(c.Endpoint("users", user, "web", "sessions", sid)) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1411-L1424
go
train
// GetUser returns a list of usernames registered in the system
func (c *Client) GetUser(name string) (services.User, error)
// GetUser returns a list of usernames registered in the system func (c *Client) GetUser(name string) (services.User, error)
{ if name == "" { return nil, trace.BadParameter("missing username") } out, err := c.Get(c.Endpoint("users", name), url.Values{}) if err != nil { return nil, trace.Wrap(err) } user, err := services.GetUserMarshaler().UnmarshalUser(out.Bytes(), services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } return user, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1427-L1445
go
train
// GetUsers returns a list of usernames registered in the system
func (c *Client) GetUsers() ([]services.User, error)
// GetUsers returns a list of usernames registered in the system func (c *Client) GetUsers() ([]services.User, error)
{ out, err := c.Get(c.Endpoint("users"), url.Values{}) if err != nil { return nil, trace.Wrap(err) } var items []json.RawMessage if err := json.Unmarshal(out.Bytes(), &items); err != nil { return nil, trace.Wrap(err) } users := make([]services.User, len(items)) for i, userBytes := range items { user, err := services.GetUserMarshaler().UnmarshalUser(userBytes, services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } users[i] = user } return users, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1448-L1451
go
train
// DeleteUser deletes a user by username
func (c *Client) DeleteUser(user string) error
// DeleteUser deletes a user by username func (c *Client) DeleteUser(user string) error
{ _, err := c.Delete(c.Endpoint("users", user)) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1456-L1466
go
train
// GenerateKeyPair generates SSH private/public key pair optionally protected // by password. If the pass parameter is an empty string, the key pair // is not password-protected.
func (c *Client) GenerateKeyPair(pass string) ([]byte, []byte, error)
// GenerateKeyPair generates SSH private/public key pair optionally protected // by password. If the pass parameter is an empty string, the key pair // is not password-protected. func (c *Client) GenerateKeyPair(pass string) ([]byte, []byte, error)
{ out, err := c.PostJSON(c.Endpoint("keypair"), generateKeyPairReq{Password: pass}) if err != nil { return nil, nil, trace.Wrap(err) } var kp *generateKeyPairResponse if err := json.Unmarshal(out.Bytes(), &kp); err != nil { return nil, nil, err } return kp.PrivKey, []byte(kp.PubKey), err }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1471-L1494
go
train
// GenerateHostCert takes the public key in the Open SSH ``authorized_keys`` // plain text format, signs it using Host Certificate Authority private key and returns the // resulting certificate.
func (c *Client) GenerateHostCert( key []byte, hostID, nodeName string, principals []string, clusterName string, roles teleport.Roles, ttl time.Duration) ([]byte, error)
// GenerateHostCert takes the public key in the Open SSH ``authorized_keys`` // plain text format, signs it using Host Certificate Authority private key and returns the // resulting certificate. func (c *Client) GenerateHostCert( key []byte, hostID, nodeName string, principals []string, clusterName string, roles teleport.Roles, ttl time.Duration) ([]byte, error)
{ out, err := c.PostJSON(c.Endpoint("ca", "host", "certs"), generateHostCertReq{ Key: key, HostID: hostID, NodeName: nodeName, Principals: principals, ClusterName: clusterName, Roles: roles, TTL: ttl, }) if err != nil { return nil, trace.Wrap(err) } var cert string if err := json.Unmarshal(out.Bytes(), &cert); err != nil { return nil, err } return []byte(cert), nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1498-L1514
go
train
// CreateSignupToken creates one time token for creating account for the user // For each token it creates username and otp generator
func (c *Client) CreateSignupToken(user services.UserV1, ttl time.Duration) (string, error)
// CreateSignupToken creates one time token for creating account for the user // For each token it creates username and otp generator func (c *Client) CreateSignupToken(user services.UserV1, ttl time.Duration) (string, error)
{ if err := user.Check(); err != nil { return "", trace.Wrap(err) } out, err := c.PostJSON(c.Endpoint("signuptokens"), createSignupTokenReq{ User: user, TTL: ttl, }) if err != nil { return "", trace.Wrap(err) } var token string if err := json.Unmarshal(out.Bytes(), &token); err != nil { return "", trace.Wrap(err) } return token, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1517-L1529
go
train
// GetSignupTokenData returns token data for a valid token
func (c *Client) GetSignupTokenData(token string) (user string, otpQRCode []byte, e error)
// GetSignupTokenData returns token data for a valid token func (c *Client) GetSignupTokenData(token string) (user string, otpQRCode []byte, e error)
{ out, err := c.Get(c.Endpoint("signuptokens", token), url.Values{}) if err != nil { return "", nil, err } var tokenData getSignupTokenDataResponse if err := json.Unmarshal(out.Bytes(), &tokenData); err != nil { return "", nil, err } return tokenData.User, tokenData.QRImg, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1534-L1550
go
train
// GenerateUserCert takes the public key in the OpenSSH `authorized_keys` plain // text format, signs it using User Certificate Authority signing key and // returns the resulting certificate.
func (c *Client) GenerateUserCert(key []byte, user string, ttl time.Duration, compatibility string) ([]byte, error)
// GenerateUserCert takes the public key in the OpenSSH `authorized_keys` plain // text format, signs it using User Certificate Authority signing key and // returns the resulting certificate. func (c *Client) GenerateUserCert(key []byte, user string, ttl time.Duration, compatibility string) ([]byte, error)
{ out, err := c.PostJSON(c.Endpoint("ca", "user", "certs"), generateUserCertReq{ Key: key, User: user, TTL: ttl, Compatibility: compatibility, }) if err != nil { return nil, trace.Wrap(err) } var cert string if err := json.Unmarshal(out.Bytes(), &cert); err != nil { return nil, trace.Wrap(err) } return []byte(cert), nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1553-L1563
go
train
// GetSignupU2FRegisterRequest generates sign request for user trying to sign up with invite tokenx
func (c *Client) GetSignupU2FRegisterRequest(token string) (u2fRegisterRequest *u2f.RegisterRequest, e error)
// GetSignupU2FRegisterRequest generates sign request for user trying to sign up with invite tokenx func (c *Client) GetSignupU2FRegisterRequest(token string) (u2fRegisterRequest *u2f.RegisterRequest, e error)
{ out, err := c.Get(c.Endpoint("u2f", "signuptokens", token), url.Values{}) if err != nil { return nil, err } var u2fRegReq u2f.RegisterRequest if err := json.Unmarshal(out.Bytes(), &u2fRegReq); err != nil { return nil, err } return &u2fRegReq, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1568-L1578
go
train
// CreateUserWithOTP creates account with provided token and password. // Account username and OTP key are taken from token data. // Deletes token after account creation.
func (c *Client) CreateUserWithOTP(token, password, otpToken string) (services.WebSession, error)
// CreateUserWithOTP creates account with provided token and password. // Account username and OTP key are taken from token data. // Deletes token after account creation. func (c *Client) CreateUserWithOTP(token, password, otpToken string) (services.WebSession, error)
{ out, err := c.PostJSON(c.Endpoint("signuptokens", "users"), createUserWithTokenReq{ Token: token, Password: password, OTPToken: otpToken, }) if err != nil { return nil, trace.Wrap(err) } return services.GetWebSessionMarshaler().UnmarshalWebSession(out.Bytes()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1594-L1604
go
train
// CreateUserWithU2FToken creates user account with provided token and U2F sign response
func (c *Client) CreateUserWithU2FToken(token string, password string, u2fRegisterResponse u2f.RegisterResponse) (services.WebSession, error)
// CreateUserWithU2FToken creates user account with provided token and U2F sign response func (c *Client) CreateUserWithU2FToken(token string, password string, u2fRegisterResponse u2f.RegisterResponse) (services.WebSession, error)
{ out, err := c.PostJSON(c.Endpoint("u2f", "users"), createUserWithU2FTokenReq{ Token: token, Password: password, U2FRegisterResponse: u2fRegisterResponse, }) if err != nil { return nil, trace.Wrap(err) } return services.GetWebSessionMarshaler().UnmarshalWebSession(out.Bytes()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1607-L1619
go
train
// UpsertOIDCConnector updates or creates OIDC connector
func (c *Client) UpsertOIDCConnector(connector services.OIDCConnector) error
// UpsertOIDCConnector updates or creates OIDC connector func (c *Client) UpsertOIDCConnector(connector services.OIDCConnector) error
{ data, err := services.GetOIDCConnectorMarshaler().MarshalOIDCConnector(connector) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("oidc", "connectors"), &upsertOIDCConnectorRawReq{ Connector: data, }) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1622-L1632
go
train
// GetOIDCConnector returns OIDC connector information by id
func (c *Client) GetOIDCConnector(id string, withSecrets bool) (services.OIDCConnector, error)
// GetOIDCConnector returns OIDC connector information by id func (c *Client) GetOIDCConnector(id string, withSecrets bool) (services.OIDCConnector, error)
{ if id == "" { return nil, trace.BadParameter("missing connector id") } out, err := c.Get(c.Endpoint("oidc", "connectors", id), url.Values{"with_secrets": []string{fmt.Sprintf("%t", withSecrets)}}) if err != nil { return nil, err } return services.GetOIDCConnectorMarshaler().UnmarshalOIDCConnector(out.Bytes(), services.SkipValidation()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1635-L1654
go
train
// GetOIDCConnector gets OIDC connectors list
func (c *Client) GetOIDCConnectors(withSecrets bool) ([]services.OIDCConnector, error)
// GetOIDCConnector gets OIDC connectors list func (c *Client) GetOIDCConnectors(withSecrets bool) ([]services.OIDCConnector, error)
{ out, err := c.Get(c.Endpoint("oidc", "connectors"), url.Values{"with_secrets": []string{fmt.Sprintf("%t", withSecrets)}}) if err != nil { return nil, err } var items []json.RawMessage if err := json.Unmarshal(out.Bytes(), &items); err != nil { return nil, trace.Wrap(err) } connectors := make([]services.OIDCConnector, len(items)) for i, raw := range items { connector, err := services.GetOIDCConnectorMarshaler().UnmarshalOIDCConnector(raw, services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } connectors[i] = connector } return connectors, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1666-L1678
go
train
// CreateOIDCAuthRequest creates OIDCAuthRequest
func (c *Client) CreateOIDCAuthRequest(req services.OIDCAuthRequest) (*services.OIDCAuthRequest, error)
// CreateOIDCAuthRequest creates OIDCAuthRequest func (c *Client) CreateOIDCAuthRequest(req services.OIDCAuthRequest) (*services.OIDCAuthRequest, error)
{ out, err := c.PostJSON(c.Endpoint("oidc", "requests", "create"), createOIDCAuthRequestReq{ Req: req, }) if err != nil { return nil, trace.Wrap(err) } var response *services.OIDCAuthRequest if err := json.Unmarshal(out.Bytes(), &response); err != nil { return nil, trace.Wrap(err) } return response, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1718-L1730
go
train
// CreateOIDCConnector creates SAML connector
func (c *Client) CreateSAMLConnector(connector services.SAMLConnector) error
// CreateOIDCConnector creates SAML connector func (c *Client) CreateSAMLConnector(connector services.SAMLConnector) error
{ data, err := services.GetSAMLConnectorMarshaler().MarshalSAMLConnector(connector) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("saml", "connectors"), &createSAMLConnectorRawReq{ Connector: data, }) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1733-L1745
go
train
// UpsertSAMLConnector updates or creates OIDC connector
func (c *Client) UpsertSAMLConnector(connector services.SAMLConnector) error
// UpsertSAMLConnector updates or creates OIDC connector func (c *Client) UpsertSAMLConnector(connector services.SAMLConnector) error
{ data, err := services.GetSAMLConnectorMarshaler().MarshalSAMLConnector(connector) if err != nil { return trace.Wrap(err) } _, err = c.PutJSON(c.Endpoint("saml", "connectors"), &upsertSAMLConnectorRawReq{ Connector: data, }) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1748-L1758
go
train
// GetOIDCConnector returns SAML connector information by id
func (c *Client) GetSAMLConnector(id string, withSecrets bool) (services.SAMLConnector, error)
// GetOIDCConnector returns SAML connector information by id func (c *Client) GetSAMLConnector(id string, withSecrets bool) (services.SAMLConnector, error)
{ if id == "" { return nil, trace.BadParameter("missing connector id") } out, err := c.Get(c.Endpoint("saml", "connectors", id), url.Values{"with_secrets": []string{fmt.Sprintf("%t", withSecrets)}}) if err != nil { return nil, trace.Wrap(err) } return services.GetSAMLConnectorMarshaler().UnmarshalSAMLConnector(out.Bytes(), services.SkipValidation()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1761-L1780
go
train
// GetSAMLConnectors gets SAML connectors list
func (c *Client) GetSAMLConnectors(withSecrets bool) ([]services.SAMLConnector, error)
// GetSAMLConnectors gets SAML connectors list func (c *Client) GetSAMLConnectors(withSecrets bool) ([]services.SAMLConnector, error)
{ out, err := c.Get(c.Endpoint("saml", "connectors"), url.Values{"with_secrets": []string{fmt.Sprintf("%t", withSecrets)}}) if err != nil { return nil, err } var items []json.RawMessage if err := json.Unmarshal(out.Bytes(), &items); err != nil { return nil, trace.Wrap(err) } connectors := make([]services.SAMLConnector, len(items)) for i, raw := range items { connector, err := services.GetSAMLConnectorMarshaler().UnmarshalSAMLConnector(raw, services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } connectors[i] = connector } return connectors, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1783-L1789
go
train
// DeleteSAMLConnector deletes SAML connector by ID
func (c *Client) DeleteSAMLConnector(connectorID string) error
// DeleteSAMLConnector deletes SAML connector by ID func (c *Client) DeleteSAMLConnector(connectorID string) error
{ if connectorID == "" { return trace.BadParameter("missing connector id") } _, err := c.Delete(c.Endpoint("saml", "connectors", connectorID)) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1792-L1804
go
train
// CreateSAMLAuthRequest creates SAML AuthnRequest
func (c *Client) CreateSAMLAuthRequest(req services.SAMLAuthRequest) (*services.SAMLAuthRequest, error)
// CreateSAMLAuthRequest creates SAML AuthnRequest func (c *Client) CreateSAMLAuthRequest(req services.SAMLAuthRequest) (*services.SAMLAuthRequest, error)
{ out, err := c.PostJSON(c.Endpoint("saml", "requests", "create"), createSAMLAuthRequestReq{ Req: req, }) if err != nil { return nil, trace.Wrap(err) } var response *services.SAMLAuthRequest if err := json.Unmarshal(out.Bytes(), &response); err != nil { return nil, trace.Wrap(err) } return response, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1807-L1841
go
train
// ValidateSAMLResponse validates response returned by SAML identity provider
func (c *Client) ValidateSAMLResponse(re string) (*SAMLAuthResponse, error)
// ValidateSAMLResponse validates response returned by SAML identity provider func (c *Client) ValidateSAMLResponse(re string) (*SAMLAuthResponse, error)
{ out, err := c.PostJSON(c.Endpoint("saml", "requests", "validate"), validateSAMLResponseReq{ Response: re, }) if err != nil { return nil, trace.Wrap(err) } var rawResponse *samlAuthRawResponse if err := json.Unmarshal(out.Bytes(), &rawResponse); err != nil { return nil, trace.Wrap(err) } response := SAMLAuthResponse{ Username: rawResponse.Username, Identity: rawResponse.Identity, Cert: rawResponse.Cert, Req: rawResponse.Req, TLSCert: rawResponse.TLSCert, } if len(rawResponse.Session) != 0 { session, err := services.GetWebSessionMarshaler().UnmarshalWebSession(rawResponse.Session) if err != nil { return nil, trace.Wrap(err) } response.Session = session } response.HostSigners = make([]services.CertAuthority, len(rawResponse.HostSigners)) for i, raw := range rawResponse.HostSigners { ca, err := services.GetCertAuthorityMarshaler().UnmarshalCertAuthority(raw) if err != nil { return nil, trace.Wrap(err) } response.HostSigners[i] = ca } return &response, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1844-L1856
go
train
// CreateGithubConnector creates a new Github connector
func (c *Client) CreateGithubConnector(connector services.GithubConnector) error
// CreateGithubConnector creates a new Github connector func (c *Client) CreateGithubConnector(connector services.GithubConnector) error
{ bytes, err := services.GetGithubConnectorMarshaler().Marshal(connector) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("github", "connectors"), &createGithubConnectorRawReq{ Connector: bytes, }) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1859-L1871
go
train
// UpsertGithubConnector creates or updates a Github connector
func (c *Client) UpsertGithubConnector(connector services.GithubConnector) error
// UpsertGithubConnector creates or updates a Github connector func (c *Client) UpsertGithubConnector(connector services.GithubConnector) error
{ bytes, err := services.GetGithubConnectorMarshaler().Marshal(connector) if err != nil { return trace.Wrap(err) } _, err = c.PutJSON(c.Endpoint("github", "connectors"), &upsertGithubConnectorRawReq{ Connector: bytes, }) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1874-L1894
go
train
// GetGithubConnectors returns all configured Github connectors
func (c *Client) GetGithubConnectors(withSecrets bool) ([]services.GithubConnector, error)
// GetGithubConnectors returns all configured Github connectors func (c *Client) GetGithubConnectors(withSecrets bool) ([]services.GithubConnector, error)
{ out, err := c.Get(c.Endpoint("github", "connectors"), url.Values{ "with_secrets": []string{strconv.FormatBool(withSecrets)}, }) if err != nil { return nil, trace.Wrap(err) } var items []json.RawMessage if err := json.Unmarshal(out.Bytes(), &items); err != nil { return nil, trace.Wrap(err) } connectors := make([]services.GithubConnector, len(items)) for i, raw := range items { connector, err := services.GetGithubConnectorMarshaler().Unmarshal(raw) if err != nil { return nil, trace.Wrap(err) } connectors[i] = connector } return connectors, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1897-L1905
go
train
// GetGithubConnector returns the specified Github connector
func (c *Client) GetGithubConnector(id string, withSecrets bool) (services.GithubConnector, error)
// GetGithubConnector returns the specified Github connector func (c *Client) GetGithubConnector(id string, withSecrets bool) (services.GithubConnector, error)
{ out, err := c.Get(c.Endpoint("github", "connectors", id), url.Values{ "with_secrets": []string{strconv.FormatBool(withSecrets)}, }) if err != nil { return nil, trace.Wrap(err) } return services.GetGithubConnectorMarshaler().Unmarshal(out.Bytes()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1908-L1914
go
train
// DeleteGithubConnector deletes the specified Github connector
func (c *Client) DeleteGithubConnector(id string) error
// DeleteGithubConnector deletes the specified Github connector func (c *Client) DeleteGithubConnector(id string) error
{ _, err := c.Delete(c.Endpoint("github", "connectors", id)) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1917-L1928
go
train
// CreateGithubAuthRequest creates a new request for Github OAuth2 flow
func (c *Client) CreateGithubAuthRequest(req services.GithubAuthRequest) (*services.GithubAuthRequest, error)
// CreateGithubAuthRequest creates a new request for Github OAuth2 flow func (c *Client) CreateGithubAuthRequest(req services.GithubAuthRequest) (*services.GithubAuthRequest, error)
{ out, err := c.PostJSON(c.Endpoint("github", "requests", "create"), createGithubAuthRequestReq{Req: req}) if err != nil { return nil, trace.Wrap(err) } var response services.GithubAuthRequest if err := json.Unmarshal(out.Bytes(), &response); err != nil { return nil, trace.Wrap(err) } return &response, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1931-L1965
go
train
// ValidateGithubAuthCallback validates Github auth callback returned from redirect
func (c *Client) ValidateGithubAuthCallback(q url.Values) (*GithubAuthResponse, error)
// ValidateGithubAuthCallback validates Github auth callback returned from redirect func (c *Client) ValidateGithubAuthCallback(q url.Values) (*GithubAuthResponse, error)
{ out, err := c.PostJSON(c.Endpoint("github", "requests", "validate"), validateGithubAuthCallbackReq{Query: q}) if err != nil { return nil, trace.Wrap(err) } var rawResponse githubAuthRawResponse if err := json.Unmarshal(out.Bytes(), &rawResponse); err != nil { return nil, trace.Wrap(err) } response := GithubAuthResponse{ Username: rawResponse.Username, Identity: rawResponse.Identity, Cert: rawResponse.Cert, Req: rawResponse.Req, TLSCert: rawResponse.TLSCert, } if len(rawResponse.Session) != 0 { session, err := services.GetWebSessionMarshaler().UnmarshalWebSession( rawResponse.Session) if err != nil { return nil, trace.Wrap(err) } response.Session = session } response.HostSigners = make([]services.CertAuthority, len(rawResponse.HostSigners)) for i, raw := range rawResponse.HostSigners { ca, err := services.GetCertAuthorityMarshaler().UnmarshalCertAuthority(raw) if err != nil { return nil, trace.Wrap(err) } response.HostSigners[i] = ca } return &response, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1968-L1979
go
train
// EmitAuditEvent sends an auditable event to the auth server (part of evets.IAuditLog interface)
func (c *Client) EmitAuditEvent(event events.Event, fields events.EventFields) error
// EmitAuditEvent sends an auditable event to the auth server (part of evets.IAuditLog interface) func (c *Client) EmitAuditEvent(event events.Event, fields events.EventFields) error
{ _, err := c.PostJSON(c.Endpoint("events"), &auditEventReq{ Event: event, Fields: fields, // Send "type" as well for backwards compatibility. Type: event.Name, }) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L1986-L2006
go
train
// PostSessionSlice allows clients to submit session stream chunks to the audit log // (part of evets.IAuditLog interface) // // The data is POSTed to HTTP server as a simple binary body (no encodings of any // kind are needed)
func (c *Client) PostSessionSlice(slice events.SessionSlice) error
// PostSessionSlice allows clients to submit session stream chunks to the audit log // (part of evets.IAuditLog interface) // // The data is POSTed to HTTP server as a simple binary body (no encodings of any // kind are needed) func (c *Client) PostSessionSlice(slice events.SessionSlice) error
{ data, err := slice.Marshal() if err != nil { return trace.Wrap(err) } r, err := http.NewRequest("POST", c.Endpoint("namespaces", slice.Namespace, "sessions", string(slice.SessionID), "slice"), bytes.NewReader(data)) if err != nil { return trace.Wrap(err) } r.Header.Set("Content-Type", "application/grpc") c.Client.SetAuthHeader(r.Header) re, err := c.Client.HTTPClient().Do(r) if err != nil { return trace.Wrap(err) } // we **must** consume response by reading all of its body, otherwise the http // client will allocate a new connection for subsequent requests defer re.Body.Close() responseBytes, _ := ioutil.ReadAll(re.Body) return trace.ReadError(re.StatusCode, responseBytes) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2011-L2024
go
train
// GetSessionChunk allows clients to receive a byte array (chunk) from a recorded // session stream, starting from 'offset', up to 'max' in length. The upper bound // of 'max' is set to events.MaxChunkBytes
func (c *Client) GetSessionChunk(namespace string, sid session.ID, offsetBytes, maxBytes int) ([]byte, error)
// GetSessionChunk allows clients to receive a byte array (chunk) from a recorded // session stream, starting from 'offset', up to 'max' in length. The upper bound // of 'max' is set to events.MaxChunkBytes func (c *Client) GetSessionChunk(namespace string, sid session.ID, offsetBytes, maxBytes int) ([]byte, error)
{ if namespace == "" { return nil, trace.BadParameter(MissingNamespaceError) } response, err := c.Get(c.Endpoint("namespaces", namespace, "sessions", string(sid), "stream"), url.Values{ "offset": []string{strconv.Itoa(offsetBytes)}, "bytes": []string{strconv.Itoa(maxBytes)}, }) if err != nil { log.Error(err) return nil, trace.Wrap(err) } return response.Bytes(), nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2027-L2042
go
train
// UploadSessionRecording uploads session recording to the audit server
func (c *Client) UploadSessionRecording(r events.SessionRecording) error
// UploadSessionRecording uploads session recording to the audit server func (c *Client) UploadSessionRecording(r events.SessionRecording) error
{ file := roundtrip.File{ Name: "recording", Filename: "recording", Reader: r.Recording, } values := url.Values{ "sid": []string{string(r.SessionID)}, "namespace": []string{r.Namespace}, } _, err := c.PostForm(c.Endpoint("namespaces", r.Namespace, "sessions", string(r.SessionID), "recording"), values, file) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2052-L2072
go
train
// Returns events that happen during a session sorted by time // (oldest first). // // afterN allows to filter by "newer than N" value where N is the cursor ID // of previously returned bunch (good for polling for latest) // // This function is usually used in conjunction with GetSessionReader to // replay recorded session streams.
func (c *Client) GetSessionEvents(namespace string, sid session.ID, afterN int, includePrintEvents bool) (retval []events.EventFields, err error)
// Returns events that happen during a session sorted by time // (oldest first). // // afterN allows to filter by "newer than N" value where N is the cursor ID // of previously returned bunch (good for polling for latest) // // This function is usually used in conjunction with GetSessionReader to // replay recorded session streams. func (c *Client) GetSessionEvents(namespace string, sid session.ID, afterN int, includePrintEvents bool) (retval []events.EventFields, err error)
{ if namespace == "" { return nil, trace.BadParameter(MissingNamespaceError) } query := make(url.Values) if afterN > 0 { query.Set("after", strconv.Itoa(afterN)) } if includePrintEvents { query.Set("print", fmt.Sprintf("%v", includePrintEvents)) } response, err := c.Get(c.Endpoint("namespaces", namespace, "sessions", string(sid), "events"), query) if err != nil { return nil, trace.Wrap(err) } retval = make([]events.EventFields, 0) if err := json.Unmarshal(response.Bytes(), &retval); err != nil { return nil, trace.Wrap(err) } return retval, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2075-L2092
go
train
// SearchEvents returns events that fit the criteria
func (c *Client) SearchEvents(from, to time.Time, query string, limit int) ([]events.EventFields, error)
// SearchEvents returns events that fit the criteria func (c *Client) SearchEvents(from, to time.Time, query string, limit int) ([]events.EventFields, error)
{ q, err := url.ParseQuery(query) if err != nil { return nil, trace.BadParameter("query") } q.Set("from", from.Format(time.RFC3339)) q.Set("to", to.Format(time.RFC3339)) q.Set("limit", fmt.Sprintf("%v", limit)) response, err := c.Get(c.Endpoint("events"), q) if err != nil { return nil, trace.Wrap(err) } retval := make([]events.EventFields, 0) if err := json.Unmarshal(response.Bytes(), &retval); err != nil { return nil, trace.Wrap(err) } return retval, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2116-L2126
go
train
// GetNamespaces returns a list of namespaces
func (c *Client) GetNamespaces() ([]services.Namespace, error)
// GetNamespaces returns a list of namespaces func (c *Client) GetNamespaces() ([]services.Namespace, error)
{ out, err := c.Get(c.Endpoint("namespaces"), url.Values{}) if err != nil { return nil, trace.Wrap(err) } var re []services.Namespace if err := utils.FastUnmarshal(out.Bytes(), &re); err != nil { return nil, trace.Wrap(err) } return re, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2129-L2138
go
train
// GetNamespace returns namespace by name
func (c *Client) GetNamespace(name string) (*services.Namespace, error)
// GetNamespace returns namespace by name func (c *Client) GetNamespace(name string) (*services.Namespace, error)
{ if name == "" { return nil, trace.BadParameter("missing namespace name") } out, err := c.Get(c.Endpoint("namespaces", name), url.Values{}) if err != nil { return nil, trace.Wrap(err) } return services.UnmarshalNamespace(out.Bytes(), services.SkipValidation()) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2141-L2144
go
train
// UpsertNamespace upserts namespace
func (c *Client) UpsertNamespace(ns services.Namespace) error
// UpsertNamespace upserts namespace func (c *Client) UpsertNamespace(ns services.Namespace) error
{ _, err := c.PostJSON(c.Endpoint("namespaces"), upsertNamespaceReq{Namespace: ns}) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2153-L2171
go
train
// GetRoles returns a list of roles
func (c *Client) GetRoles() ([]services.Role, error)
// GetRoles returns a list of roles func (c *Client) GetRoles() ([]services.Role, error)
{ out, err := c.Get(c.Endpoint("roles"), url.Values{}) if err != nil { return nil, trace.Wrap(err) } var items []json.RawMessage if err := json.Unmarshal(out.Bytes(), &items); err != nil { return nil, trace.Wrap(err) } roles := make([]services.Role, len(items)) for i, roleBytes := range items { role, err := services.GetRoleMarshaler().UnmarshalRole(roleBytes, services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } roles[i] = role } return roles, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2179-L2186
go
train
// UpsertRole creates or updates role
func (c *Client) UpsertRole(role services.Role) error
// UpsertRole creates or updates role func (c *Client) UpsertRole(role services.Role) error
{ data, err := services.GetRoleMarshaler().MarshalRole(role) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("roles"), &upsertRoleRawReq{Role: data}) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2189-L2202
go
train
// GetRole returns role by name
func (c *Client) GetRole(name string) (services.Role, error)
// GetRole returns role by name func (c *Client) GetRole(name string) (services.Role, error)
{ if name == "" { return nil, trace.BadParameter("missing name") } out, err := c.Get(c.Endpoint("roles", name), url.Values{}) if err != nil { return nil, trace.Wrap(err) } role, err := services.GetRoleMarshaler().UnmarshalRole(out.Bytes(), services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } return role, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2211-L2223
go
train
// GetClusterConfig returns cluster level configuration information.
func (c *Client) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error)
// GetClusterConfig returns cluster level configuration information. func (c *Client) GetClusterConfig(opts ...services.MarshalOption) (services.ClusterConfig, error)
{ out, err := c.Get(c.Endpoint("configuration"), url.Values{}) if err != nil { return nil, trace.Wrap(err) } cc, err := services.GetClusterConfigMarshaler().Unmarshal(out.Bytes(), services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } return cc, err }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2226-L2238
go
train
// SetClusterConfig sets cluster level configuration information.
func (c *Client) SetClusterConfig(cc services.ClusterConfig) error
// SetClusterConfig sets cluster level configuration information. func (c *Client) SetClusterConfig(cc services.ClusterConfig) error
{ data, err := services.GetClusterConfigMarshaler().Marshal(cc) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("configuration"), &setClusterConfigReq{ClusterConfig: data}) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2241-L2253
go
train
// GetClusterName returns a cluster name
func (c *Client) GetClusterName(opts ...services.MarshalOption) (services.ClusterName, error)
// GetClusterName returns a cluster name func (c *Client) GetClusterName(opts ...services.MarshalOption) (services.ClusterName, error)
{ out, err := c.Get(c.Endpoint("configuration", "name"), url.Values{}) if err != nil { return nil, trace.Wrap(err) } cn, err := services.GetClusterNameMarshaler().Unmarshal(out.Bytes(), services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } return cn, err }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2257-L2269
go
train
// SetClusterName sets cluster name once, will // return Already Exists error if the name is already set
func (c *Client) SetClusterName(cn services.ClusterName) error
// SetClusterName sets cluster name once, will // return Already Exists error if the name is already set func (c *Client) SetClusterName(cn services.ClusterName) error
{ data, err := services.GetClusterNameMarshaler().Marshal(cn) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("configuration", "name"), &setClusterNameReq{ClusterName: data}) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2277-L2280
go
train
// DeleteStaticTokens deletes static tokens
func (c *Client) DeleteStaticTokens() error
// DeleteStaticTokens deletes static tokens func (c *Client) DeleteStaticTokens() error
{ _, err := c.Delete(c.Endpoint("configuration", "static_tokens")) return trace.Wrap(err) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2283-L2295
go
train
// GetStaticTokens returns a list of static register tokens
func (c *Client) GetStaticTokens() (services.StaticTokens, error)
// GetStaticTokens returns a list of static register tokens func (c *Client) GetStaticTokens() (services.StaticTokens, error)
{ out, err := c.Get(c.Endpoint("configuration", "static_tokens"), url.Values{}) if err != nil { return nil, trace.Wrap(err) } st, err := services.GetStaticTokensMarshaler().Unmarshal(out.Bytes(), services.SkipValidation()) if err != nil { return nil, trace.Wrap(err) } return st, err }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/auth/clt.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/clt.go#L2298-L2310
go
train
// SetStaticTokens sets a list of static register tokens
func (c *Client) SetStaticTokens(st services.StaticTokens) error
// SetStaticTokens sets a list of static register tokens func (c *Client) SetStaticTokens(st services.StaticTokens) error
{ data, err := services.GetStaticTokensMarshaler().Marshal(st) if err != nil { return trace.Wrap(err) } _, err = c.PostJSON(c.Endpoint("configuration", "static_tokens"), &setStaticTokensReq{StaticTokens: data}) if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/forward/subsystem.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/forward/subsystem.go#L45-L58
go
train
// parseRemoteSubsystem returns *remoteSubsystem which can be used to run a subsystem on a remote node.
func parseRemoteSubsystem(ctx context.Context, subsytemName string, serverContext *srv.ServerContext) *remoteSubsystem
// parseRemoteSubsystem returns *remoteSubsystem which can be used to run a subsystem on a remote node. func parseRemoteSubsystem(ctx context.Context, subsytemName string, serverContext *srv.ServerContext) *remoteSubsystem
{ return &remoteSubsystem{ log: log.WithFields(log.Fields{ trace.Component: teleport.ComponentRemoteSubsystem, trace.ComponentFields: map[string]string{ "name": subsytemName, }, }), serverContext: serverContext, subsytemName: subsytemName, ctx: ctx, errorCh: make(chan error, 3), } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/forward/subsystem.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/forward/subsystem.go#L61-L108
go
train
// Start will begin execution of the remote subsytem on the passed in channel.
func (r *remoteSubsystem) Start(channel ssh.Channel) error
// Start will begin execution of the remote subsytem on the passed in channel. func (r *remoteSubsystem) Start(channel ssh.Channel) error
{ session := r.serverContext.RemoteSession stdout, err := session.StdoutPipe() if err != nil { return trace.Wrap(err) } stderr, err := session.StderrPipe() if err != nil { return trace.Wrap(err) } stdin, err := session.StdinPipe() if err != nil { return trace.Wrap(err) } // request the subsystem from the remote node. if successful, the user can // interact with the remote subsystem with stdin, stdout, and stderr. err = session.RequestSubsystem(r.subsytemName) if err != nil { // emit an event to the audit log with the reason remote execution failed r.emitAuditEvent(err) return trace.Wrap(err) } // copy back and forth between stdin, stdout, and stderr and the SSH channel. go func() { defer session.Close() _, err := io.Copy(channel, stdout) r.errorCh <- err }() go func() { defer session.Close() _, err := io.Copy(channel.Stderr(), stderr) r.errorCh <- err }() go func() { defer session.Close() _, err := io.Copy(stdin, channel) r.errorCh <- err }() return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/forward/subsystem.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/forward/subsystem.go#L111-L130
go
train
// Wait until the remote subsystem has finished execution and then return the last error.
func (r *remoteSubsystem) Wait() error
// Wait until the remote subsystem has finished execution and then return the last error. func (r *remoteSubsystem) Wait() error
{ var lastErr error for i := 0; i < 3; i++ { select { case err := <-r.errorCh: if err != nil && err != io.EOF { r.log.Warnf("Connection problem: %v %T", trace.DebugReport(err), err) lastErr = err } case <-r.ctx.Done(): lastErr = trace.ConnectionProblem(nil, "context is closing") } } // emit an event to the audit log with the result of execution r.emitAuditEvent(lastErr) return lastErr }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L74-L84
go
train
// NewWebSession returns new instance of the web session based on the V2 spec
func NewWebSession(name string, spec WebSessionSpecV2) WebSession
// NewWebSession returns new instance of the web session based on the V2 spec func NewWebSession(name string, spec WebSessionSpecV2) WebSession
{ return &WebSessionV2{ Kind: KindWebSession, Version: V2, Metadata: Metadata{ Name: name, Namespace: defaults.Namespace, }, Spec: spec, } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L123-L127
go
train
// WithoutSecrets returns copy of the object but without secrets
func (ws *WebSessionV2) WithoutSecrets() WebSession
// WithoutSecrets returns copy of the object but without secrets func (ws *WebSessionV2) WithoutSecrets() WebSession
{ v2 := ws.V2() v2.Spec.Priv = nil return v2 }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L130-L137
go
train
// CheckAndSetDefaults checks and set default values for any missing fields.
func (ws *WebSessionV2) CheckAndSetDefaults() error
// CheckAndSetDefaults checks and set default values for any missing fields. func (ws *WebSessionV2) CheckAndSetDefaults() error
{ err := ws.Metadata.CheckAndSetDefaults() if err != nil { return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L155-L160
go
train
// GetShortName returns visible short name used in logging
func (ws *WebSessionV2) GetShortName() string
// GetShortName returns visible short name used in logging func (ws *WebSessionV2) GetShortName() string
{ if len(ws.Metadata.Name) < 4 { return "<undefined>" } return ws.Metadata.Name[:4] }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L194-L196
go
train
// SetBearerTokenExpiryTime sets bearer token expiry time
func (ws *WebSessionV2) SetBearerTokenExpiryTime(tm time.Time)
// SetBearerTokenExpiryTime sets bearer token expiry time func (ws *WebSessionV2) SetBearerTokenExpiryTime(tm time.Time)
{ ws.Spec.BearerTokenExpires = tm }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L199-L201
go
train
// SetExpiryTime sets session expiry time
func (ws *WebSessionV2) SetExpiryTime(tm time.Time)
// SetExpiryTime sets session expiry time func (ws *WebSessionV2) SetExpiryTime(tm time.Time)
{ ws.Spec.Expires = tm }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L219-L227
go
train
// V1 returns V1 version of the object
func (ws *WebSessionV2) V1() *WebSessionV1
// V1 returns V1 version of the object func (ws *WebSessionV2) V1() *WebSessionV1
{ return &WebSessionV1{ ID: ws.Metadata.Name, Priv: ws.Spec.Priv, Pub: ws.Spec.Pub, BearerToken: ws.Spec.BearerToken, Expires: ws.Spec.Expires, } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L269-L285
go
train
// V2 returns V2 version of the resource
func (s *WebSessionV1) V2() *WebSessionV2
// V2 returns V2 version of the resource func (s *WebSessionV1) V2() *WebSessionV2
{ return &WebSessionV2{ Kind: KindWebSession, Version: V2, Metadata: Metadata{ Name: s.ID, Namespace: defaults.Namespace, }, Spec: WebSessionSpecV2{ Pub: s.Pub, Priv: s.Priv, BearerToken: s.BearerToken, Expires: s.Expires, BearerTokenExpires: s.Expires, }, } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L395-L397
go
train
// GetWebSessionSchemaWithExtensions returns JSON Schema for web session with user-supplied extensions
func GetWebSessionSchemaWithExtensions(extension string) string
// GetWebSessionSchemaWithExtensions returns JSON Schema for web session with user-supplied extensions func GetWebSessionSchemaWithExtensions(extension string) string
{ return fmt.Sprintf(V2SchemaTemplate, MetadataSchema, fmt.Sprintf(WebSessionSpecV2Schema, extension), DefaultDefinitions) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L414-L445
go
train
// UnmarshalWebSession unmarshals web session from on-disk byte format
func (*TeleportWebSessionMarshaler) UnmarshalWebSession(bytes []byte) (WebSession, error)
// UnmarshalWebSession unmarshals web session from on-disk byte format func (*TeleportWebSessionMarshaler) UnmarshalWebSession(bytes []byte) (WebSession, error)
{ var h ResourceHeader err := json.Unmarshal(bytes, &h) if err != nil { return nil, trace.Wrap(err) } switch h.Version { case "": var ws WebSessionV1 err := json.Unmarshal(bytes, &ws) if err != nil { return nil, trace.Wrap(err) } utils.UTC(&ws.Expires) return ws.V2(), nil case V2: var ws WebSessionV2 if err := utils.UnmarshalWithSchema(GetWebSessionSchema(), &ws, bytes); err != nil { return nil, trace.BadParameter(err.Error()) } utils.UTC(&ws.Spec.BearerTokenExpires) utils.UTC(&ws.Spec.Expires) if err := ws.CheckAndSetDefaults(); err != nil { return nil, trace.Wrap(err) } return &ws, nil } return nil, trace.BadParameter("web session resource version %v is not supported", h.Version) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/services/session.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/session.go#L448-L484
go
train
// MarshalWebSession marshals web session into on-disk representation
func (*TeleportWebSessionMarshaler) MarshalWebSession(ws WebSession, opts ...MarshalOption) ([]byte, error)
// MarshalWebSession marshals web session into on-disk representation func (*TeleportWebSessionMarshaler) MarshalWebSession(ws WebSession, opts ...MarshalOption) ([]byte, error)
{ cfg, err := collectOptions(opts) if err != nil { return nil, trace.Wrap(err) } type ws1 interface { V1() *WebSessionV1 } type ws2 interface { V2() *WebSessionV2 } version := cfg.GetVersion() switch version { case V1: v, ok := ws.(ws1) if !ok { return nil, trace.BadParameter("don't know how to marshal session %v", V1) } return json.Marshal(v.V1()) case V2: v, ok := ws.(ws2) if !ok { return nil, trace.BadParameter("don't know how to marshal session %v", V2) } v2 := v.V2() if !cfg.PreserveResourceID { // avoid modifying the original object // to prevent unexpected data races copy := *v2 copy.Metadata.ID = 0 v2 = &copy } return utils.FastMarshal(v2) default: return nil, trace.BadParameter("version %v is not supported", version) } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L115-L145
go
train
// emitSessionJoinEvent emits a session join event to both the Audit Log as // well as sending a "x-teleport-event" global request on the SSH connection.
func (s *SessionRegistry) emitSessionJoinEvent(ctx *ServerContext)
// emitSessionJoinEvent emits a session join event to both the Audit Log as // well as sending a "x-teleport-event" global request on the SSH connection. func (s *SessionRegistry) emitSessionJoinEvent(ctx *ServerContext)
{ sessionJoinEvent := events.EventFields{ events.EventType: events.SessionJoinEvent, events.SessionEventID: string(ctx.session.id), events.EventNamespace: s.srv.GetNamespace(), events.EventLogin: ctx.Identity.Login, events.EventUser: ctx.Identity.TeleportUser, events.LocalAddr: ctx.Conn.LocalAddr().String(), events.RemoteAddr: ctx.Conn.RemoteAddr().String(), events.SessionServerID: ctx.srv.ID(), } // Emit session join event to Audit Log. ctx.session.recorder.GetAuditLog().EmitAuditEvent(events.SessionJoin, sessionJoinEvent) // Notify all members of the party that a new member has joined over the // "x-teleport-event" channel. for _, p := range s.getParties(ctx.session) { eventPayload, err := json.Marshal(sessionJoinEvent) if err != nil { s.log.Warnf("Unable to marshal %v for %v: %v.", events.SessionJoinEvent, p.sconn.RemoteAddr(), err) continue } _, _, err = p.sconn.SendRequest(teleport.SessionEvent, false, eventPayload) if err != nil { s.log.Warnf("Unable to send %v to %v: %v.", events.SessionJoinEvent, p.sconn.RemoteAddr(), err) continue } s.log.Debugf("Sent %v to %v.", events.SessionJoinEvent, p.sconn.RemoteAddr()) } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L148-L185
go
train
// OpenSession either joins an existing session or starts a new session.
func (s *SessionRegistry) OpenSession(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error
// OpenSession either joins an existing session or starts a new session. func (s *SessionRegistry) OpenSession(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error
{ if ctx.session != nil { ctx.Infof("Joining existing session %v.", ctx.session.id) // Update the in-memory data structure that a party member has joined. _, err := ctx.session.join(ch, req, ctx) if err != nil { return trace.Wrap(err) } // Emit session join event to both the Audit Log as well as over the // "x-teleport-event" channel in the SSH connection. s.emitSessionJoinEvent(ctx) return nil } // session not found? need to create one. start by getting/generating an ID for it sid, found := ctx.GetEnv(sshutils.SessionEnvVar) if !found { sid = string(rsession.NewID()) ctx.SetEnv(sshutils.SessionEnvVar, sid) } // This logic allows concurrent request to create a new session // to fail, what is ok because we should never have this condition sess, err := newSession(rsession.ID(sid), s, ctx) if err != nil { return trace.Wrap(err) } ctx.session = sess s.addSession(sess) ctx.Infof("Creating session %v.", sid) if err := sess.start(ch, ctx); err != nil { sess.Close() return trace.Wrap(err) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L189-L216
go
train
// emitSessionLeaveEvent emits a session leave event to both the Audit Log as // well as sending a "x-teleport-event" global request on the SSH connection.
func (s *SessionRegistry) emitSessionLeaveEvent(party *party)
// emitSessionLeaveEvent emits a session leave event to both the Audit Log as // well as sending a "x-teleport-event" global request on the SSH connection. func (s *SessionRegistry) emitSessionLeaveEvent(party *party)
{ sessionLeaveEvent := events.EventFields{ events.EventType: events.SessionLeaveEvent, events.SessionEventID: party.id.String(), events.EventUser: party.user, events.SessionServerID: party.serverID, events.EventNamespace: s.srv.GetNamespace(), } // Emit session leave event to Audit Log. party.s.recorder.GetAuditLog().EmitAuditEvent(events.SessionLeave, sessionLeaveEvent) // Notify all members of the party that a new member has left over the // "x-teleport-event" channel. for _, p := range s.getParties(party.s) { eventPayload, err := json.Marshal(sessionLeaveEvent) if err != nil { s.log.Warnf("Unable to marshal %v for %v: %v.", events.SessionJoinEvent, p.sconn.RemoteAddr(), err) continue } _, _, err = p.sconn.SendRequest(teleport.SessionEvent, false, eventPayload) if err != nil { s.log.Warnf("Unable to send %v to %v: %v.", events.SessionJoinEvent, p.sconn.RemoteAddr(), err) continue } s.log.Debugf("Sent %v to %v.", events.SessionJoinEvent, p.sconn.RemoteAddr()) } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L219-L281
go
train
// leaveSession removes the given party from this session.
func (s *SessionRegistry) leaveSession(party *party) error
// leaveSession removes the given party from this session. func (s *SessionRegistry) leaveSession(party *party) error
{ sess := party.s s.Lock() defer s.Unlock() // Emit session leave event to both the Audit Log as well as over the // "x-teleport-event" channel in the SSH connection. s.emitSessionLeaveEvent(party) // Remove member from in-members representation of party. if err := sess.removeParty(party); err != nil { return trace.Wrap(err) } // this goroutine runs for a short amount of time only after a session // becomes empty (no parties). It allows session to "linger" for a bit // allowing parties to reconnect if they lost connection momentarily lingerAndDie := func() { lingerTTL := sess.GetLingerTTL() if lingerTTL > 0 { time.Sleep(lingerTTL) } // not lingering anymore? someone reconnected? cool then... no need // to die... if !sess.isLingering() { s.log.Infof("Session %v has become active again.", sess.id) return } s.log.Infof("Session %v will be garbage collected.", sess.id) // no more people left? Need to end the session! s.Lock() delete(s.sessions, sess.id) s.Unlock() // send an event indicating that this session has ended sess.recorder.GetAuditLog().EmitAuditEvent(events.SessionEnd, events.EventFields{ events.SessionEventID: string(sess.id), events.EventUser: party.user, events.EventNamespace: s.srv.GetNamespace(), }) // close recorder to free up associated resources // and flush data sess.recorder.Close() if err := sess.Close(); err != nil { s.log.Errorf("Unable to close session %v: %v", sess.id, err) } // mark it as inactive in the DB if s.srv.GetSessionServer() != nil { False := false s.srv.GetSessionServer().UpdateSession(rsession.UpdateRequest{ ID: sess.id, Active: &False, Namespace: s.srv.GetNamespace(), }) } } go lingerAndDie() return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L285-L300
go
train
// getParties allows to safely return a list of parties connected to this // session (as determined by ctx)
func (s *SessionRegistry) getParties(sess *session) []*party
// getParties allows to safely return a list of parties connected to this // session (as determined by ctx) func (s *SessionRegistry) getParties(sess *session) []*party
{ var parties []*party if sess == nil { return parties } sess.Lock() defer sess.Unlock() for _, p := range sess.parties { parties = append(parties, p) } return parties }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L305-L364
go
train
// NotifyWinChange is called to notify all members in the party that the PTY // size has changed. The notification is sent as a global SSH request and it // is the responsibility of the client to update it's window size upon receipt.
func (s *SessionRegistry) NotifyWinChange(params rsession.TerminalParams, ctx *ServerContext) error
// NotifyWinChange is called to notify all members in the party that the PTY // size has changed. The notification is sent as a global SSH request and it // is the responsibility of the client to update it's window size upon receipt. func (s *SessionRegistry) NotifyWinChange(params rsession.TerminalParams, ctx *ServerContext) error
{ if ctx.session == nil { s.log.Debugf("Unable to update window size, no session found in context.") return nil } sid := ctx.session.id // Build the resize event. resizeEvent := events.EventFields{ events.EventType: events.ResizeEvent, events.EventNamespace: s.srv.GetNamespace(), events.SessionEventID: sid, events.EventLogin: ctx.Identity.Login, events.EventUser: ctx.Identity.TeleportUser, events.TerminalSize: params.Serialize(), } // Report the updated window size to the event log (this is so the sessions // can be replayed correctly). ctx.session.recorder.GetAuditLog().EmitAuditEvent(events.TerminalResize, resizeEvent) // Update the size of the server side PTY. err := ctx.session.term.SetWinSize(params) if err != nil { return trace.Wrap(err) } // If sessions are being recorded at the proxy, sessions can not be shared. // In that situation, PTY size information does not need to be propagated // back to all clients and we can return right away. if ctx.ClusterConfig.GetSessionRecording() == services.RecordAtProxy { return nil } // Notify all members of the party (except originator) that the size of the // window has changed so the client can update it's own local PTY. Note that // OpenSSH clients will ignore this and not update their own local PTY. for _, p := range s.getParties(ctx.session) { // Don't send the window change notification back to the originator. if p.ctx.ID() == ctx.ID() { continue } eventPayload, err := json.Marshal(resizeEvent) if err != nil { s.log.Warnf("Unable to marshal resize event for %v: %v.", p.sconn.RemoteAddr(), err) continue } // Send the message as a global request. _, _, err = p.sconn.SendRequest(teleport.SessionEvent, false, eventPayload) if err != nil { s.log.Warnf("Unable to resize event to %v: %v.", p.sconn.RemoteAddr(), err) continue } s.log.Debugf("Sent resize event %v to %v.", params, p.sconn.RemoteAddr()) } return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L428-L491
go
train
// newSession creates a new session with a given ID within a given context.
func newSession(id rsession.ID, r *SessionRegistry, ctx *ServerContext) (*session, error)
// newSession creates a new session with a given ID within a given context. func newSession(id rsession.ID, r *SessionRegistry, ctx *ServerContext) (*session, error)
{ serverSessions.Inc() rsess := rsession.Session{ ID: id, TerminalParams: rsession.TerminalParams{ W: teleport.DefaultTerminalWidth, H: teleport.DefaultTerminalHeight, }, Login: ctx.Identity.Login, Created: time.Now().UTC(), LastActive: time.Now().UTC(), ServerID: ctx.srv.ID(), Namespace: r.srv.GetNamespace(), } term := ctx.GetTerm() if term != nil { winsize, err := term.GetWinSize() if err != nil { return nil, trace.Wrap(err) } rsess.TerminalParams.W = int(winsize.Width) rsess.TerminalParams.H = int(winsize.Height) } // get the session server where session information lives. if the recording // proxy is being used and this is a node, then a discard session server will // be returned here. sessionServer := r.srv.GetSessionServer() err := sessionServer.CreateSession(rsess) if err != nil { if trace.IsAlreadyExists(err) { // if session already exists, make sure they are compatible // Login matches existing login existing, err := sessionServer.GetSession(r.srv.GetNamespace(), id) if err != nil { return nil, trace.Wrap(err) } if existing.Login != rsess.Login { return nil, trace.AccessDenied( "can't switch users from %v to %v for session %v", rsess.Login, existing.Login, id) } } // return nil, trace.Wrap(err) // No need to abort. Perhaps the auth server is down? // Log the error and continue: r.log.Errorf("Failed to create new session: %v.", err) } sess := &session{ log: logrus.WithFields(logrus.Fields{ trace.Component: teleport.Component(teleport.ComponentSession, r.srv.Component()), }), id: id, registry: r, parties: make(map[rsession.ID]*party), writer: newMultiWriter(), login: ctx.Identity.Login, closeC: make(chan bool), lingerTTL: defaults.SessionIdlePeriod, } return sess, nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L495-L500
go
train
// isLingering returns true if every party has left this session. Occurs // under a lock.
func (s *session) isLingering() bool
// isLingering returns true if every party has left this session. Occurs // under a lock. func (s *session) isLingering() bool
{ s.Lock() defer s.Unlock() return len(s.parties) == 0 }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L503-L529
go
train
// Close ends the active session forcing all clients to disconnect and freeing all resources
func (s *session) Close() error
// Close ends the active session forcing all clients to disconnect and freeing all resources func (s *session) Close() error
{ serverSessions.Dec() s.closeOnce.Do(func() { // closing needs to happen asynchronously because the last client // (session writer) will try to close this session, causing a deadlock // because of closeOnce go func() { s.log.Infof("Closing session %v", s.id) if s.term != nil { s.term.Close() } close(s.closeC) // close all writers in our multi-writer s.writer.Lock() defer s.writer.Unlock() for writerName, writer := range s.writer.writers { s.log.Infof("Closing session writer: %v", writerName) closer, ok := io.Writer(writer).(io.WriteCloser) if ok { closer.Close() } } }() }) return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L537-L698
go
train
// start starts a new interactive process (or a shell) in the current session
func (s *session) start(ch ssh.Channel, ctx *ServerContext) error
// start starts a new interactive process (or a shell) in the current session func (s *session) start(ch ssh.Channel, ctx *ServerContext) error
{ var err error // create a new "party" (connected client) p := newParty(s, ch, ctx) // get the audit log from the server and create a session recorder. this will // be a discard audit log if the proxy is in recording mode and a teleport // node so we don't create double recordings. auditLog := s.registry.srv.GetAuditLog() if auditLog == nil || isDiscardAuditLog(auditLog) { s.recorder = &events.DiscardRecorder{} } else { s.recorder, err = events.NewForwardRecorder(events.ForwardRecorderConfig{ DataDir: filepath.Join(ctx.srv.GetDataDir(), teleport.LogsDir), SessionID: s.id, Namespace: ctx.srv.GetNamespace(), RecordSessions: ctx.ClusterConfig.GetSessionRecording() != services.RecordOff, Component: teleport.Component(teleport.ComponentSession, ctx.srv.Component()), ForwardTo: auditLog, }) if err != nil { return trace.Wrap(err) } } s.writer.addWriter("session-recorder", s.recorder, true) // If this code is running on a Teleport node and PAM is enabled, then open a // PAM context. var pamContext *pam.PAM if ctx.srv.Component() == teleport.ComponentNode { conf, err := s.registry.srv.GetPAM() if err != nil { return trace.Wrap(err) } if conf.Enabled == true { pamContext, err = pam.Open(&pam.Config{ ServiceName: conf.ServiceName, Username: ctx.Identity.Login, Stdin: ch, Stderr: s.writer, Stdout: s.writer, }) if err != nil { return trace.Wrap(err) } ctx.Debugf("Opening PAM context for session %v.", s.id) } } // allocate a terminal or take the one previously allocated via a // seaprate "allocate TTY" SSH request if ctx.GetTerm() != nil { s.term = ctx.GetTerm() ctx.SetTerm(nil) } else { if s.term, err = NewTerminal(ctx); err != nil { ctx.Infof("Unable to allocate new terminal: %v", err) return trace.Wrap(err) } } if err := s.term.Run(); err != nil { ctx.Errorf("Unable to run shell command (%v): %v", ctx.ExecRequest.GetCommand(), err) return trace.ConvertSystemError(err) } if err := s.addParty(p); err != nil { return trace.Wrap(err) } params := s.term.GetTerminalParams() // emit "new session created" event: s.recorder.GetAuditLog().EmitAuditEvent(events.SessionStart, events.EventFields{ events.EventNamespace: ctx.srv.GetNamespace(), events.SessionEventID: string(s.id), events.SessionServerID: ctx.srv.ID(), events.EventLogin: ctx.Identity.Login, events.EventUser: ctx.Identity.TeleportUser, events.LocalAddr: ctx.Conn.LocalAddr().String(), events.RemoteAddr: ctx.Conn.RemoteAddr().String(), events.TerminalSize: params.Serialize(), }) // Start a heartbeat that marks this session as active with current members // of party in the backend. go s.heartbeat(ctx) doneCh := make(chan bool, 1) // copy everything from the pty to the writer. this lets us capture all input // and output of the session (because input is echoed to stdout in the pty). // the writer contains multiple writers: the session logger and a direct // connection to members of the "party" (other people in the session). s.term.AddParty(1) go func() { defer s.term.AddParty(-1) _, err := io.Copy(s.writer, s.term.PTY()) s.log.Debugf("Copying from PTY to writer completed with error %v.", err) // once everything has been copied, notify the goroutine below. if this code // is running in a teleport node, when the exec.Cmd is done it will close // the PTY, allowing io.Copy to return. if this is a teleport forwarding // node, when the remote side closes the channel (which is what s.term.PTY() // returns) io.Copy will return. doneCh <- true }() // wait for exec.Cmd (or receipt of "exit-status" for a forwarding node), // once it is received wait for the io.Copy above to finish, then broadcast // the "exit-status" to the client. go func() { result, err := s.term.Wait() // wait for copying from the pty to be complete or a timeout before // broadcasting the result (which will close the pty) if it has not been // closed already. select { case <-time.After(defaults.WaitCopyTimeout): s.log.Errorf("Timed out waiting for PTY copy to finish, session data for %v may be missing.", s.id) case <-doneCh: } // If this code is running on a Teleport node and PAM is enabled, close the context. if ctx.srv.Component() == teleport.ComponentNode { conf, err := s.registry.srv.GetPAM() if err != nil { ctx.Errorf("Unable to get PAM configuration from server: %v", err) return } if conf.Enabled == true { err = pamContext.Close() if err != nil { ctx.Errorf("Unable to close PAM context for session: %v: %v", s.id, err) return } ctx.Debugf("Closing PAM context for session: %v.", s.id) } } if result != nil { s.registry.broadcastResult(s.id, *result) } if err != nil { s.log.Infof("Shell exited with error: %v", err) } else { // no error? this means the command exited cleanly: no need // for this session to "linger" after this. s.SetLingerTTL(time.Duration(0)) } }() // wait for the session to end before the shell, kill the shell go func() { <-s.closeC s.term.Kill() }() return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L712-L717
go
train
// removePartyMember removes participant from in-memory representation of // party members. Occurs under a lock.
func (s *session) removePartyMember(party *party)
// removePartyMember removes participant from in-memory representation of // party members. Occurs under a lock. func (s *session) removePartyMember(party *party)
{ s.Lock() defer s.Unlock() delete(s.parties, party.id) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L721-L730
go
train
// removeParty removes the party from the in-memory map that holds all party // members.
func (s *session) removeParty(p *party) error
// removeParty removes the party from the in-memory map that holds all party // members. func (s *session) removeParty(p *party) error
{ p.ctx.Infof("Removing party %v from session %v", p, s.id) // Removes participant from in-memory map of party members. s.removePartyMember(p) s.writer.deleteWriter(string(p.id)) return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L750-L766
go
train
// exportPartyMembers exports participants in the in-memory map of party // members. Occurs under a lock.
func (s *session) exportPartyMembers() []rsession.Party
// exportPartyMembers exports participants in the in-memory map of party // members. Occurs under a lock. func (s *session) exportPartyMembers() []rsession.Party
{ s.Lock() defer s.Unlock() var partyList []rsession.Party for _, p := range s.parties { partyList = append(partyList, rsession.Party{ ID: p.id, User: p.user, ServerID: p.serverID, RemoteAddr: p.site, LastActive: p.getLastActive(), }) } return partyList }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L772-L813
go
train
// heartbeat will loop as long as the session is not closed and mark it as // active and update the list of party members. If the session are recorded at // the proxy, then this function does nothing as it's counterpart // in the proxy will do this work.
func (s *session) heartbeat(ctx *ServerContext)
// heartbeat will loop as long as the session is not closed and mark it as // active and update the list of party members. If the session are recorded at // the proxy, then this function does nothing as it's counterpart // in the proxy will do this work. func (s *session) heartbeat(ctx *ServerContext)
{ // If sessions are being recorded at the proxy, an identical version of this // goroutine is running in the proxy, which means it does not need to run here. if ctx.ClusterConfig.GetSessionRecording() == services.RecordAtProxy && s.registry.srv.Component() == teleport.ComponentNode { return } // If no session server (endpoint interface for active sessions) is passed in // (for example Teleconsole does this) then nothing to sync. sessionServer := s.registry.srv.GetSessionServer() if sessionServer == nil { return } s.log.Debugf("Starting poll and sync of terminal size to all parties.") defer s.log.Debugf("Stopping poll and sync of terminal size to all parties.") tickerCh := time.NewTicker(defaults.SessionRefreshPeriod) defer tickerCh.Stop() // Loop as long as the session is active, updating the session in the backend. for { select { case <-tickerCh.C: partyList := s.exportPartyMembers() var active = true err := sessionServer.UpdateSession(rsession.UpdateRequest{ Namespace: s.getNamespace(), ID: s.id, Active: &active, Parties: &partyList, }) if err != nil { s.log.Warnf("Unable to update session %v as active: %v", s.id, err) } case <-s.closeC: return } } }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L817-L822
go
train
// addPartyMember adds participant to in-memory map of party members. Occurs // under a lock.
func (s *session) addPartyMember(p *party)
// addPartyMember adds participant to in-memory map of party members. Occurs // under a lock. func (s *session) addPartyMember(p *party)
{ s.Lock() defer s.Unlock() s.parties[p.id] = p }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L825-L865
go
train
// addParty is called when a new party joins the session.
func (s *session) addParty(p *party) error
// addParty is called when a new party joins the session. func (s *session) addParty(p *party) error
{ if s.login != p.login { return trace.AccessDenied( "can't switch users from %v to %v for session %v", s.login, p.login, s.id) } // Adds participant to in-memory map of party members. s.addPartyMember(p) // Write last chunk (so the newly joined parties won't stare at a blank // screen). getRecentWrite := func() []byte { s.writer.Lock() defer s.writer.Unlock() data := make([]byte, 0, 1024) for i := range s.writer.recentWrites { data = append(data, s.writer.recentWrites[i]...) } return data } p.Write(getRecentWrite()) // Register this party as one of the session writers (output will go to it). s.writer.addWriter(string(p.id), p, true) p.ctx.AddCloser(p) s.term.AddParty(1) s.log.Infof("New party %v joined session: %v", p.String(), s.id) // This goroutine keeps pumping party's input into the session. go func() { defer s.term.AddParty(-1) _, err := io.Copy(s.term.PTY(), p) if err != nil { s.log.Errorf("Party member %v left session %v due an error: %v", p.id, s.id, err) } s.log.Infof("Party member %v left session %v.", p.id, s.id) }() return nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/srv/sess.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/sess.go#L915-L946
go
train
// Write multiplexes the input to multiple sub-writers. The entire point // of multiWriter is to do this
func (m *multiWriter) Write(p []byte) (n int, err error)
// Write multiplexes the input to multiple sub-writers. The entire point // of multiWriter is to do this func (m *multiWriter) Write(p []byte) (n int, err error)
{ // lock and make a local copy of available writers: getWriters := func() (writers []writerWrapper) { m.RLock() defer m.RUnlock() writers = make([]writerWrapper, 0, len(m.writers)) for _, w := range m.writers { writers = append(writers, w) } // add the recent write chunk to the "instant replay" buffer // of the session, to be replayed to newly joining parties: m.lockedAddRecentWrite(p) return writers } // unlock and multiplex the write to all writers: for _, w := range getWriters() { n, err = w.Write(p) if err != nil { if w.closeOnError { return } continue } if n != len(p) { err = io.ErrShortWrite return } } return len(p), nil }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/service/supervisor.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/service/supervisor.go#L96-L98
go
train
// String returns user-friendly representation of the mapping.
func (e EventMapping) String() string
// String returns user-friendly representation of the mapping. func (e EventMapping) String() string
{ return fmt.Sprintf("EventMapping(in=%v, out=%v)", e.In, e.Out) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/service/supervisor.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/service/supervisor.go#L142-L166
go
train
// NewSupervisor returns new instance of initialized supervisor
func NewSupervisor(id string) Supervisor
// NewSupervisor returns new instance of initialized supervisor func NewSupervisor(id string) Supervisor
{ closeContext, cancel := context.WithCancel(context.TODO()) exitContext, signalExit := context.WithCancel(context.TODO()) reloadContext, signalReload := context.WithCancel(context.TODO()) srv := &LocalSupervisor{ id: id, services: []Service{}, wg: &sync.WaitGroup{}, events: map[string]Event{}, eventsC: make(chan Event, 1024), eventWaiters: make(map[string][]*waiter), closeContext: closeContext, signalClose: cancel, exitContext: exitContext, signalExit: signalExit, reloadContext: reloadContext, signalReload: signalReload, } go srv.fanOut() return srv }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/service/supervisor.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/service/supervisor.go#L191-L195
go
train
// ServiceCount returns the number of registered and actively running services
func (s *LocalSupervisor) ServiceCount() int
// ServiceCount returns the number of registered and actively running services func (s *LocalSupervisor) ServiceCount() int
{ s.Lock() defer s.Unlock() return len(s.services) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/service/supervisor.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/service/supervisor.go#L199-L201
go
train
// RegisterFunc creates a service from function spec and registers // it within the system
func (s *LocalSupervisor) RegisterFunc(name string, fn ServiceFunc)
// RegisterFunc creates a service from function spec and registers // it within the system func (s *LocalSupervisor) RegisterFunc(name string, fn ServiceFunc)
{ s.Register(&LocalService{Function: fn, ServiceName: name}) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/service/supervisor.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/service/supervisor.go#L206-L208
go
train
// RegisterCriticalFunc creates a critical service from function spec and registers // it within the system, if this service exits with error, // the process shuts down.
func (s *LocalSupervisor) RegisterCriticalFunc(name string, fn ServiceFunc)
// RegisterCriticalFunc creates a critical service from function spec and registers // it within the system, if this service exits with error, // the process shuts down. func (s *LocalSupervisor) RegisterCriticalFunc(name string, fn ServiceFunc)
{ s.Register(&LocalService{Function: fn, ServiceName: name, Critical: true}) }
gravitational/teleport
d5243dbe8d36bba44bf640c08f1c49185ed2c8a4
lib/service/supervisor.go
https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/service/supervisor.go#L211-L224
go
train
// RemoveService removes service from supervisor tracking list
func (s *LocalSupervisor) RemoveService(srv Service) error
// RemoveService removes service from supervisor tracking list func (s *LocalSupervisor) RemoveService(srv Service) error
{ l := logrus.WithFields(logrus.Fields{"service": srv.Name(), trace.Component: teleport.Component(teleport.ComponentProcess, s.id)}) s.Lock() defer s.Unlock() for i, el := range s.services { if el == srv { s.services = append(s.services[:i], s.services[i+1:]...) l.Debugf("Service is completed and removed.") return nil } } l.Warningf("Service is completed but not found.") return trace.NotFound("service %v is not found", srv) }