repo stringlengths 5 54 | path stringlengths 4 155 | func_name stringlengths 1 118 | original_string stringlengths 52 85.5k | language stringclasses 1
value | code stringlengths 52 85.5k | code_tokens list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
gravitational/teleport | lib/backend/legacy/legacy.go | AnyTTL | func AnyTTL(clock clockwork.Clock, times ...time.Time) time.Duration {
for _, t := range times {
if !t.IsZero() {
return TTL(clock, t)
}
}
return Forever
} | go | func AnyTTL(clock clockwork.Clock, times ...time.Time) time.Duration {
for _, t := range times {
if !t.IsZero() {
return TTL(clock, t)
}
}
return Forever
} | [
"func",
"AnyTTL",
"(",
"clock",
"clockwork",
".",
"Clock",
",",
"times",
"...",
"time",
".",
"Time",
")",
"time",
".",
"Duration",
"{",
"for",
"_",
",",
"t",
":=",
"range",
"times",
"{",
"if",
"!",
"t",
".",
"IsZero",
"(",
")",
"{",
"return",
"TT... | // AnyTTL returns TTL if any of the suplied times pass expiry time
// otherwise returns forever | [
"AnyTTL",
"returns",
"TTL",
"if",
"any",
"of",
"the",
"suplied",
"times",
"pass",
"expiry",
"time",
"otherwise",
"returns",
"forever"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/legacy.go#L193-L200 | train |
gravitational/teleport | lib/limiter/connlimiter.go | NewConnectionsLimiter | func NewConnectionsLimiter(config LimiterConfig) (*ConnectionsLimiter, error) {
limiter := ConnectionsLimiter{
Mutex: &sync.Mutex{},
maxConnections: config.MaxConnections,
connections: make(map[string]int64),
}
ipExtractor, err := utils.NewExtractor("client.ip")
if err != nil {
return nil, trac... | go | func NewConnectionsLimiter(config LimiterConfig) (*ConnectionsLimiter, error) {
limiter := ConnectionsLimiter{
Mutex: &sync.Mutex{},
maxConnections: config.MaxConnections,
connections: make(map[string]int64),
}
ipExtractor, err := utils.NewExtractor("client.ip")
if err != nil {
return nil, trac... | [
"func",
"NewConnectionsLimiter",
"(",
"config",
"LimiterConfig",
")",
"(",
"*",
"ConnectionsLimiter",
",",
"error",
")",
"{",
"limiter",
":=",
"ConnectionsLimiter",
"{",
"Mutex",
":",
"&",
"sync",
".",
"Mutex",
"{",
"}",
",",
"maxConnections",
":",
"config",
... | // NewConnectionsLimiter returns new connection limiter, in case if connection
// limits are not set, they won't be tracked | [
"NewConnectionsLimiter",
"returns",
"new",
"connection",
"limiter",
"in",
"case",
"if",
"connection",
"limits",
"are",
"not",
"set",
"they",
"won",
"t",
"be",
"tracked"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/limiter/connlimiter.go#L39-L58 | train |
gravitational/teleport | lib/limiter/connlimiter.go | WrapHandle | func (l *ConnectionsLimiter) WrapHandle(h http.Handler) {
l.ConnLimiter.Wrap(h)
} | go | func (l *ConnectionsLimiter) WrapHandle(h http.Handler) {
l.ConnLimiter.Wrap(h)
} | [
"func",
"(",
"l",
"*",
"ConnectionsLimiter",
")",
"WrapHandle",
"(",
"h",
"http",
".",
"Handler",
")",
"{",
"l",
".",
"ConnLimiter",
".",
"Wrap",
"(",
"h",
")",
"\n",
"}"
] | // WrapHandle adds connection limiter to the handle | [
"WrapHandle",
"adds",
"connection",
"limiter",
"to",
"the",
"handle"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/limiter/connlimiter.go#L61-L63 | train |
gravitational/teleport | lib/limiter/connlimiter.go | AcquireConnection | func (l *ConnectionsLimiter) AcquireConnection(token string) error {
l.Lock()
defer l.Unlock()
if l.maxConnections == 0 {
return nil
}
numberOfConnections, exists := l.connections[token]
if !exists {
l.connections[token] = 1
return nil
}
if numberOfConnections >= l.maxConnections {
return trace.LimitE... | go | func (l *ConnectionsLimiter) AcquireConnection(token string) error {
l.Lock()
defer l.Unlock()
if l.maxConnections == 0 {
return nil
}
numberOfConnections, exists := l.connections[token]
if !exists {
l.connections[token] = 1
return nil
}
if numberOfConnections >= l.maxConnections {
return trace.LimitE... | [
"func",
"(",
"l",
"*",
"ConnectionsLimiter",
")",
"AcquireConnection",
"(",
"token",
"string",
")",
"error",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"maxConnections",
"==",
"0",
"{",
"retu... | // AcquireConnection acquires connection and bumps counter | [
"AcquireConnection",
"acquires",
"connection",
"and",
"bumps",
"counter"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/limiter/connlimiter.go#L66-L86 | train |
gravitational/teleport | lib/limiter/connlimiter.go | ReleaseConnection | func (l *ConnectionsLimiter) ReleaseConnection(token string) {
l.Lock()
defer l.Unlock()
if l.maxConnections == 0 {
return
}
numberOfConnections, exists := l.connections[token]
if !exists {
log.Errorf("Trying to set negative number of connections")
} else {
if numberOfConnections <= 1 {
delete(l.conn... | go | func (l *ConnectionsLimiter) ReleaseConnection(token string) {
l.Lock()
defer l.Unlock()
if l.maxConnections == 0 {
return
}
numberOfConnections, exists := l.connections[token]
if !exists {
log.Errorf("Trying to set negative number of connections")
} else {
if numberOfConnections <= 1 {
delete(l.conn... | [
"func",
"(",
"l",
"*",
"ConnectionsLimiter",
")",
"ReleaseConnection",
"(",
"token",
"string",
")",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"if",
"l",
".",
"maxConnections",
"==",
"0",
"{",
"return",
"\n"... | // ReleaseConnection decrements the counter | [
"ReleaseConnection",
"decrements",
"the",
"counter"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/limiter/connlimiter.go#L89-L108 | train |
gravitational/teleport | lib/utils/time.go | MinTTL | func MinTTL(a, b time.Duration) time.Duration {
if a == 0 {
return b
}
if b == 0 {
return a
}
if a < b {
return a
}
return b
} | go | func MinTTL(a, b time.Duration) time.Duration {
if a == 0 {
return b
}
if b == 0 {
return a
}
if a < b {
return a
}
return b
} | [
"func",
"MinTTL",
"(",
"a",
",",
"b",
"time",
".",
"Duration",
")",
"time",
".",
"Duration",
"{",
"if",
"a",
"==",
"0",
"{",
"return",
"b",
"\n",
"}",
"\n",
"if",
"b",
"==",
"0",
"{",
"return",
"a",
"\n",
"}",
"\n",
"if",
"a",
"<",
"b",
"{"... | // MinTTL finds min non 0 TTL duration,
// if both durations are 0, fails | [
"MinTTL",
"finds",
"min",
"non",
"0",
"TTL",
"duration",
"if",
"both",
"durations",
"are",
"0",
"fails"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/time.go#L11-L22 | train |
gravitational/teleport | lib/utils/time.go | ToTTL | func ToTTL(c clockwork.Clock, tm time.Time) time.Duration {
now := c.Now().UTC()
if tm.IsZero() || tm.Before(now) {
return 0
}
return tm.Sub(now)
} | go | func ToTTL(c clockwork.Clock, tm time.Time) time.Duration {
now := c.Now().UTC()
if tm.IsZero() || tm.Before(now) {
return 0
}
return tm.Sub(now)
} | [
"func",
"ToTTL",
"(",
"c",
"clockwork",
".",
"Clock",
",",
"tm",
"time",
".",
"Time",
")",
"time",
".",
"Duration",
"{",
"now",
":=",
"c",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"\n",
"if",
"tm",
".",
"IsZero",
"(",
")",
"||",
"tm",
".",... | // ToTTL converts expiration time to TTL duration
// relative to current time as provided by clock | [
"ToTTL",
"converts",
"expiration",
"time",
"to",
"TTL",
"duration",
"relative",
"to",
"current",
"time",
"as",
"provided",
"by",
"clock"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/time.go#L26-L32 | train |
gravitational/teleport | lib/utils/time.go | UTC | func UTC(t *time.Time) {
if t == nil {
return
}
if t.IsZero() {
// to fix issue with timezones for tests
*t = time.Time{}
return
}
*t = t.UTC()
} | go | func UTC(t *time.Time) {
if t == nil {
return
}
if t.IsZero() {
// to fix issue with timezones for tests
*t = time.Time{}
return
}
*t = t.UTC()
} | [
"func",
"UTC",
"(",
"t",
"*",
"time",
".",
"Time",
")",
"{",
"if",
"t",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"IsZero",
"(",
")",
"{",
"// to fix issue with timezones for tests",
"*",
"t",
"=",
"time",
".",
"Time",
"{",
"}"... | // UTC converts time to UTC timezone | [
"UTC",
"converts",
"time",
"to",
"UTC",
"timezone"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/time.go#L35-L46 | train |
gravitational/teleport | lib/auth/password.go | ChangePassword | func (s *AuthServer) ChangePassword(req services.ChangePasswordReq) error {
// validate new password
err := services.VerifyPassword(req.NewPassword)
if err != nil {
return trace.Wrap(err)
}
authPreference, err := s.GetAuthPreference()
if err != nil {
return trace.Wrap(err)
}
userID := req.User
fn := func... | go | func (s *AuthServer) ChangePassword(req services.ChangePasswordReq) error {
// validate new password
err := services.VerifyPassword(req.NewPassword)
if err != nil {
return trace.Wrap(err)
}
authPreference, err := s.GetAuthPreference()
if err != nil {
return trace.Wrap(err)
}
userID := req.User
fn := func... | [
"func",
"(",
"s",
"*",
"AuthServer",
")",
"ChangePassword",
"(",
"req",
"services",
".",
"ChangePasswordReq",
")",
"error",
"{",
"// validate new password",
"err",
":=",
"services",
".",
"VerifyPassword",
"(",
"req",
".",
"NewPassword",
")",
"\n",
"if",
"err",... | // ChangePassword changes user passsword | [
"ChangePassword",
"changes",
"user",
"passsword"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/password.go#L21-L58 | train |
gravitational/teleport | lib/auth/password.go | CheckPasswordWOToken | func (s *AuthServer) CheckPasswordWOToken(user string, password []byte) error {
const errMsg = "invalid username or password"
err := services.VerifyPassword(password)
if err != nil {
return trace.BadParameter(errMsg)
}
hash, err := s.GetPasswordHash(user)
if err != nil && !trace.IsNotFound(err) {
return tra... | go | func (s *AuthServer) CheckPasswordWOToken(user string, password []byte) error {
const errMsg = "invalid username or password"
err := services.VerifyPassword(password)
if err != nil {
return trace.BadParameter(errMsg)
}
hash, err := s.GetPasswordHash(user)
if err != nil && !trace.IsNotFound(err) {
return tra... | [
"func",
"(",
"s",
"*",
"AuthServer",
")",
"CheckPasswordWOToken",
"(",
"user",
"string",
",",
"password",
"[",
"]",
"byte",
")",
"error",
"{",
"const",
"errMsg",
"=",
"\"",
"\"",
"\n\n",
"err",
":=",
"services",
".",
"VerifyPassword",
"(",
"password",
")... | // CheckPasswordWOToken checks just password without checking OTP tokens
// used in case of SSH authentication, when token has been validated. | [
"CheckPasswordWOToken",
"checks",
"just",
"password",
"without",
"checking",
"OTP",
"tokens",
"used",
"in",
"case",
"of",
"SSH",
"authentication",
"when",
"token",
"has",
"been",
"validated",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/password.go#L62-L85 | train |
gravitational/teleport | lib/auth/password.go | GetOTPData | func (s *AuthServer) GetOTPData(user string) (string, []byte, error) {
// get otp key from backend
otpSecret, err := s.GetTOTP(user)
if err != nil {
return "", nil, trace.Wrap(err)
}
// create otp url
params := map[string][]byte{"secret": []byte(otpSecret)}
otpURL := utils.GenerateOTPURL("totp", user, params)... | go | func (s *AuthServer) GetOTPData(user string) (string, []byte, error) {
// get otp key from backend
otpSecret, err := s.GetTOTP(user)
if err != nil {
return "", nil, trace.Wrap(err)
}
// create otp url
params := map[string][]byte{"secret": []byte(otpSecret)}
otpURL := utils.GenerateOTPURL("totp", user, params)... | [
"func",
"(",
"s",
"*",
"AuthServer",
")",
"GetOTPData",
"(",
"user",
"string",
")",
"(",
"string",
",",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// get otp key from backend",
"otpSecret",
",",
"err",
":=",
"s",
".",
"GetTOTP",
"(",
"user",
")",
"\n",... | // GetOTPData returns the OTP Key, Key URL, and the QR code. | [
"GetOTPData",
"returns",
"the",
"OTP",
"Key",
"Key",
"URL",
"and",
"the",
"QR",
"code",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/auth/password.go#L182-L200 | train |
gravitational/teleport | lib/services/parser.go | NewWhereParser | func NewWhereParser(ctx RuleContext) (predicate.Parser, error) {
return predicate.NewParser(predicate.Def{
Operators: predicate.Operators{
AND: predicate.And,
OR: predicate.Or,
NOT: predicate.Not,
},
Functions: map[string]interface{}{
"equals": predicate.Equals,
"contains": predicate.Contains,
... | go | func NewWhereParser(ctx RuleContext) (predicate.Parser, error) {
return predicate.NewParser(predicate.Def{
Operators: predicate.Operators{
AND: predicate.And,
OR: predicate.Or,
NOT: predicate.Not,
},
Functions: map[string]interface{}{
"equals": predicate.Equals,
"contains": predicate.Contains,
... | [
"func",
"NewWhereParser",
"(",
"ctx",
"RuleContext",
")",
"(",
"predicate",
".",
"Parser",
",",
"error",
")",
"{",
"return",
"predicate",
".",
"NewParser",
"(",
"predicate",
".",
"Def",
"{",
"Operators",
":",
"predicate",
".",
"Operators",
"{",
"AND",
":",... | // NewWhereParser returns standard parser for `where` section in access rules. | [
"NewWhereParser",
"returns",
"standard",
"parser",
"for",
"where",
"section",
"in",
"access",
"rules",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/parser.go#L56-L87 | train |
gravitational/teleport | lib/services/parser.go | NewActionsParser | func NewActionsParser(ctx RuleContext) (predicate.Parser, error) {
return predicate.NewParser(predicate.Def{
Operators: predicate.Operators{},
Functions: map[string]interface{}{
"log": NewLogActionFn(ctx),
},
GetIdentifier: ctx.GetIdentifier,
GetProperty: predicate.GetStringMapValue,
})
} | go | func NewActionsParser(ctx RuleContext) (predicate.Parser, error) {
return predicate.NewParser(predicate.Def{
Operators: predicate.Operators{},
Functions: map[string]interface{}{
"log": NewLogActionFn(ctx),
},
GetIdentifier: ctx.GetIdentifier,
GetProperty: predicate.GetStringMapValue,
})
} | [
"func",
"NewActionsParser",
"(",
"ctx",
"RuleContext",
")",
"(",
"predicate",
".",
"Parser",
",",
"error",
")",
"{",
"return",
"predicate",
".",
"NewParser",
"(",
"predicate",
".",
"Def",
"{",
"Operators",
":",
"predicate",
".",
"Operators",
"{",
"}",
",",... | // NewActionsParser returns standard parser for 'actions' section in access rules | [
"NewActionsParser",
"returns",
"standard",
"parser",
"for",
"actions",
"section",
"in",
"access",
"rules"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/parser.go#L125-L134 | train |
gravitational/teleport | lib/services/parser.go | NewLogActionFn | func NewLogActionFn(ctx RuleContext) interface{} {
l := &LogAction{ctx: ctx}
writer, ok := ctx.(io.Writer)
if ok && writer != nil {
l.writer = writer
}
return l.Log
} | go | func NewLogActionFn(ctx RuleContext) interface{} {
l := &LogAction{ctx: ctx}
writer, ok := ctx.(io.Writer)
if ok && writer != nil {
l.writer = writer
}
return l.Log
} | [
"func",
"NewLogActionFn",
"(",
"ctx",
"RuleContext",
")",
"interface",
"{",
"}",
"{",
"l",
":=",
"&",
"LogAction",
"{",
"ctx",
":",
"ctx",
"}",
"\n",
"writer",
",",
"ok",
":=",
"ctx",
".",
"(",
"io",
".",
"Writer",
")",
"\n",
"if",
"ok",
"&&",
"w... | // NewLogActionFn creates logger functions | [
"NewLogActionFn",
"creates",
"logger",
"functions"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/parser.go#L137-L144 | train |
gravitational/teleport | lib/services/parser.go | Log | func (l *LogAction) Log(level, format string, args ...interface{}) predicate.BoolPredicate {
return func() bool {
ilevel, err := log.ParseLevel(level)
if err != nil {
ilevel = log.DebugLevel
}
var writer io.Writer
if l.writer != nil {
writer = l.writer
} else {
writer = log.StandardLogger().Writer... | go | func (l *LogAction) Log(level, format string, args ...interface{}) predicate.BoolPredicate {
return func() bool {
ilevel, err := log.ParseLevel(level)
if err != nil {
ilevel = log.DebugLevel
}
var writer io.Writer
if l.writer != nil {
writer = l.writer
} else {
writer = log.StandardLogger().Writer... | [
"func",
"(",
"l",
"*",
"LogAction",
")",
"Log",
"(",
"level",
",",
"format",
"string",
",",
"args",
"...",
"interface",
"{",
"}",
")",
"predicate",
".",
"BoolPredicate",
"{",
"return",
"func",
"(",
")",
"bool",
"{",
"ilevel",
",",
"err",
":=",
"log",... | // Log logs with specified level and formatting string with arguments | [
"Log",
"logs",
"with",
"specified",
"level",
"and",
"formatting",
"string",
"with",
"arguments"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/parser.go#L154-L169 | train |
gravitational/teleport | lib/services/parser.go | String | func (ctx *Context) String() string {
return fmt.Sprintf("user %v, resource: %v", ctx.User, ctx.Resource)
} | go | func (ctx *Context) String() string {
return fmt.Sprintf("user %v, resource: %v", ctx.User, ctx.Resource)
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ctx",
".",
"User",
",",
"ctx",
".",
"Resource",
")",
"\n",
"}"
] | // String returns user friendly representation of this context | [
"String",
"returns",
"user",
"friendly",
"representation",
"of",
"this",
"context"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/parser.go#L181-L183 | train |
gravitational/teleport | lib/services/parser.go | GetResource | func (ctx *Context) GetResource() (Resource, error) {
if ctx.Resource == nil {
return nil, trace.NotFound("resource is not set in the context")
}
return ctx.Resource, nil
} | go | func (ctx *Context) GetResource() (Resource, error) {
if ctx.Resource == nil {
return nil, trace.NotFound("resource is not set in the context")
}
return ctx.Resource, nil
} | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"GetResource",
"(",
")",
"(",
"Resource",
",",
"error",
")",
"{",
"if",
"ctx",
".",
"Resource",
"==",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"NotFound",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ret... | // GetResource returns resource specified in the context,
// returns error if not specified. | [
"GetResource",
"returns",
"resource",
"specified",
"in",
"the",
"context",
"returns",
"error",
"if",
"not",
"specified",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/parser.go#L194-L199 | train |
gravitational/teleport | lib/services/parser.go | GetIdentifier | func (ctx *Context) GetIdentifier(fields []string) (interface{}, error) {
switch fields[0] {
case UserIdentifier:
var user User
if ctx.User == nil {
user = emptyUser
} else {
user = ctx.User
}
return predicate.GetFieldByTag(user, teleport.JSON, fields[1:])
case ResourceIdentifier:
var resource Reso... | go | func (ctx *Context) GetIdentifier(fields []string) (interface{}, error) {
switch fields[0] {
case UserIdentifier:
var user User
if ctx.User == nil {
user = emptyUser
} else {
user = ctx.User
}
return predicate.GetFieldByTag(user, teleport.JSON, fields[1:])
case ResourceIdentifier:
var resource Reso... | [
"func",
"(",
"ctx",
"*",
"Context",
")",
"GetIdentifier",
"(",
"fields",
"[",
"]",
"string",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"switch",
"fields",
"[",
"0",
"]",
"{",
"case",
"UserIdentifier",
":",
"var",
"user",
"User",
"\n",
... | // GetIdentifier returns identifier defined in a context | [
"GetIdentifier",
"returns",
"identifier",
"defined",
"in",
"a",
"context"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/parser.go#L202-L223 | train |
gravitational/teleport | lib/secret/secret.go | ParseKey | func ParseKey(k []byte) (Key, error) {
key, err := hex.DecodeString(string(k))
if err != nil {
return nil, trace.Wrap(err)
}
return Key(key), nil
} | go | func ParseKey(k []byte) (Key, error) {
key, err := hex.DecodeString(string(k))
if err != nil {
return nil, trace.Wrap(err)
}
return Key(key), nil
} | [
"func",
"ParseKey",
"(",
"k",
"[",
"]",
"byte",
")",
"(",
"Key",
",",
"error",
")",
"{",
"key",
",",
"err",
":=",
"hex",
".",
"DecodeString",
"(",
"string",
"(",
"k",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trace",... | // ParseKey reads in an existing hex encoded key. | [
"ParseKey",
"reads",
"in",
"an",
"existing",
"hex",
"encoded",
"key",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/secret/secret.go#L54-L61 | train |
gravitational/teleport | lib/secret/secret.go | Seal | func (k Key) Seal(plaintext []byte) ([]byte, error) {
block, err := aes.NewCipher([]byte(k))
if err != nil {
return nil, trace.Wrap(err)
}
aesgcm, err := cipher.NewGCM(block)
if err != nil {
return nil, trace.Wrap(err)
}
nonce := make([]byte, aesgcm.NonceSize())
_, err = io.ReadFull(rand.Reader, nonce)
i... | go | func (k Key) Seal(plaintext []byte) ([]byte, error) {
block, err := aes.NewCipher([]byte(k))
if err != nil {
return nil, trace.Wrap(err)
}
aesgcm, err := cipher.NewGCM(block)
if err != nil {
return nil, trace.Wrap(err)
}
nonce := make([]byte, aesgcm.NonceSize())
_, err = io.ReadFull(rand.Reader, nonce)
i... | [
"func",
"(",
"k",
"Key",
")",
"Seal",
"(",
"plaintext",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"block",
",",
"err",
":=",
"aes",
".",
"NewCipher",
"(",
"[",
"]",
"byte",
"(",
"k",
")",
")",
"\n",
"if",
"err",
... | // Seal will encrypt then authenticate the ciphertext. | [
"Seal",
"will",
"encrypt",
"then",
"authenticate",
"the",
"ciphertext",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/secret/secret.go#L64-L90 | train |
gravitational/teleport | lib/secret/secret.go | Open | func (k Key) Open(ciphertext []byte) ([]byte, error) {
var data sealedData
err := json.Unmarshal(ciphertext, &data)
if err != nil {
return nil, trace.Wrap(err)
}
block, err := aes.NewCipher(k)
if err != nil {
return nil, trace.Wrap(err)
}
aesgcm, err := cipher.NewGCM(block)
if err != nil {
return nil,... | go | func (k Key) Open(ciphertext []byte) ([]byte, error) {
var data sealedData
err := json.Unmarshal(ciphertext, &data)
if err != nil {
return nil, trace.Wrap(err)
}
block, err := aes.NewCipher(k)
if err != nil {
return nil, trace.Wrap(err)
}
aesgcm, err := cipher.NewGCM(block)
if err != nil {
return nil,... | [
"func",
"(",
"k",
"Key",
")",
"Open",
"(",
"ciphertext",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"data",
"sealedData",
"\n\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"ciphertext",
",",
"&",
"data",
")",
"... | // Open will authenticate then decrypt the ciphertext. | [
"Open",
"will",
"authenticate",
"then",
"decrypt",
"the",
"ciphertext",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/secret/secret.go#L93-L117 | train |
gravitational/teleport | lib/events/forward.go | NewForwarder | func NewForwarder(cfg ForwarderConfig) (*Forwarder, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
diskLogger, err := NewDiskSessionLogger(DiskSessionLoggerConfig{
SessionID: cfg.SessionID,
DataDir: cfg.DataDir,
RecordSessions: cfg.RecordSessions,
Names... | go | func NewForwarder(cfg ForwarderConfig) (*Forwarder, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
diskLogger, err := NewDiskSessionLogger(DiskSessionLoggerConfig{
SessionID: cfg.SessionID,
DataDir: cfg.DataDir,
RecordSessions: cfg.RecordSessions,
Names... | [
"func",
"NewForwarder",
"(",
"cfg",
"ForwarderConfig",
")",
"(",
"*",
"Forwarder",
",",
"error",
")",
"{",
"if",
"err",
":=",
"cfg",
".",
"CheckAndSetDefaults",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"Wrap",
"(",
... | // NewForwarder returns a new instance of session forwarder | [
"NewForwarder",
"returns",
"a",
"new",
"instance",
"of",
"session",
"forwarder"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/forward.go#L71-L90 | train |
gravitational/teleport | lib/events/forward.go | Close | func (l *Forwarder) Close() error {
l.Lock()
defer l.Unlock()
if l.isClosed {
return nil
}
l.isClosed = true
return l.sessionLogger.Finalize()
} | go | func (l *Forwarder) Close() error {
l.Lock()
defer l.Unlock()
if l.isClosed {
return nil
}
l.isClosed = true
return l.sessionLogger.Finalize()
} | [
"func",
"(",
"l",
"*",
"Forwarder",
")",
"Close",
"(",
")",
"error",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n",
"if",
"l",
".",
"isClosed",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"l",
".",
"isClosed",
... | // Closer releases connection and resources associated with log if any | [
"Closer",
"releases",
"connection",
"and",
"resources",
"associated",
"with",
"log",
"if",
"any"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/forward.go#L104-L112 | train |
gravitational/teleport | lib/events/forward.go | WaitForDelivery | func (l *Forwarder) WaitForDelivery(ctx context.Context) error {
return l.ForwardTo.WaitForDelivery(ctx)
} | go | func (l *Forwarder) WaitForDelivery(ctx context.Context) error {
return l.ForwardTo.WaitForDelivery(ctx)
} | [
"func",
"(",
"l",
"*",
"Forwarder",
")",
"WaitForDelivery",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"return",
"l",
".",
"ForwardTo",
".",
"WaitForDelivery",
"(",
"ctx",
")",
"\n",
"}"
] | // WaitForDelivery waits for resources to be released and outstanding requests to
// complete after calling Close method | [
"WaitForDelivery",
"waits",
"for",
"resources",
"to",
"be",
"released",
"and",
"outstanding",
"requests",
"to",
"complete",
"after",
"calling",
"Close",
"method"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/forward.go#L241-L243 | train |
gravitational/teleport | lib/backend/legacy/boltbk/boltbk.go | Exists | func Exists(path string) (bool, error) {
path, err := filepath.Abs(filepath.Join(path, keysBoltFile))
if err != nil {
return false, trace.Wrap(err)
}
f, err := os.Open(path)
err = trace.ConvertSystemError(err)
if err != nil {
if trace.IsNotFound(err) {
return false, nil
}
return false, trace.Wrap(err)
... | go | func Exists(path string) (bool, error) {
path, err := filepath.Abs(filepath.Join(path, keysBoltFile))
if err != nil {
return false, trace.Wrap(err)
}
f, err := os.Open(path)
err = trace.ConvertSystemError(err)
if err != nil {
if trace.IsNotFound(err) {
return false, nil
}
return false, trace.Wrap(err)
... | [
"func",
"Exists",
"(",
"path",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"path",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"filepath",
".",
"Join",
"(",
"path",
",",
"keysBoltFile",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"r... | // Exists returns true if backend has been used before | [
"Exists",
"returns",
"true",
"if",
"backend",
"has",
"been",
"used",
"before"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/boltbk/boltbk.go#L66-L81 | train |
gravitational/teleport | lib/backend/legacy/boltbk/boltbk.go | New | func New(params legacy.Params) (*BoltBackend, error) {
// look at 'path' parameter, if it's missing use 'data_dir' (default):
path := params.GetString("path")
if len(path) == 0 {
path = params.GetString(teleport.DataDirParameterName)
}
// still nothing? return an error:
if path == "" {
return nil, trace.BadPa... | go | func New(params legacy.Params) (*BoltBackend, error) {
// look at 'path' parameter, if it's missing use 'data_dir' (default):
path := params.GetString("path")
if len(path) == 0 {
path = params.GetString(teleport.DataDirParameterName)
}
// still nothing? return an error:
if path == "" {
return nil, trace.BadPa... | [
"func",
"New",
"(",
"params",
"legacy",
".",
"Params",
")",
"(",
"*",
"BoltBackend",
",",
"error",
")",
"{",
"// look at 'path' parameter, if it's missing use 'data_dir' (default):",
"path",
":=",
"params",
".",
"GetString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"le... | // New initializes and returns a fully created BoltDB backend. It's
// a properly implemented Backend.NewFunc, part of a backend API | [
"New",
"initializes",
"and",
"returns",
"a",
"fully",
"created",
"BoltDB",
"backend",
".",
"It",
"s",
"a",
"properly",
"implemented",
"Backend",
".",
"NewFunc",
"part",
"of",
"a",
"backend",
"API"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/boltbk/boltbk.go#L85-L117 | train |
gravitational/teleport | lib/backend/legacy/boltbk/boltbk.go | GetItems | func (b *BoltBackend) GetItems(path []string, opts ...legacy.OpOption) ([]legacy.Item, error) {
cfg, err := legacy.CollectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
if cfg.Recursive {
return b.getItemsRecursive(path)
}
keys, err := b.GetKeys(path)
if err != nil {
return nil, trace.Wrap(er... | go | func (b *BoltBackend) GetItems(path []string, opts ...legacy.OpOption) ([]legacy.Item, error) {
cfg, err := legacy.CollectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
if cfg.Recursive {
return b.getItemsRecursive(path)
}
keys, err := b.GetKeys(path)
if err != nil {
return nil, trace.Wrap(er... | [
"func",
"(",
"b",
"*",
"BoltBackend",
")",
"GetItems",
"(",
"path",
"[",
"]",
"string",
",",
"opts",
"...",
"legacy",
".",
"OpOption",
")",
"(",
"[",
"]",
"legacy",
".",
"Item",
",",
"error",
")",
"{",
"cfg",
",",
"err",
":=",
"legacy",
".",
"Col... | // GetItems fetches keys and values and returns them to the caller. | [
"GetItems",
"fetches",
"keys",
"and",
"values",
"and",
"returns",
"them",
"to",
"the",
"caller",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/boltbk/boltbk.go#L278-L309 | train |
gravitational/teleport | lib/backend/legacy/boltbk/boltbk.go | CompareAndSwapVal | func (b *BoltBackend) CompareAndSwapVal(bucket []string, key string, newData []byte, prevData []byte, ttl time.Duration) error {
if len(prevData) == 0 {
return trace.BadParameter("missing prevData parameter, to atomically create item, use CreateVal method")
}
v := &kv{
Created: b.clock.Now().UTC(),
Value: ne... | go | func (b *BoltBackend) CompareAndSwapVal(bucket []string, key string, newData []byte, prevData []byte, ttl time.Duration) error {
if len(prevData) == 0 {
return trace.BadParameter("missing prevData parameter, to atomically create item, use CreateVal method")
}
v := &kv{
Created: b.clock.Now().UTC(),
Value: ne... | [
"func",
"(",
"b",
"*",
"BoltBackend",
")",
"CompareAndSwapVal",
"(",
"bucket",
"[",
"]",
"string",
",",
"key",
"string",
",",
"newData",
"[",
"]",
"byte",
",",
"prevData",
"[",
"]",
"byte",
",",
"ttl",
"time",
".",
"Duration",
")",
"error",
"{",
"if"... | // CompareAndSwapVal compares and swap values in atomic operation,
// succeeds if prevData matches the value stored in the databases,
// requires prevData as a non-empty value. Returns trace.CompareFailed
// in case if value did not match | [
"CompareAndSwapVal",
"compares",
"and",
"swap",
"values",
"in",
"atomic",
"operation",
"succeeds",
"if",
"prevData",
"matches",
"the",
"value",
"stored",
"in",
"the",
"databases",
"requires",
"prevData",
"as",
"a",
"non",
"-",
"empty",
"value",
".",
"Returns",
... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/boltbk/boltbk.go#L357-L396 | train |
gravitational/teleport | lib/services/invite.go | NewInviteToken | func NewInviteToken(token, signupURL string, expires time.Time) *InviteTokenV3 {
tok := InviteTokenV3{
Kind: KindInviteToken,
Version: V3,
Metadata: Metadata{
Name: token,
},
Spec: InviteTokenSpecV3{
URL: signupURL,
},
}
if !expires.IsZero() {
tok.Metadata.SetExpiry(expires)
}
return &tok
} | go | func NewInviteToken(token, signupURL string, expires time.Time) *InviteTokenV3 {
tok := InviteTokenV3{
Kind: KindInviteToken,
Version: V3,
Metadata: Metadata{
Name: token,
},
Spec: InviteTokenSpecV3{
URL: signupURL,
},
}
if !expires.IsZero() {
tok.Metadata.SetExpiry(expires)
}
return &tok
} | [
"func",
"NewInviteToken",
"(",
"token",
",",
"signupURL",
"string",
",",
"expires",
"time",
".",
"Time",
")",
"*",
"InviteTokenV3",
"{",
"tok",
":=",
"InviteTokenV3",
"{",
"Kind",
":",
"KindInviteToken",
",",
"Version",
":",
"V3",
",",
"Metadata",
":",
"Me... | // NewInviteToken returns a new instance of the invite token | [
"NewInviteToken",
"returns",
"a",
"new",
"instance",
"of",
"the",
"invite",
"token"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/invite.go#L48-L63 | train |
gravitational/teleport | lib/sshutils/scp/http.go | CreateHTTPUpload | func CreateHTTPUpload(req HTTPTransferRequest) (Command, error) {
if req.HTTPRequest == nil {
return nil, trace.BadParameter("missing parameter HTTPRequest")
}
if req.FileName == "" {
return nil, trace.BadParameter("missing file name")
}
if req.RemoteLocation == "" {
return nil, trace.BadParameter("missing... | go | func CreateHTTPUpload(req HTTPTransferRequest) (Command, error) {
if req.HTTPRequest == nil {
return nil, trace.BadParameter("missing parameter HTTPRequest")
}
if req.FileName == "" {
return nil, trace.BadParameter("missing file name")
}
if req.RemoteLocation == "" {
return nil, trace.BadParameter("missing... | [
"func",
"CreateHTTPUpload",
"(",
"req",
"HTTPTransferRequest",
")",
"(",
"Command",
",",
"error",
")",
"{",
"if",
"req",
".",
"HTTPRequest",
"==",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"BadParameter",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
... | // CreateHTTPUpload creates HTTP download command | [
"CreateHTTPUpload",
"creates",
"HTTP",
"download",
"command"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/http.go#L69-L114 | train |
gravitational/teleport | lib/sshutils/scp/http.go | CreateHTTPDownload | func CreateHTTPDownload(req HTTPTransferRequest) (Command, error) {
_, filename, err := req.parseRemoteLocation()
if err != nil {
return nil, trace.Wrap(err)
}
flags := Flags{
Target: []string{filename},
}
cfg := Config{
Flags: flags,
User: req.User,
ProgressWriter: req.Progress,
... | go | func CreateHTTPDownload(req HTTPTransferRequest) (Command, error) {
_, filename, err := req.parseRemoteLocation()
if err != nil {
return nil, trace.Wrap(err)
}
flags := Flags{
Target: []string{filename},
}
cfg := Config{
Flags: flags,
User: req.User,
ProgressWriter: req.Progress,
... | [
"func",
"CreateHTTPDownload",
"(",
"req",
"HTTPTransferRequest",
")",
"(",
"Command",
",",
"error",
")",
"{",
"_",
",",
"filename",
",",
"err",
":=",
"req",
".",
"parseRemoteLocation",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
... | // CreateHTTPDownload creates HTTP upload command | [
"CreateHTTPDownload",
"creates",
"HTTP",
"upload",
"command"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/http.go#L117-L143 | train |
gravitational/teleport | lib/sshutils/scp/http.go | MkDir | func (l *httpFileSystem) MkDir(path string, mode int) error {
return trace.BadParameter("directories are not supported in http file transfer")
} | go | func (l *httpFileSystem) MkDir(path string, mode int) error {
return trace.BadParameter("directories are not supported in http file transfer")
} | [
"func",
"(",
"l",
"*",
"httpFileSystem",
")",
"MkDir",
"(",
"path",
"string",
",",
"mode",
"int",
")",
"error",
"{",
"return",
"trace",
".",
"BadParameter",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // MkDir creates a directory. This method is not implemented as creating directories
// is not supported during HTTP downloads. | [
"MkDir",
"creates",
"a",
"directory",
".",
"This",
"method",
"is",
"not",
"implemented",
"as",
"creating",
"directories",
"is",
"not",
"supported",
"during",
"HTTP",
"downloads",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/http.go#L161-L163 | train |
gravitational/teleport | lib/sshutils/scp/http.go | OpenFile | func (l *httpFileSystem) OpenFile(filePath string) (io.ReadCloser, error) {
if l.reader == nil {
return nil, trace.BadParameter("missing reader")
}
return l.reader, nil
} | go | func (l *httpFileSystem) OpenFile(filePath string) (io.ReadCloser, error) {
if l.reader == nil {
return nil, trace.BadParameter("missing reader")
}
return l.reader, nil
} | [
"func",
"(",
"l",
"*",
"httpFileSystem",
")",
"OpenFile",
"(",
"filePath",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"if",
"l",
".",
"reader",
"==",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"BadParameter",
"(",
"\"",... | // OpenFile returns file reader | [
"OpenFile",
"returns",
"file",
"reader"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/http.go#L172-L178 | train |
gravitational/teleport | lib/sshutils/scp/http.go | CreateFile | func (l *httpFileSystem) CreateFile(filePath string, length uint64) (io.WriteCloser, error) {
_, filename := filepath.Split(filePath)
contentLength := strconv.FormatUint(length, 10)
header := l.writer.Header()
httplib.SetNoCacheHeaders(header)
httplib.SetNoSniff(header)
header.Set("Content-Length", contentLength... | go | func (l *httpFileSystem) CreateFile(filePath string, length uint64) (io.WriteCloser, error) {
_, filename := filepath.Split(filePath)
contentLength := strconv.FormatUint(length, 10)
header := l.writer.Header()
httplib.SetNoCacheHeaders(header)
httplib.SetNoSniff(header)
header.Set("Content-Length", contentLength... | [
"func",
"(",
"l",
"*",
"httpFileSystem",
")",
"CreateFile",
"(",
"filePath",
"string",
",",
"length",
"uint64",
")",
"(",
"io",
".",
"WriteCloser",
",",
"error",
")",
"{",
"_",
",",
"filename",
":=",
"filepath",
".",
"Split",
"(",
"filePath",
")",
"\n"... | // CreateFile sets proper HTTP headers and returns HTTP writer to stream incoming
// file content | [
"CreateFile",
"sets",
"proper",
"HTTP",
"headers",
"and",
"returns",
"HTTP",
"writer",
"to",
"stream",
"incoming",
"file",
"content"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/http.go#L182-L195 | train |
gravitational/teleport | lib/sshutils/scp/http.go | GetFileInfo | func (l *httpFileSystem) GetFileInfo(filePath string) (FileInfo, error) {
return &httpFileInfo{
name: l.fileName,
path: l.fileName,
size: l.fileSize,
}, nil
} | go | func (l *httpFileSystem) GetFileInfo(filePath string) (FileInfo, error) {
return &httpFileInfo{
name: l.fileName,
path: l.fileName,
size: l.fileSize,
}, nil
} | [
"func",
"(",
"l",
"*",
"httpFileSystem",
")",
"GetFileInfo",
"(",
"filePath",
"string",
")",
"(",
"FileInfo",
",",
"error",
")",
"{",
"return",
"&",
"httpFileInfo",
"{",
"name",
":",
"l",
".",
"fileName",
",",
"path",
":",
"l",
".",
"fileName",
",",
... | // GetFileInfo returns file information | [
"GetFileInfo",
"returns",
"file",
"information"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/sshutils/scp/http.go#L198-L204 | train |
gravitational/teleport | lib/utils/writer.go | Write | func (w *BroadcastWriter) Write(p []byte) (n int, err error) {
for _, writer := range w.writers {
n, err = writer.Write(p)
if err != nil {
return
}
if n != len(p) {
err = io.ErrShortWrite
return
}
}
return len(p), nil
} | go | func (w *BroadcastWriter) Write(p []byte) (n int, err error) {
for _, writer := range w.writers {
n, err = writer.Write(p)
if err != nil {
return
}
if n != len(p) {
err = io.ErrShortWrite
return
}
}
return len(p), nil
} | [
"func",
"(",
"w",
"*",
"BroadcastWriter",
")",
"Write",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"for",
"_",
",",
"writer",
":=",
"range",
"w",
".",
"writers",
"{",
"n",
",",
"err",
"=",
"writer",
".",
... | // Write multiplexes the input to multiple sub-writers. If any of the write
// fails, it won't attempt to write to other writers | [
"Write",
"multiplexes",
"the",
"input",
"to",
"multiple",
"sub",
"-",
"writers",
".",
"If",
"any",
"of",
"the",
"write",
"fails",
"it",
"won",
"t",
"attempt",
"to",
"write",
"to",
"other",
"writers"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/writer.go#L37-L49 | train |
gravitational/teleport | lib/backend/memory/memory.go | New | func New(cfg Config) (*Memory, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
ctx, cancel := context.WithCancel(cfg.Context)
buf, err := backend.NewCircularBuffer(ctx, cfg.BufferSize)
if err != nil {
cancel()
return nil, trace.Wrap(err)
}
m := &Memory{
Mutex: &sy... | go | func New(cfg Config) (*Memory, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
ctx, cancel := context.WithCancel(cfg.Context)
buf, err := backend.NewCircularBuffer(ctx, cfg.BufferSize)
if err != nil {
cancel()
return nil, trace.Wrap(err)
}
m := &Memory{
Mutex: &sy... | [
"func",
"New",
"(",
"cfg",
"Config",
")",
"(",
"*",
"Memory",
",",
"error",
")",
"{",
"if",
"err",
":=",
"cfg",
".",
"CheckAndSetDefaults",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"Wrap",
"(",
"err",
")",
"\n",... | // New creates a new memory backend | [
"New",
"creates",
"a",
"new",
"memory",
"backend"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/memory/memory.go#L83-L106 | train |
gravitational/teleport | lib/backend/memory/memory.go | Close | func (m *Memory) Close() error {
m.cancel()
m.Lock()
defer m.Unlock()
m.buf.Close()
return nil
} | go | func (m *Memory) Close() error {
m.cancel()
m.Lock()
defer m.Unlock()
m.buf.Close()
return nil
} | [
"func",
"(",
"m",
"*",
"Memory",
")",
"Close",
"(",
")",
"error",
"{",
"m",
".",
"cancel",
"(",
")",
"\n",
"m",
".",
"Lock",
"(",
")",
"\n",
"defer",
"m",
".",
"Unlock",
"(",
")",
"\n",
"m",
".",
"buf",
".",
"Close",
"(",
")",
"\n",
"return... | // Close closes memory backend | [
"Close",
"closes",
"memory",
"backend"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/memory/memory.go#L128-L134 | train |
gravitational/teleport | lib/backend/memory/memory.go | Update | func (m *Memory) Update(ctx context.Context, i backend.Item) (*backend.Lease, error) {
if len(i.Key) == 0 {
return nil, trace.BadParameter("missing parameter key")
}
m.Lock()
defer m.Unlock()
m.removeExpired()
if m.tree.Get(&btreeItem{Item: i}) == nil {
return nil, trace.NotFound("key %q is not found", string... | go | func (m *Memory) Update(ctx context.Context, i backend.Item) (*backend.Lease, error) {
if len(i.Key) == 0 {
return nil, trace.BadParameter("missing parameter key")
}
m.Lock()
defer m.Unlock()
m.removeExpired()
if m.tree.Get(&btreeItem{Item: i}) == nil {
return nil, trace.NotFound("key %q is not found", string... | [
"func",
"(",
"m",
"*",
"Memory",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"i",
"backend",
".",
"Item",
")",
"(",
"*",
"backend",
".",
"Lease",
",",
"error",
")",
"{",
"if",
"len",
"(",
"i",
".",
"Key",
")",
"==",
"0",
"{",
"... | // Update updates item if it exists, or returns NotFound error | [
"Update",
"updates",
"item",
"if",
"it",
"exists",
"or",
"returns",
"NotFound",
"error"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/memory/memory.go#L182-L204 | train |
gravitational/teleport | lib/backend/memory/memory.go | CompareAndSwap | func (m *Memory) CompareAndSwap(ctx context.Context, expected backend.Item, replaceWith backend.Item) (*backend.Lease, error) {
if len(expected.Key) == 0 {
return nil, trace.BadParameter("missing parameter Key")
}
if len(replaceWith.Key) == 0 {
return nil, trace.BadParameter("missing parameter Key")
}
if bytes... | go | func (m *Memory) CompareAndSwap(ctx context.Context, expected backend.Item, replaceWith backend.Item) (*backend.Lease, error) {
if len(expected.Key) == 0 {
return nil, trace.BadParameter("missing parameter Key")
}
if len(replaceWith.Key) == 0 {
return nil, trace.BadParameter("missing parameter Key")
}
if bytes... | [
"func",
"(",
"m",
"*",
"Memory",
")",
"CompareAndSwap",
"(",
"ctx",
"context",
".",
"Context",
",",
"expected",
"backend",
".",
"Item",
",",
"replaceWith",
"backend",
".",
"Item",
")",
"(",
"*",
"backend",
".",
"Lease",
",",
"error",
")",
"{",
"if",
... | // CompareAndSwap compares item with existing item and replaces it with replaceWith item | [
"CompareAndSwap",
"compares",
"item",
"with",
"existing",
"item",
"and",
"replaces",
"it",
"with",
"replaceWith",
"item"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/memory/memory.go#L344-L374 | train |
gravitational/teleport | lib/backend/memory/memory.go | removeExpired | func (m *Memory) removeExpired() int {
removed := 0
now := m.Clock().Now().UTC()
for {
if len(*m.heap) == 0 {
break
}
item := m.heap.PeekEl()
if now.Before(item.Expires) {
break
}
m.heap.PopEl()
m.tree.Delete(item)
m.Debugf("Removed expired %v %v item.", string(item.Key), item.Expires)
remove... | go | func (m *Memory) removeExpired() int {
removed := 0
now := m.Clock().Now().UTC()
for {
if len(*m.heap) == 0 {
break
}
item := m.heap.PeekEl()
if now.Before(item.Expires) {
break
}
m.heap.PopEl()
m.tree.Delete(item)
m.Debugf("Removed expired %v %v item.", string(item.Key), item.Expires)
remove... | [
"func",
"(",
"m",
"*",
"Memory",
")",
"removeExpired",
"(",
")",
"int",
"{",
"removed",
":=",
"0",
"\n",
"now",
":=",
"m",
".",
"Clock",
"(",
")",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
"\n",
"for",
"{",
"if",
"len",
"(",
"*",
"m",
"."... | // removeExpired makes a pass through map and removes expired elements
// returns the number of expired elements removed | [
"removeExpired",
"makes",
"a",
"pass",
"through",
"map",
"and",
"removes",
"expired",
"elements",
"returns",
"the",
"number",
"of",
"expired",
"elements",
"removed"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/memory/memory.go#L412-L432 | train |
gravitational/teleport | lib/session/session.go | Set | func (s *ID) Set(v string) error {
id, err := ParseID(v)
if err != nil {
return trace.Wrap(err)
}
*s = *id
return nil
} | go | func (s *ID) Set(v string) error {
id, err := ParseID(v)
if err != nil {
return trace.Wrap(err)
}
*s = *id
return nil
} | [
"func",
"(",
"s",
"*",
"ID",
")",
"Set",
"(",
"v",
"string",
")",
"error",
"{",
"id",
",",
"err",
":=",
"ParseID",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"trace",
".",
"Wrap",
"(",
"err",
")",
"\n",
"}",
"\n",
"*",
"s... | // Set makes ID cli compatible, lets to set value from string | [
"Set",
"makes",
"ID",
"cli",
"compatible",
"lets",
"to",
"set",
"value",
"from",
"string"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L58-L65 | train |
gravitational/teleport | lib/session/session.go | Time | func (s *ID) Time() time.Time {
tm, ok := s.UUID().Time()
if !ok {
return time.Time{}
}
sec, nsec := tm.UnixTime()
return time.Unix(sec, nsec).UTC()
} | go | func (s *ID) Time() time.Time {
tm, ok := s.UUID().Time()
if !ok {
return time.Time{}
}
sec, nsec := tm.UnixTime()
return time.Unix(sec, nsec).UTC()
} | [
"func",
"(",
"s",
"*",
"ID",
")",
"Time",
"(",
")",
"time",
".",
"Time",
"{",
"tm",
",",
"ok",
":=",
"s",
".",
"UUID",
"(",
")",
".",
"Time",
"(",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
"\n",
"}",
"\n",
... | // Time returns time portion of this ID | [
"Time",
"returns",
"time",
"portion",
"of",
"this",
"ID"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L68-L75 | train |
gravitational/teleport | lib/session/session.go | Check | func (s *ID) Check() error {
_, err := ParseID(string(*s))
return trace.Wrap(err)
} | go | func (s *ID) Check() error {
_, err := ParseID(string(*s))
return trace.Wrap(err)
} | [
"func",
"(",
"s",
"*",
"ID",
")",
"Check",
"(",
")",
"error",
"{",
"_",
",",
"err",
":=",
"ParseID",
"(",
"string",
"(",
"*",
"s",
")",
")",
"\n",
"return",
"trace",
".",
"Wrap",
"(",
"err",
")",
"\n",
"}"
] | // Check checks if it's a valid UUID | [
"Check",
"checks",
"if",
"it",
"s",
"a",
"valid",
"UUID"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L78-L81 | train |
gravitational/teleport | lib/session/session.go | ParseID | func ParseID(id string) (*ID, error) {
val := uuid.Parse(id)
if val == nil {
return nil, trace.BadParameter("'%v' is not a valid Time UUID v1", id)
}
if ver, ok := val.Version(); !ok || ver != 1 {
return nil, trace.BadParameter("'%v' is not a be a valid Time UUID v1", id)
}
uid := ID(id)
return &uid, nil
} | go | func ParseID(id string) (*ID, error) {
val := uuid.Parse(id)
if val == nil {
return nil, trace.BadParameter("'%v' is not a valid Time UUID v1", id)
}
if ver, ok := val.Version(); !ok || ver != 1 {
return nil, trace.BadParameter("'%v' is not a be a valid Time UUID v1", id)
}
uid := ID(id)
return &uid, nil
} | [
"func",
"ParseID",
"(",
"id",
"string",
")",
"(",
"*",
"ID",
",",
"error",
")",
"{",
"val",
":=",
"uuid",
".",
"Parse",
"(",
"id",
")",
"\n",
"if",
"val",
"==",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"BadParameter",
"(",
"\"",
"\"",
",... | // ParseID parses ID and checks if it's correct | [
"ParseID",
"parses",
"ID",
"and",
"checks",
"if",
"it",
"s",
"correct"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L84-L94 | train |
gravitational/teleport | lib/session/session.go | RemoveParty | func (s *Session) RemoveParty(pid ID) bool {
for i := range s.Parties {
if s.Parties[i].ID == pid {
s.Parties = append(s.Parties[:i], s.Parties[i+1:]...)
return true
}
}
return false
} | go | func (s *Session) RemoveParty(pid ID) bool {
for i := range s.Parties {
if s.Parties[i].ID == pid {
s.Parties = append(s.Parties[:i], s.Parties[i+1:]...)
return true
}
}
return false
} | [
"func",
"(",
"s",
"*",
"Session",
")",
"RemoveParty",
"(",
"pid",
"ID",
")",
"bool",
"{",
"for",
"i",
":=",
"range",
"s",
".",
"Parties",
"{",
"if",
"s",
".",
"Parties",
"[",
"i",
"]",
".",
"ID",
"==",
"pid",
"{",
"s",
".",
"Parties",
"=",
"a... | // RemoveParty helper allows to remove a party by it's ID from the
// session's list. Returns 'false' if pid couldn't be found | [
"RemoveParty",
"helper",
"allows",
"to",
"remove",
"a",
"party",
"by",
"it",
"s",
"ID",
"from",
"the",
"session",
"s",
"list",
".",
"Returns",
"false",
"if",
"pid",
"couldn",
"t",
"be",
"found"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L128-L136 | train |
gravitational/teleport | lib/session/session.go | String | func (p *Party) String() string {
return fmt.Sprintf(
"party(id=%v, remote=%v, user=%v, server=%v, last_active=%v)",
p.ID, p.RemoteAddr, p.User, p.ServerID, p.LastActive,
)
} | go | func (p *Party) String() string {
return fmt.Sprintf(
"party(id=%v, remote=%v, user=%v, server=%v, last_active=%v)",
p.ID, p.RemoteAddr, p.User, p.ServerID, p.LastActive,
)
} | [
"func",
"(",
"p",
"*",
"Party",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"ID",
",",
"p",
".",
"RemoteAddr",
",",
"p",
".",
"User",
",",
"p",
".",
"ServerID",
",",
"p",
".",
"Last... | // String returns debug friendly representation | [
"String",
"returns",
"debug",
"friendly",
"representation"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L154-L159 | train |
gravitational/teleport | lib/session/session.go | String | func (p *TerminalParams) String() string {
return fmt.Sprintf("TerminalParams(w=%v, h=%v)", p.W, p.H)
} | go | func (p *TerminalParams) String() string {
return fmt.Sprintf("TerminalParams(w=%v, h=%v)", p.W, p.H)
} | [
"func",
"(",
"p",
"*",
"TerminalParams",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"W",
",",
"p",
".",
"H",
")",
"\n",
"}"
] | // String returns debug friendly representation of terminal | [
"String",
"returns",
"debug",
"friendly",
"representation",
"of",
"terminal"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L199-L201 | train |
gravitational/teleport | lib/session/session.go | Winsize | func (p *TerminalParams) Winsize() *term.Winsize {
return &term.Winsize{
Width: uint16(p.W),
Height: uint16(p.H),
}
} | go | func (p *TerminalParams) Winsize() *term.Winsize {
return &term.Winsize{
Width: uint16(p.W),
Height: uint16(p.H),
}
} | [
"func",
"(",
"p",
"*",
"TerminalParams",
")",
"Winsize",
"(",
")",
"*",
"term",
".",
"Winsize",
"{",
"return",
"&",
"term",
".",
"Winsize",
"{",
"Width",
":",
"uint16",
"(",
"p",
".",
"W",
")",
",",
"Height",
":",
"uint16",
"(",
"p",
".",
"H",
... | // Winsize returns low-level parameters for changing PTY | [
"Winsize",
"returns",
"low",
"-",
"level",
"parameters",
"for",
"changing",
"PTY"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L204-L209 | train |
gravitational/teleport | lib/session/session.go | Check | func (u *UpdateRequest) Check() error {
if err := u.ID.Check(); err != nil {
return trace.Wrap(err)
}
if u.Namespace == "" {
return trace.BadParameter("missing parameter Namespace")
}
if u.TerminalParams != nil {
_, err := NewTerminalParamsFromInt(u.TerminalParams.W, u.TerminalParams.H)
if err != nil {
... | go | func (u *UpdateRequest) Check() error {
if err := u.ID.Check(); err != nil {
return trace.Wrap(err)
}
if u.Namespace == "" {
return trace.BadParameter("missing parameter Namespace")
}
if u.TerminalParams != nil {
_, err := NewTerminalParamsFromInt(u.TerminalParams.W, u.TerminalParams.H)
if err != nil {
... | [
"func",
"(",
"u",
"*",
"UpdateRequest",
")",
"Check",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"u",
".",
"ID",
".",
"Check",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"trace",
".",
"Wrap",
"(",
"err",
")",
"\n",
"}",
"\n",
"if",
"u"... | // Check returns nil if request is valid, error otherwize | [
"Check",
"returns",
"nil",
"if",
"request",
"is",
"valid",
"error",
"otherwize"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L230-L244 | train |
gravitational/teleport | lib/session/session.go | New | func New(bk backend.Backend) (Service, error) {
s := &server{
bk: bk,
clock: clockwork.NewRealClock(),
}
if s.activeSessionTTL == 0 {
s.activeSessionTTL = defaults.ActiveSessionTTL
}
return s, nil
} | go | func New(bk backend.Backend) (Service, error) {
s := &server{
bk: bk,
clock: clockwork.NewRealClock(),
}
if s.activeSessionTTL == 0 {
s.activeSessionTTL = defaults.ActiveSessionTTL
}
return s, nil
} | [
"func",
"New",
"(",
"bk",
"backend",
".",
"Backend",
")",
"(",
"Service",
",",
"error",
")",
"{",
"s",
":=",
"&",
"server",
"{",
"bk",
":",
"bk",
",",
"clock",
":",
"clockwork",
".",
"NewRealClock",
"(",
")",
",",
"}",
"\n",
"if",
"s",
".",
"ac... | // New returns new session server that uses sqlite to manage
// active sessions | [
"New",
"returns",
"new",
"session",
"server",
"that",
"uses",
"sqlite",
"to",
"manage",
"active",
"sessions"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L277-L286 | train |
gravitational/teleport | lib/session/session.go | GetSessions | func (s *server) GetSessions(namespace string) ([]Session, error) {
prefix := activePrefix(namespace)
result, err := s.bk.GetRange(context.TODO(), prefix, backend.RangeEnd(prefix), MaxSessionSliceLength)
if err != nil {
return nil, trace.Wrap(err)
}
out := make(Sessions, 0, len(result.Items))
for i := range r... | go | func (s *server) GetSessions(namespace string) ([]Session, error) {
prefix := activePrefix(namespace)
result, err := s.bk.GetRange(context.TODO(), prefix, backend.RangeEnd(prefix), MaxSessionSliceLength)
if err != nil {
return nil, trace.Wrap(err)
}
out := make(Sessions, 0, len(result.Items))
for i := range r... | [
"func",
"(",
"s",
"*",
"server",
")",
"GetSessions",
"(",
"namespace",
"string",
")",
"(",
"[",
"]",
"Session",
",",
"error",
")",
"{",
"prefix",
":=",
"activePrefix",
"(",
"namespace",
")",
"\n\n",
"result",
",",
"err",
":=",
"s",
".",
"bk",
".",
... | // GetSessions returns a list of active sessions. Returns an empty slice
// if no sessions are active | [
"GetSessions",
"returns",
"a",
"list",
"of",
"active",
"sessions",
".",
"Returns",
"an",
"empty",
"slice",
"if",
"no",
"sessions",
"are",
"active"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L298-L316 | train |
gravitational/teleport | lib/session/session.go | GetSession | func (s *server) GetSession(namespace string, id ID) (*Session, error) {
item, err := s.bk.Get(context.TODO(), activeKey(namespace, string(id)))
if err != nil {
if trace.IsNotFound(err) {
return nil, trace.NotFound("session(%v, %v) is not found", namespace, id)
}
return nil, trace.Wrap(err)
}
var sess Sess... | go | func (s *server) GetSession(namespace string, id ID) (*Session, error) {
item, err := s.bk.Get(context.TODO(), activeKey(namespace, string(id)))
if err != nil {
if trace.IsNotFound(err) {
return nil, trace.NotFound("session(%v, %v) is not found", namespace, id)
}
return nil, trace.Wrap(err)
}
var sess Sess... | [
"func",
"(",
"s",
"*",
"server",
")",
"GetSession",
"(",
"namespace",
"string",
",",
"id",
"ID",
")",
"(",
"*",
"Session",
",",
"error",
")",
"{",
"item",
",",
"err",
":=",
"s",
".",
"bk",
".",
"Get",
"(",
"context",
".",
"TODO",
"(",
")",
",",... | // GetSession returns the session by it's id. Returns NotFound if a session
// is not found | [
"GetSession",
"returns",
"the",
"session",
"by",
"it",
"s",
"id",
".",
"Returns",
"NotFound",
"if",
"a",
"session",
"is",
"not",
"found"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L341-L354 | train |
gravitational/teleport | lib/session/session.go | CreateSession | func (s *server) CreateSession(sess Session) error {
if err := sess.ID.Check(); err != nil {
return trace.Wrap(err)
}
if sess.Namespace == "" {
return trace.BadParameter("session namespace can not be empty")
}
if sess.Login == "" {
return trace.BadParameter("session login can not be empty")
}
if sess.Creat... | go | func (s *server) CreateSession(sess Session) error {
if err := sess.ID.Check(); err != nil {
return trace.Wrap(err)
}
if sess.Namespace == "" {
return trace.BadParameter("session namespace can not be empty")
}
if sess.Login == "" {
return trace.BadParameter("session login can not be empty")
}
if sess.Creat... | [
"func",
"(",
"s",
"*",
"server",
")",
"CreateSession",
"(",
"sess",
"Session",
")",
"error",
"{",
"if",
"err",
":=",
"sess",
".",
"ID",
".",
"Check",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"trace",
".",
"Wrap",
"(",
"err",
")",
"\n",
... | // CreateSession creates a new session if it does not exist, if the session
// exists the function will return AlreadyExists error
// The session will be marked as active for TTL period of time | [
"CreateSession",
"creates",
"a",
"new",
"session",
"if",
"it",
"does",
"not",
"exist",
"if",
"the",
"session",
"exists",
"the",
"function",
"will",
"return",
"AlreadyExists",
"error",
"The",
"session",
"will",
"be",
"marked",
"as",
"active",
"for",
"TTL",
"p... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L359-L394 | train |
gravitational/teleport | lib/session/session.go | UpdateSession | func (s *server) UpdateSession(req UpdateRequest) error {
if err := req.Check(); err != nil {
return trace.Wrap(err)
}
key := activeKey(req.Namespace, string(req.ID))
// Try several times, then give up
for i := 0; i < sessionUpdateAttempts; i++ {
item, err := s.bk.Get(context.TODO(), key)
if err != nil {
... | go | func (s *server) UpdateSession(req UpdateRequest) error {
if err := req.Check(); err != nil {
return trace.Wrap(err)
}
key := activeKey(req.Namespace, string(req.ID))
// Try several times, then give up
for i := 0; i < sessionUpdateAttempts; i++ {
item, err := s.bk.Get(context.TODO(), key)
if err != nil {
... | [
"func",
"(",
"s",
"*",
"server",
")",
"UpdateSession",
"(",
"req",
"UpdateRequest",
")",
"error",
"{",
"if",
"err",
":=",
"req",
".",
"Check",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"trace",
".",
"Wrap",
"(",
"err",
")",
"\n",
"}",
"\n... | // UpdateSession updates session parameters - can mark it as inactive and update it's terminal parameters | [
"UpdateSession",
"updates",
"session",
"parameters",
"-",
"can",
"mark",
"it",
"as",
"inactive",
"and",
"update",
"it",
"s",
"terminal",
"parameters"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L402-L452 | train |
gravitational/teleport | lib/session/session.go | GetSession | func (d *discardSessionServer) GetSession(namespace string, id ID) (*Session, error) {
return &Session{}, nil
} | go | func (d *discardSessionServer) GetSession(namespace string, id ID) (*Session, error) {
return &Session{}, nil
} | [
"func",
"(",
"d",
"*",
"discardSessionServer",
")",
"GetSession",
"(",
"namespace",
"string",
",",
"id",
"ID",
")",
"(",
"*",
"Session",
",",
"error",
")",
"{",
"return",
"&",
"Session",
"{",
"}",
",",
"nil",
"\n",
"}"
] | // GetSession always returns a zero session. | [
"GetSession",
"always",
"returns",
"a",
"zero",
"session",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L471-L473 | train |
gravitational/teleport | lib/session/session.go | NewTerminalParamsFromUint32 | func NewTerminalParamsFromUint32(w uint32, h uint32) (*TerminalParams, error) {
if w > maxSize || w < minSize {
return nil, trace.BadParameter("bad width")
}
if h > maxSize || h < minSize {
return nil, trace.BadParameter("bad height")
}
return &TerminalParams{W: int(w), H: int(h)}, nil
} | go | func NewTerminalParamsFromUint32(w uint32, h uint32) (*TerminalParams, error) {
if w > maxSize || w < minSize {
return nil, trace.BadParameter("bad width")
}
if h > maxSize || h < minSize {
return nil, trace.BadParameter("bad height")
}
return &TerminalParams{W: int(w), H: int(h)}, nil
} | [
"func",
"NewTerminalParamsFromUint32",
"(",
"w",
"uint32",
",",
"h",
"uint32",
")",
"(",
"*",
"TerminalParams",
",",
"error",
")",
"{",
"if",
"w",
">",
"maxSize",
"||",
"w",
"<",
"minSize",
"{",
"return",
"nil",
",",
"trace",
".",
"BadParameter",
"(",
... | // NewTerminalParamsFromUint32 returns new terminal parameters from uint32 width and height | [
"NewTerminalParamsFromUint32",
"returns",
"new",
"terminal",
"parameters",
"from",
"uint32",
"width",
"and",
"height"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/session/session.go#L486-L494 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | isAuditedAtProxy | func (s *Server) isAuditedAtProxy() bool {
// always be safe, better to double record than not record at all
clusterConfig, err := s.GetAccessPoint().GetClusterConfig()
if err != nil {
return false
}
isRecordAtProxy := clusterConfig.GetSessionRecording() == services.RecordAtProxy
isTeleportNode := s.Component(... | go | func (s *Server) isAuditedAtProxy() bool {
// always be safe, better to double record than not record at all
clusterConfig, err := s.GetAccessPoint().GetClusterConfig()
if err != nil {
return false
}
isRecordAtProxy := clusterConfig.GetSessionRecording() == services.RecordAtProxy
isTeleportNode := s.Component(... | [
"func",
"(",
"s",
"*",
"Server",
")",
"isAuditedAtProxy",
"(",
")",
"bool",
"{",
"// always be safe, better to double record than not record at all",
"clusterConfig",
",",
"err",
":=",
"s",
".",
"GetAccessPoint",
"(",
")",
".",
"GetClusterConfig",
"(",
")",
"\n",
... | // isAuditedAtProxy returns true if sessions are being recorded at the proxy
// and this is a Teleport node. | [
"isAuditedAtProxy",
"returns",
"true",
"if",
"sessions",
"are",
"being",
"recorded",
"at",
"the",
"proxy",
"and",
"this",
"is",
"a",
"Teleport",
"node",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L188-L202 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | Shutdown | func (s *Server) Shutdown(ctx context.Context) error {
// wait until connections drain off
err := s.srv.Shutdown(ctx)
s.cancel()
s.reg.Close()
if s.heartbeat != nil {
if err := s.heartbeat.Close(); err != nil {
s.Warningf("Failed to close heartbeat: %v.", err)
}
s.heartbeat = nil
}
return err
} | go | func (s *Server) Shutdown(ctx context.Context) error {
// wait until connections drain off
err := s.srv.Shutdown(ctx)
s.cancel()
s.reg.Close()
if s.heartbeat != nil {
if err := s.heartbeat.Close(); err != nil {
s.Warningf("Failed to close heartbeat: %v.", err)
}
s.heartbeat = nil
}
return err
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Shutdown",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"// wait until connections drain off",
"err",
":=",
"s",
".",
"srv",
".",
"Shutdown",
"(",
"ctx",
")",
"\n",
"s",
".",
"cancel",
"(",
")",
"\n",... | // Shutdown performs graceful shutdown | [
"Shutdown",
"performs",
"graceful",
"shutdown"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L221-L233 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | Start | func (s *Server) Start() error {
if len(s.getCommandLabels()) > 0 {
s.updateLabels()
}
go s.heartbeat.Run()
// If the server requested connections to it arrive over a reverse tunnel,
// don't call Start() which listens on a socket, return right away.
if s.useTunnel {
return nil
}
return s.srv.Start()
} | go | func (s *Server) Start() error {
if len(s.getCommandLabels()) > 0 {
s.updateLabels()
}
go s.heartbeat.Run()
// If the server requested connections to it arrive over a reverse tunnel,
// don't call Start() which listens on a socket, return right away.
if s.useTunnel {
return nil
}
return s.srv.Start()
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Start",
"(",
")",
"error",
"{",
"if",
"len",
"(",
"s",
".",
"getCommandLabels",
"(",
")",
")",
">",
"0",
"{",
"s",
".",
"updateLabels",
"(",
")",
"\n",
"}",
"\n",
"go",
"s",
".",
"heartbeat",
".",
"Run",
... | // Start starts server | [
"Start",
"starts",
"server"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L236-L248 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | Serve | func (s *Server) Serve(l net.Listener) error {
if len(s.getCommandLabels()) > 0 {
s.updateLabels()
}
go s.heartbeat.Run()
return s.srv.Serve(l)
} | go | func (s *Server) Serve(l net.Listener) error {
if len(s.getCommandLabels()) > 0 {
s.updateLabels()
}
go s.heartbeat.Run()
return s.srv.Serve(l)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"Serve",
"(",
"l",
"net",
".",
"Listener",
")",
"error",
"{",
"if",
"len",
"(",
"s",
".",
"getCommandLabels",
"(",
")",
")",
">",
"0",
"{",
"s",
".",
"updateLabels",
"(",
")",
"\n",
"}",
"\n",
"go",
"s",
... | // Serve servers service on started listener | [
"Serve",
"servers",
"service",
"on",
"started",
"listener"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L251-L257 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | HandleConnection | func (s *Server) HandleConnection(conn net.Conn) {
s.srv.HandleConnection(conn)
} | go | func (s *Server) HandleConnection(conn net.Conn) {
s.srv.HandleConnection(conn)
} | [
"func",
"(",
"s",
"*",
"Server",
")",
"HandleConnection",
"(",
"conn",
"net",
".",
"Conn",
")",
"{",
"s",
".",
"srv",
".",
"HandleConnection",
"(",
"conn",
")",
"\n",
"}"
] | // HandleConnection is called after a connection has been accepted and starts
// to perform the SSH handshake immediately. | [
"HandleConnection",
"is",
"called",
"after",
"a",
"connection",
"has",
"been",
"accepted",
"and",
"starts",
"to",
"perform",
"the",
"SSH",
"handshake",
"immediately",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L266-L268 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetRotationGetter | func SetRotationGetter(getter RotationGetter) ServerOption {
return func(s *Server) error {
s.getRotation = getter
return nil
}
} | go | func SetRotationGetter(getter RotationGetter) ServerOption {
return func(s *Server) error {
s.getRotation = getter
return nil
}
} | [
"func",
"SetRotationGetter",
"(",
"getter",
"RotationGetter",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"getRotation",
"=",
"getter",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetRotationGetter sets rotation state getter | [
"SetRotationGetter",
"sets",
"rotation",
"state",
"getter"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L274-L279 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetShell | func SetShell(shell string) ServerOption {
return func(s *Server) error {
s.shell = shell
return nil
}
} | go | func SetShell(shell string) ServerOption {
return func(s *Server) error {
s.shell = shell
return nil
}
} | [
"func",
"SetShell",
"(",
"shell",
"string",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"shell",
"=",
"shell",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetShell sets default shell that will be executed for interactive
// sessions | [
"SetShell",
"sets",
"default",
"shell",
"that",
"will",
"be",
"executed",
"for",
"interactive",
"sessions"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L283-L288 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetSessionServer | func SetSessionServer(sessionServer rsession.Service) ServerOption {
return func(s *Server) error {
s.sessionServer = sessionServer
return nil
}
} | go | func SetSessionServer(sessionServer rsession.Service) ServerOption {
return func(s *Server) error {
s.sessionServer = sessionServer
return nil
}
} | [
"func",
"SetSessionServer",
"(",
"sessionServer",
"rsession",
".",
"Service",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"sessionServer",
"=",
"sessionServer",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"... | // SetSessionServer represents realtime session registry server | [
"SetSessionServer",
"represents",
"realtime",
"session",
"registry",
"server"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L291-L296 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetProxyMode | func SetProxyMode(tsrv reversetunnel.Server) ServerOption {
return func(s *Server) error {
// always set proxy mode to true,
// because in some tests reverse tunnel is disabled,
// but proxy is still used without it.
s.proxyMode = true
s.proxyTun = tsrv
return nil
}
} | go | func SetProxyMode(tsrv reversetunnel.Server) ServerOption {
return func(s *Server) error {
// always set proxy mode to true,
// because in some tests reverse tunnel is disabled,
// but proxy is still used without it.
s.proxyMode = true
s.proxyTun = tsrv
return nil
}
} | [
"func",
"SetProxyMode",
"(",
"tsrv",
"reversetunnel",
".",
"Server",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"// always set proxy mode to true,",
"// because in some tests reverse tunnel is disabled,",
"// but proxy is still u... | // SetProxyMode starts this server in SSH proxying mode | [
"SetProxyMode",
"starts",
"this",
"server",
"in",
"SSH",
"proxying",
"mode"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L299-L308 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetLabels | func SetLabels(labels map[string]string,
cmdLabels services.CommandLabels) ServerOption {
return func(s *Server) error {
// make sure to clone labels to avoid
// concurrent writes to the map during reloads
cmdLabels = cmdLabels.Clone()
for name, label := range cmdLabels {
if label.GetPeriod() < time.Second... | go | func SetLabels(labels map[string]string,
cmdLabels services.CommandLabels) ServerOption {
return func(s *Server) error {
// make sure to clone labels to avoid
// concurrent writes to the map during reloads
cmdLabels = cmdLabels.Clone()
for name, label := range cmdLabels {
if label.GetPeriod() < time.Second... | [
"func",
"SetLabels",
"(",
"labels",
"map",
"[",
"string",
"]",
"string",
",",
"cmdLabels",
"services",
".",
"CommandLabels",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"// make sure to clone labels to avoid",
"// conc... | // SetLabels sets dynamic and static labels that server will report to the
// auth servers | [
"SetLabels",
"sets",
"dynamic",
"and",
"static",
"labels",
"that",
"server",
"will",
"report",
"to",
"the",
"auth",
"servers"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L312-L329 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetAuditLog | func SetAuditLog(alog events.IAuditLog) ServerOption {
return func(s *Server) error {
s.alog = alog
return nil
}
} | go | func SetAuditLog(alog events.IAuditLog) ServerOption {
return func(s *Server) error {
s.alog = alog
return nil
}
} | [
"func",
"SetAuditLog",
"(",
"alog",
"events",
".",
"IAuditLog",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"alog",
"=",
"alog",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetAuditLog assigns an audit log interfaces to this server | [
"SetAuditLog",
"assigns",
"an",
"audit",
"log",
"interfaces",
"to",
"this",
"server"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L340-L345 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetUUID | func SetUUID(uuid string) ServerOption {
return func(s *Server) error {
s.uuid = uuid
return nil
}
} | go | func SetUUID(uuid string) ServerOption {
return func(s *Server) error {
s.uuid = uuid
return nil
}
} | [
"func",
"SetUUID",
"(",
"uuid",
"string",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"uuid",
"=",
"uuid",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // SetUUID sets server unique ID | [
"SetUUID",
"sets",
"server",
"unique",
"ID"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L348-L353 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | SetPermitUserEnvironment | func SetPermitUserEnvironment(permitUserEnvironment bool) ServerOption {
return func(s *Server) error {
s.permitUserEnvironment = permitUserEnvironment
return nil
}
} | go | func SetPermitUserEnvironment(permitUserEnvironment bool) ServerOption {
return func(s *Server) error {
s.permitUserEnvironment = permitUserEnvironment
return nil
}
} | [
"func",
"SetPermitUserEnvironment",
"(",
"permitUserEnvironment",
"bool",
")",
"ServerOption",
"{",
"return",
"func",
"(",
"s",
"*",
"Server",
")",
"error",
"{",
"s",
".",
"permitUserEnvironment",
"=",
"permitUserEnvironment",
"\n",
"return",
"nil",
"\n",
"}",
"... | // SetPermitUserEnvironment allows you to set the value of permitUserEnvironment. | [
"SetPermitUserEnvironment",
"allows",
"you",
"to",
"set",
"the",
"value",
"of",
"permitUserEnvironment",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L363-L368 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | serveAgent | func (s *Server) serveAgent(ctx *srv.ServerContext) error {
// gather information about user and process. this will be used to set the
// socket path and permissions
systemUser, err := user.Lookup(ctx.Identity.Login)
if err != nil {
return trace.ConvertSystemError(err)
}
uid, err := strconv.Atoi(systemUser.Uid)... | go | func (s *Server) serveAgent(ctx *srv.ServerContext) error {
// gather information about user and process. this will be used to set the
// socket path and permissions
systemUser, err := user.Lookup(ctx.Identity.Login)
if err != nil {
return trace.ConvertSystemError(err)
}
uid, err := strconv.Atoi(systemUser.Uid)... | [
"func",
"(",
"s",
"*",
"Server",
")",
"serveAgent",
"(",
"ctx",
"*",
"srv",
".",
"ServerContext",
")",
"error",
"{",
"// gather information about user and process. this will be used to set the",
"// socket path and permissions",
"systemUser",
",",
"err",
":=",
"user",
"... | // serveAgent will build the a sock path for this user and serve an SSH agent on unix socket. | [
"serveAgent",
"will",
"build",
"the",
"a",
"sock",
"path",
"for",
"this",
"user",
"and",
"serve",
"an",
"SSH",
"agent",
"on",
"unix",
"socket",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L683-L728 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | EmitAuditEvent | func (s *Server) EmitAuditEvent(event events.Event, fields events.EventFields) {
log.Debugf("server.EmitAuditEvent(%v)", event.Name)
alog := s.alog
if alog != nil {
// record the event time with ms precision
fields[events.EventTime] = s.clock.Now().In(time.UTC).Round(time.Millisecond)
if err := alog.EmitAuditE... | go | func (s *Server) EmitAuditEvent(event events.Event, fields events.EventFields) {
log.Debugf("server.EmitAuditEvent(%v)", event.Name)
alog := s.alog
if alog != nil {
// record the event time with ms precision
fields[events.EventTime] = s.clock.Now().In(time.UTC).Round(time.Millisecond)
if err := alog.EmitAuditE... | [
"func",
"(",
"s",
"*",
"Server",
")",
"EmitAuditEvent",
"(",
"event",
"events",
".",
"Event",
",",
"fields",
"events",
".",
"EventFields",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"event",
".",
"Name",
")",
"\n",
"alog",
":=",
"s",
"."... | // EmitAuditEvent logs a given event to the audit log attached to the
// server who owns these sessions | [
"EmitAuditEvent",
"logs",
"a",
"given",
"event",
"to",
"the",
"audit",
"log",
"attached",
"to",
"the",
"server",
"who",
"owns",
"these",
"sessions"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L732-L744 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | HandleNewChan | func (s *Server) HandleNewChan(wconn net.Conn, sconn *ssh.ServerConn, nch ssh.NewChannel) {
identityContext, err := s.authHandlers.CreateIdentityContext(sconn)
if err != nil {
nch.Reject(ssh.Prohibited, fmt.Sprintf("Unable to create identity from connection: %v", err))
return
}
channelType := nch.ChannelType()... | go | func (s *Server) HandleNewChan(wconn net.Conn, sconn *ssh.ServerConn, nch ssh.NewChannel) {
identityContext, err := s.authHandlers.CreateIdentityContext(sconn)
if err != nil {
nch.Reject(ssh.Prohibited, fmt.Sprintf("Unable to create identity from connection: %v", err))
return
}
channelType := nch.ChannelType()... | [
"func",
"(",
"s",
"*",
"Server",
")",
"HandleNewChan",
"(",
"wconn",
"net",
".",
"Conn",
",",
"sconn",
"*",
"ssh",
".",
"ServerConn",
",",
"nch",
"ssh",
".",
"NewChannel",
")",
"{",
"identityContext",
",",
"err",
":=",
"s",
".",
"authHandlers",
".",
... | // HandleNewChan is called when new channel is opened | [
"HandleNewChan",
"is",
"called",
"when",
"new",
"channel",
"is",
"opened"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L768-L823 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | handleAgentForwardNode | func (s *Server) handleAgentForwardNode(req *ssh.Request, ctx *srv.ServerContext) error {
// check if the user's RBAC role allows agent forwarding
err := s.authHandlers.CheckAgentForward(ctx)
if err != nil {
return trace.Wrap(err)
}
// open a channel to the client where the client will serve an agent
authChann... | go | func (s *Server) handleAgentForwardNode(req *ssh.Request, ctx *srv.ServerContext) error {
// check if the user's RBAC role allows agent forwarding
err := s.authHandlers.CheckAgentForward(ctx)
if err != nil {
return trace.Wrap(err)
}
// open a channel to the client where the client will serve an agent
authChann... | [
"func",
"(",
"s",
"*",
"Server",
")",
"handleAgentForwardNode",
"(",
"req",
"*",
"ssh",
".",
"Request",
",",
"ctx",
"*",
"srv",
".",
"ServerContext",
")",
"error",
"{",
"// check if the user's RBAC role allows agent forwarding",
"err",
":=",
"s",
".",
"authHandl... | // handleAgentForwardNode will create a unix socket and serve the agent running
// on the client on it. | [
"handleAgentForwardNode",
"will",
"create",
"a",
"unix",
"socket",
"and",
"serve",
"the",
"agent",
"running",
"on",
"the",
"client",
"on",
"it",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L1079-L1102 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | handleKeepAlive | func (s *Server) handleKeepAlive(req *ssh.Request) {
log.Debugf("Received %q: WantReply: %v", req.Type, req.WantReply)
// only reply if the sender actually wants a response
if req.WantReply {
err := req.Reply(true, nil)
if err != nil {
log.Warnf("Unable to reply to %q request: %v", req.Type, err)
return
... | go | func (s *Server) handleKeepAlive(req *ssh.Request) {
log.Debugf("Received %q: WantReply: %v", req.Type, req.WantReply)
// only reply if the sender actually wants a response
if req.WantReply {
err := req.Reply(true, nil)
if err != nil {
log.Warnf("Unable to reply to %q request: %v", req.Type, err)
return
... | [
"func",
"(",
"s",
"*",
"Server",
")",
"handleKeepAlive",
"(",
"req",
"*",
"ssh",
".",
"Request",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"req",
".",
"Type",
",",
"req",
".",
"WantReply",
")",
"\n\n",
"// only reply if the sender actually wa... | // handleKeepAlive accepts and replies to keepalive@openssh.com requests. | [
"handleKeepAlive",
"accepts",
"and",
"replies",
"to",
"keepalive"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L1171-L1184 | train |
gravitational/teleport | lib/srv/regular/sshserver.go | handleRecordingProxy | func (s *Server) handleRecordingProxy(req *ssh.Request) {
var recordingProxy bool
log.Debugf("Global request (%v, %v) received", req.Type, req.WantReply)
if req.WantReply {
// get the cluster config, if we can't get it, reply false
clusterConfig, err := s.authService.GetClusterConfig()
if err != nil {
err... | go | func (s *Server) handleRecordingProxy(req *ssh.Request) {
var recordingProxy bool
log.Debugf("Global request (%v, %v) received", req.Type, req.WantReply)
if req.WantReply {
// get the cluster config, if we can't get it, reply false
clusterConfig, err := s.authService.GetClusterConfig()
if err != nil {
err... | [
"func",
"(",
"s",
"*",
"Server",
")",
"handleRecordingProxy",
"(",
"req",
"*",
"ssh",
".",
"Request",
")",
"{",
"var",
"recordingProxy",
"bool",
"\n\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"req",
".",
"Type",
",",
"req",
".",
"WantReply",
")"... | // handleRecordingProxy responds to global out-of-band with a bool which
// indicates if it is in recording mode or not. | [
"handleRecordingProxy",
"responds",
"to",
"global",
"out",
"-",
"of",
"-",
"band",
"with",
"a",
"bool",
"which",
"indicates",
"if",
"it",
"is",
"in",
"recording",
"mode",
"or",
"not",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/regular/sshserver.go#L1188-L1215 | train |
gravitational/teleport | lib/services/wrappers.go | UnmarshalJSON | func (s *Strings) UnmarshalJSON(data []byte) error {
if len(data) == 0 {
return nil
}
var stringVar string
if err := json.Unmarshal(data, &stringVar); err == nil {
*s = []string{stringVar}
return nil
}
var stringsVar []string
if err := json.Unmarshal(data, &stringsVar); err != nil {
return trace.Wrap(err... | go | func (s *Strings) UnmarshalJSON(data []byte) error {
if len(data) == 0 {
return nil
}
var stringVar string
if err := json.Unmarshal(data, &stringVar); err == nil {
*s = []string{stringVar}
return nil
}
var stringsVar []string
if err := json.Unmarshal(data, &stringsVar); err != nil {
return trace.Wrap(err... | [
"func",
"(",
"s",
"*",
"Strings",
")",
"UnmarshalJSON",
"(",
"data",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"len",
"(",
"data",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"var",
"stringVar",
"string",
"\n",
"if",
"err",
":=",
"jso... | // UnmarshalJSON unmarshals scalar string or strings slice to Strings | [
"UnmarshalJSON",
"unmarshals",
"scalar",
"string",
"or",
"strings",
"slice",
"to",
"Strings"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/wrappers.go#L99-L114 | train |
gravitational/teleport | lib/services/wrappers.go | UnmarshalYAML | func (s *Strings) UnmarshalYAML(unmarshal func(interface{}) error) error {
// try unmarshal as string
var val string
err := unmarshal(&val)
if err == nil {
*s = []string{val}
return nil
}
// try unmarshal as slice
var slice []string
err = unmarshal(&slice)
if err == nil {
*s = slice
return nil
}
re... | go | func (s *Strings) UnmarshalYAML(unmarshal func(interface{}) error) error {
// try unmarshal as string
var val string
err := unmarshal(&val)
if err == nil {
*s = []string{val}
return nil
}
// try unmarshal as slice
var slice []string
err = unmarshal(&slice)
if err == nil {
*s = slice
return nil
}
re... | [
"func",
"(",
"s",
"*",
"Strings",
")",
"UnmarshalYAML",
"(",
"unmarshal",
"func",
"(",
"interface",
"{",
"}",
")",
"error",
")",
"error",
"{",
"// try unmarshal as string",
"var",
"val",
"string",
"\n",
"err",
":=",
"unmarshal",
"(",
"&",
"val",
")",
"\n... | // UnmarshalYAML is used to allow Strings to unmarshal from
// scalar string value or from the list | [
"UnmarshalYAML",
"is",
"used",
"to",
"allow",
"Strings",
"to",
"unmarshal",
"from",
"scalar",
"string",
"value",
"or",
"from",
"the",
"list"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/wrappers.go#L118-L136 | train |
gravitational/teleport | lib/services/wrappers.go | MarshalJSON | func (s Strings) MarshalJSON() ([]byte, error) {
if len(s) == 1 {
return json.Marshal(s[0])
}
return json.Marshal([]string(s))
} | go | func (s Strings) MarshalJSON() ([]byte, error) {
if len(s) == 1 {
return json.Marshal(s[0])
}
return json.Marshal([]string(s))
} | [
"func",
"(",
"s",
"Strings",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"1",
"{",
"return",
"json",
".",
"Marshal",
"(",
"s",
"[",
"0",
"]",
")",
"\n",
"}",
"\n",
"return",
... | // MarshalJSON marshals to scalar value
// if there is only one value in the list
// to list otherwise | [
"MarshalJSON",
"marshals",
"to",
"scalar",
"value",
"if",
"there",
"is",
"only",
"one",
"value",
"in",
"the",
"list",
"to",
"list",
"otherwise"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/wrappers.go#L141-L146 | train |
gravitational/teleport | lib/services/wrappers.go | MarshalYAML | func (s Strings) MarshalYAML() (interface{}, error) {
if len(s) == 1 {
return s[0], nil
}
return []string(s), nil
} | go | func (s Strings) MarshalYAML() (interface{}, error) {
if len(s) == 1 {
return s[0], nil
}
return []string(s), nil
} | [
"func",
"(",
"s",
"Strings",
")",
"MarshalYAML",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"len",
"(",
"s",
")",
"==",
"1",
"{",
"return",
"s",
"[",
"0",
"]",
",",
"nil",
"\n",
"}",
"\n",
"return",
"[",
"]",
"string"... | // MarshalYAML marshals to scalar value
// if there is only one value in the list,
// marshals to list otherwise | [
"MarshalYAML",
"marshals",
"to",
"scalar",
"value",
"if",
"there",
"is",
"only",
"one",
"value",
"in",
"the",
"list",
"marshals",
"to",
"list",
"otherwise"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/wrappers.go#L151-L156 | train |
gravitational/teleport | lib/utils/utils.go | NewTracer | func NewTracer(description string) *Tracer {
return &Tracer{Started: time.Now().UTC(), Description: description}
} | go | func NewTracer(description string) *Tracer {
return &Tracer{Started: time.Now().UTC(), Description: description}
} | [
"func",
"NewTracer",
"(",
"description",
"string",
")",
"*",
"Tracer",
"{",
"return",
"&",
"Tracer",
"{",
"Started",
":",
"time",
".",
"Now",
"(",
")",
".",
"UTC",
"(",
")",
",",
"Description",
":",
"description",
"}",
"\n",
"}"
] | // NewTracer returns a new tracer | [
"NewTracer",
"returns",
"a",
"new",
"tracer"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L50-L52 | train |
gravitational/teleport | lib/utils/utils.go | Stop | func (t *Tracer) Stop() *Tracer {
log.Debugf("Tracer completed %v in %v.", t.Description, time.Now().Sub(t.Started))
return t
} | go | func (t *Tracer) Stop() *Tracer {
log.Debugf("Tracer completed %v in %v.", t.Description, time.Now().Sub(t.Started))
return t
} | [
"func",
"(",
"t",
"*",
"Tracer",
")",
"Stop",
"(",
")",
"*",
"Tracer",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"t",
".",
"Description",
",",
"time",
".",
"Now",
"(",
")",
".",
"Sub",
"(",
"t",
".",
"Started",
")",
")",
"\n",
"return"... | // Stop logs stop of the trace | [
"Stop",
"logs",
"stop",
"of",
"the",
"trace"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L61-L64 | train |
gravitational/teleport | lib/utils/utils.go | ThisFunction | func ThisFunction() string {
var pc [32]uintptr
runtime.Callers(2, pc[:])
return runtime.FuncForPC(pc[0]).Name()
} | go | func ThisFunction() string {
var pc [32]uintptr
runtime.Callers(2, pc[:])
return runtime.FuncForPC(pc[0]).Name()
} | [
"func",
"ThisFunction",
"(",
")",
"string",
"{",
"var",
"pc",
"[",
"32",
"]",
"uintptr",
"\n",
"runtime",
".",
"Callers",
"(",
"2",
",",
"pc",
"[",
":",
"]",
")",
"\n",
"return",
"runtime",
".",
"FuncForPC",
"(",
"pc",
"[",
"0",
"]",
")",
".",
... | // ThisFunction returns calling function name | [
"ThisFunction",
"returns",
"calling",
"function",
"name"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L67-L71 | train |
gravitational/teleport | lib/utils/utils.go | Value | func (s *SyncString) Value() string {
s.Lock()
defer s.Unlock()
return s.string
} | go | func (s *SyncString) Value() string {
s.Lock()
defer s.Unlock()
return s.string
} | [
"func",
"(",
"s",
"*",
"SyncString",
")",
"Value",
"(",
")",
"string",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"return",
"s",
".",
"string",
"\n",
"}"
] | // Value returns value of the string | [
"Value",
"returns",
"value",
"of",
"the",
"string"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L81-L85 | train |
gravitational/teleport | lib/utils/utils.go | Set | func (s *SyncString) Set(v string) {
s.Lock()
defer s.Unlock()
s.string = v
} | go | func (s *SyncString) Set(v string) {
s.Lock()
defer s.Unlock()
s.string = v
} | [
"func",
"(",
"s",
"*",
"SyncString",
")",
"Set",
"(",
"v",
"string",
")",
"{",
"s",
".",
"Lock",
"(",
")",
"\n",
"defer",
"s",
".",
"Unlock",
"(",
")",
"\n",
"s",
".",
"string",
"=",
"v",
"\n",
"}"
] | // Set sets the value of the string | [
"Set",
"sets",
"the",
"value",
"of",
"the",
"string"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L88-L92 | train |
gravitational/teleport | lib/utils/utils.go | AsBool | func AsBool(v string) bool {
if v == "" {
return false
}
out, _ := ParseBool(v)
return out
} | go | func AsBool(v string) bool {
if v == "" {
return false
}
out, _ := ParseBool(v)
return out
} | [
"func",
"AsBool",
"(",
"v",
"string",
")",
"bool",
"{",
"if",
"v",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"out",
",",
"_",
":=",
"ParseBool",
"(",
"v",
")",
"\n",
"return",
"out",
"\n",
"}"
] | // AsBool converts string to bool, in case of the value is empty
// or unknown, defaults to false | [
"AsBool",
"converts",
"string",
"to",
"bool",
"in",
"case",
"of",
"the",
"value",
"is",
"empty",
"or",
"unknown",
"defaults",
"to",
"false"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L118-L124 | train |
gravitational/teleport | lib/utils/utils.go | ParseBool | func ParseBool(value string) (bool, error) {
switch strings.ToLower(value) {
case "yes", "yeah", "y", "true", "1", "on":
return true, nil
case "no", "nope", "n", "false", "0", "off":
return false, nil
default:
return false, trace.BadParameter("unsupported value: %q", value)
}
} | go | func ParseBool(value string) (bool, error) {
switch strings.ToLower(value) {
case "yes", "yeah", "y", "true", "1", "on":
return true, nil
case "no", "nope", "n", "false", "0", "off":
return false, nil
default:
return false, trace.BadParameter("unsupported value: %q", value)
}
} | [
"func",
"ParseBool",
"(",
"value",
"string",
")",
"(",
"bool",
",",
"error",
")",
"{",
"switch",
"strings",
".",
"ToLower",
"(",
"value",
")",
"{",
"case",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"... | // ParseBool parses string as boolean value,
// returns error in case if value is not recognized | [
"ParseBool",
"parses",
"string",
"as",
"boolean",
"value",
"returns",
"error",
"in",
"case",
"if",
"value",
"is",
"not",
"recognized"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L128-L137 | train |
gravitational/teleport | lib/utils/utils.go | ParseAdvertiseAddr | func ParseAdvertiseAddr(advertiseIP string) (string, string, error) {
advertiseIP = strings.TrimSpace(advertiseIP)
host := advertiseIP
port := ""
if len(net.ParseIP(host)) == 0 && strings.Contains(advertiseIP, ":") {
var err error
host, port, err = net.SplitHostPort(advertiseIP)
if err != nil {
return "", ... | go | func ParseAdvertiseAddr(advertiseIP string) (string, string, error) {
advertiseIP = strings.TrimSpace(advertiseIP)
host := advertiseIP
port := ""
if len(net.ParseIP(host)) == 0 && strings.Contains(advertiseIP, ":") {
var err error
host, port, err = net.SplitHostPort(advertiseIP)
if err != nil {
return "", ... | [
"func",
"ParseAdvertiseAddr",
"(",
"advertiseIP",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"advertiseIP",
"=",
"strings",
".",
"TrimSpace",
"(",
"advertiseIP",
")",
"\n",
"host",
":=",
"advertiseIP",
"\n",
"port",
":=",
"\"",
"\... | // ParseAdvertiseAddr validates advertise address,
// makes sure it's not an unreachable or multicast address
// returns address split into host and port, port could be empty
// if not specified | [
"ParseAdvertiseAddr",
"validates",
"advertise",
"address",
"makes",
"sure",
"it",
"s",
"not",
"an",
"unreachable",
"or",
"multicast",
"address",
"returns",
"address",
"split",
"into",
"host",
"and",
"port",
"port",
"could",
"be",
"empty",
"if",
"not",
"specified... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L143-L167 | train |
gravitational/teleport | lib/utils/utils.go | ParseOnOff | func ParseOnOff(parameterName, val string, defaultValue bool) (bool, error) {
switch val {
case teleport.On:
return true, nil
case teleport.Off:
return false, nil
case "":
return defaultValue, nil
default:
return false, trace.BadParameter("bad %q parameter value: %q, supported values are on or off", parame... | go | func ParseOnOff(parameterName, val string, defaultValue bool) (bool, error) {
switch val {
case teleport.On:
return true, nil
case teleport.Off:
return false, nil
case "":
return defaultValue, nil
default:
return false, trace.BadParameter("bad %q parameter value: %q, supported values are on or off", parame... | [
"func",
"ParseOnOff",
"(",
"parameterName",
",",
"val",
"string",
",",
"defaultValue",
"bool",
")",
"(",
"bool",
",",
"error",
")",
"{",
"switch",
"val",
"{",
"case",
"teleport",
".",
"On",
":",
"return",
"true",
",",
"nil",
"\n",
"case",
"teleport",
"... | // ParseOnOff parses whether value is "on" or "off", parameterName is passed for error
// reporting purposes, defaultValue is returned when no value is set | [
"ParseOnOff",
"parses",
"whether",
"value",
"is",
"on",
"or",
"off",
"parameterName",
"is",
"passed",
"for",
"error",
"reporting",
"purposes",
"defaultValue",
"is",
"returned",
"when",
"no",
"value",
"is",
"set"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L184-L195 | train |
gravitational/teleport | lib/utils/utils.go | IsGroupMember | func IsGroupMember(gid int) (bool, error) {
groups, err := os.Getgroups()
if err != nil {
return false, trace.ConvertSystemError(err)
}
for _, group := range groups {
if group == gid {
return true, nil
}
}
return false, nil
} | go | func IsGroupMember(gid int) (bool, error) {
groups, err := os.Getgroups()
if err != nil {
return false, trace.ConvertSystemError(err)
}
for _, group := range groups {
if group == gid {
return true, nil
}
}
return false, nil
} | [
"func",
"IsGroupMember",
"(",
"gid",
"int",
")",
"(",
"bool",
",",
"error",
")",
"{",
"groups",
",",
"err",
":=",
"os",
".",
"Getgroups",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"trace",
".",
"ConvertSystemError",
"(",
... | // IsGroupMember returns whether currently logged user is a member of a group | [
"IsGroupMember",
"returns",
"whether",
"currently",
"logged",
"user",
"is",
"a",
"member",
"of",
"a",
"group"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L198-L209 | train |
gravitational/teleport | lib/utils/utils.go | SplitHostPort | func SplitHostPort(hostname string) (string, string, error) {
host, port, err := net.SplitHostPort(hostname)
if err != nil {
return "", "", trace.Wrap(err)
}
if host == "" {
return "", "", trace.BadParameter("empty hostname")
}
return host, port, nil
} | go | func SplitHostPort(hostname string) (string, string, error) {
host, port, err := net.SplitHostPort(hostname)
if err != nil {
return "", "", trace.Wrap(err)
}
if host == "" {
return "", "", trace.BadParameter("empty hostname")
}
return host, port, nil
} | [
"func",
"SplitHostPort",
"(",
"hostname",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"host",
",",
"port",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"hostname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\... | // SplitHostPort splits host and port and checks that host is not empty | [
"SplitHostPort",
"splits",
"host",
"and",
"port",
"and",
"checks",
"that",
"host",
"is",
"not",
"empty"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L224-L233 | train |
gravitational/teleport | lib/utils/utils.go | ReadPath | func ReadPath(path string) ([]byte, error) {
if path == "" {
return nil, trace.NotFound("empty path")
}
s, err := filepath.Abs(path)
if err != nil {
return nil, trace.ConvertSystemError(err)
}
abs, err := filepath.EvalSymlinks(s)
if err != nil {
return nil, trace.ConvertSystemError(err)
}
bytes, err := i... | go | func ReadPath(path string) ([]byte, error) {
if path == "" {
return nil, trace.NotFound("empty path")
}
s, err := filepath.Abs(path)
if err != nil {
return nil, trace.ConvertSystemError(err)
}
abs, err := filepath.EvalSymlinks(s)
if err != nil {
return nil, trace.ConvertSystemError(err)
}
bytes, err := i... | [
"func",
"ReadPath",
"(",
"path",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"trace",
".",
"NotFound",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"s",
",",
"err",
":=",
... | // ReadPath reads file contents | [
"ReadPath",
"reads",
"file",
"contents"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L236-L253 | train |
gravitational/teleport | lib/utils/utils.go | IsHandshakeFailedError | func IsHandshakeFailedError(err error) bool {
if err == nil {
return false
}
return strings.Contains(trace.Unwrap(err).Error(), "ssh: handshake failed")
} | go | func IsHandshakeFailedError(err error) bool {
if err == nil {
return false
}
return strings.Contains(trace.Unwrap(err).Error(), "ssh: handshake failed")
} | [
"func",
"IsHandshakeFailedError",
"(",
"err",
"error",
")",
"bool",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Contains",
"(",
"trace",
".",
"Unwrap",
"(",
"err",
")",
".",
"Error",
"(",
")",
",... | // IsHandshakeFailedError specifies whether this error indicates
// failed handshake | [
"IsHandshakeFailedError",
"specifies",
"whether",
"this",
"error",
"indicates",
"failed",
"handshake"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L277-L282 | train |
gravitational/teleport | lib/utils/utils.go | Pop | func (p *PortList) Pop() string {
if len(*p) == 0 {
panic("list is empty")
}
val := (*p)[len(*p)-1]
*p = (*p)[:len(*p)-1]
return val
} | go | func (p *PortList) Pop() string {
if len(*p) == 0 {
panic("list is empty")
}
val := (*p)[len(*p)-1]
*p = (*p)[:len(*p)-1]
return val
} | [
"func",
"(",
"p",
"*",
"PortList",
")",
"Pop",
"(",
")",
"string",
"{",
"if",
"len",
"(",
"*",
"p",
")",
"==",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"val",
":=",
"(",
"*",
"p",
")",
"[",
"len",
"(",
"*",
"p",
")",
"-... | // Pop returns a value from the list, it panics if the value is not there | [
"Pop",
"returns",
"a",
"value",
"from",
"the",
"list",
"it",
"panics",
"if",
"the",
"value",
"is",
"not",
"there"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L303-L310 | train |
gravitational/teleport | lib/utils/utils.go | PopInt | func (p *PortList) PopInt() int {
i, err := strconv.Atoi(p.Pop())
if err != nil {
panic(err)
}
return i
} | go | func (p *PortList) PopInt() int {
i, err := strconv.Atoi(p.Pop())
if err != nil {
panic(err)
}
return i
} | [
"func",
"(",
"p",
"*",
"PortList",
")",
"PopInt",
"(",
")",
"int",
"{",
"i",
",",
"err",
":=",
"strconv",
".",
"Atoi",
"(",
"p",
".",
"Pop",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"ret... | // PopInt returns a value from the list, it panics if not enough values
// were allocated | [
"PopInt",
"returns",
"a",
"value",
"from",
"the",
"list",
"it",
"panics",
"if",
"not",
"enough",
"values",
"were",
"allocated"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L314-L320 | train |
gravitational/teleport | lib/utils/utils.go | PopIntSlice | func (p *PortList) PopIntSlice(num int) []int {
ports := make([]int, num)
for i := range ports {
ports[i] = p.PopInt()
}
return ports
} | go | func (p *PortList) PopIntSlice(num int) []int {
ports := make([]int, num)
for i := range ports {
ports[i] = p.PopInt()
}
return ports
} | [
"func",
"(",
"p",
"*",
"PortList",
")",
"PopIntSlice",
"(",
"num",
"int",
")",
"[",
"]",
"int",
"{",
"ports",
":=",
"make",
"(",
"[",
"]",
"int",
",",
"num",
")",
"\n",
"for",
"i",
":=",
"range",
"ports",
"{",
"ports",
"[",
"i",
"]",
"=",
"p"... | // PopIntSlice returns a slice of values from the list, it panics if not enough
// ports were allocated | [
"PopIntSlice",
"returns",
"a",
"slice",
"of",
"values",
"from",
"the",
"list",
"it",
"panics",
"if",
"not",
"enough",
"ports",
"were",
"allocated"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L324-L330 | train |
gravitational/teleport | lib/utils/utils.go | GetFreeTCPPorts | func GetFreeTCPPorts(n int, offset ...int) (PortList, error) {
list := make(PortList, 0, n)
start := PortStartingNumber
if len(offset) != 0 {
start = offset[0]
}
for i := start; i < start+n; i++ {
list = append(list, strconv.Itoa(i))
}
return list, nil
} | go | func GetFreeTCPPorts(n int, offset ...int) (PortList, error) {
list := make(PortList, 0, n)
start := PortStartingNumber
if len(offset) != 0 {
start = offset[0]
}
for i := start; i < start+n; i++ {
list = append(list, strconv.Itoa(i))
}
return list, nil
} | [
"func",
"GetFreeTCPPorts",
"(",
"n",
"int",
",",
"offset",
"...",
"int",
")",
"(",
"PortList",
",",
"error",
")",
"{",
"list",
":=",
"make",
"(",
"PortList",
",",
"0",
",",
"n",
")",
"\n",
"start",
":=",
"PortStartingNumber",
"\n",
"if",
"len",
"(",
... | // GetFreeTCPPorts returns n ports starting from port 20000. | [
"GetFreeTCPPorts",
"returns",
"n",
"ports",
"starting",
"from",
"port",
"20000",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L336-L346 | train |
gravitational/teleport | lib/utils/utils.go | ReadHostUUID | func ReadHostUUID(dataDir string) (string, error) {
out, err := ReadPath(filepath.Join(dataDir, HostUUIDFile))
if err != nil {
return "", trace.Wrap(err)
}
return strings.TrimSpace(string(out)), nil
} | go | func ReadHostUUID(dataDir string) (string, error) {
out, err := ReadPath(filepath.Join(dataDir, HostUUIDFile))
if err != nil {
return "", trace.Wrap(err)
}
return strings.TrimSpace(string(out)), nil
} | [
"func",
"ReadHostUUID",
"(",
"dataDir",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"out",
",",
"err",
":=",
"ReadPath",
"(",
"filepath",
".",
"Join",
"(",
"dataDir",
",",
"HostUUIDFile",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retu... | // ReadHostUUID reads host UUID from the file in the data dir | [
"ReadHostUUID",
"reads",
"host",
"UUID",
"from",
"the",
"file",
"in",
"the",
"data",
"dir"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L349-L355 | train |
gravitational/teleport | lib/utils/utils.go | WriteHostUUID | func WriteHostUUID(dataDir string, id string) error {
err := ioutil.WriteFile(filepath.Join(dataDir, HostUUIDFile), []byte(id), os.ModeExclusive|0400)
if err != nil {
return trace.ConvertSystemError(err)
}
return nil
} | go | func WriteHostUUID(dataDir string, id string) error {
err := ioutil.WriteFile(filepath.Join(dataDir, HostUUIDFile), []byte(id), os.ModeExclusive|0400)
if err != nil {
return trace.ConvertSystemError(err)
}
return nil
} | [
"func",
"WriteHostUUID",
"(",
"dataDir",
"string",
",",
"id",
"string",
")",
"error",
"{",
"err",
":=",
"ioutil",
".",
"WriteFile",
"(",
"filepath",
".",
"Join",
"(",
"dataDir",
",",
"HostUUIDFile",
")",
",",
"[",
"]",
"byte",
"(",
"id",
")",
",",
"o... | // WriteHostUUID writes host UUID into a file | [
"WriteHostUUID",
"writes",
"host",
"UUID",
"into",
"a",
"file"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L358-L364 | train |
gravitational/teleport | lib/utils/utils.go | ReadOrMakeHostUUID | func ReadOrMakeHostUUID(dataDir string) (string, error) {
id, err := ReadHostUUID(dataDir)
if err == nil {
return id, nil
}
if !trace.IsNotFound(err) {
return "", trace.Wrap(err)
}
id = uuid.New()
if err = WriteHostUUID(dataDir, id); err != nil {
return "", trace.Wrap(err)
}
return id, nil
} | go | func ReadOrMakeHostUUID(dataDir string) (string, error) {
id, err := ReadHostUUID(dataDir)
if err == nil {
return id, nil
}
if !trace.IsNotFound(err) {
return "", trace.Wrap(err)
}
id = uuid.New()
if err = WriteHostUUID(dataDir, id); err != nil {
return "", trace.Wrap(err)
}
return id, nil
} | [
"func",
"ReadOrMakeHostUUID",
"(",
"dataDir",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"id",
",",
"err",
":=",
"ReadHostUUID",
"(",
"dataDir",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"return",
"id",
",",
"nil",
"\n",
"}",
"\n",
"if",
... | // ReadOrMakeHostUUID looks for a hostid file in the data dir. If present,
// returns the UUID from it, otherwise generates one | [
"ReadOrMakeHostUUID",
"looks",
"for",
"a",
"hostid",
"file",
"in",
"the",
"data",
"dir",
".",
"If",
"present",
"returns",
"the",
"UUID",
"from",
"it",
"otherwise",
"generates",
"one"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/utils.go#L368-L381 | train |
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.