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/events/filelog.go | CheckAndSetDefaults | func (cfg *FileLogConfig) CheckAndSetDefaults() error {
if cfg.Dir == "" {
return trace.BadParameter("missing parameter Dir")
}
if !utils.IsDir(cfg.Dir) {
return trace.BadParameter("path %q does not exist or is not a directory", cfg.Dir)
}
if cfg.SymlinkDir == "" {
cfg.SymlinkDir = cfg.Dir
}
if !utils.IsDi... | go | func (cfg *FileLogConfig) CheckAndSetDefaults() error {
if cfg.Dir == "" {
return trace.BadParameter("missing parameter Dir")
}
if !utils.IsDir(cfg.Dir) {
return trace.BadParameter("path %q does not exist or is not a directory", cfg.Dir)
}
if cfg.SymlinkDir == "" {
cfg.SymlinkDir = cfg.Dir
}
if !utils.IsDi... | [
"func",
"(",
"cfg",
"*",
"FileLogConfig",
")",
"CheckAndSetDefaults",
"(",
")",
"error",
"{",
"if",
"cfg",
".",
"Dir",
"==",
"\"",
"\"",
"{",
"return",
"trace",
".",
"BadParameter",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"!",
"utils",
".",
"I... | // CheckAndSetDefaults checks and sets config defaults | [
"CheckAndSetDefaults",
"checks",
"and",
"sets",
"config",
"defaults"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L60-L86 | train |
gravitational/teleport | lib/events/filelog.go | NewFileLog | func NewFileLog(cfg FileLogConfig) (*FileLog, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
f := &FileLog{
FileLogConfig: cfg,
Entry: log.WithFields(log.Fields{
trace.Component: teleport.ComponentAuditLog,
}),
}
return f, nil
} | go | func NewFileLog(cfg FileLogConfig) (*FileLog, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
f := &FileLog{
FileLogConfig: cfg,
Entry: log.WithFields(log.Fields{
trace.Component: teleport.ComponentAuditLog,
}),
}
return f, nil
} | [
"func",
"NewFileLog",
"(",
"cfg",
"FileLogConfig",
")",
"(",
"*",
"FileLog",
",",
"error",
")",
"{",
"if",
"err",
":=",
"cfg",
".",
"CheckAndSetDefaults",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"Wrap",
"(",
"err",... | // NewFileLog returns a new instance of a file log | [
"NewFileLog",
"returns",
"a",
"new",
"instance",
"of",
"a",
"file",
"log"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L89-L100 | train |
gravitational/teleport | lib/events/filelog.go | EmitAuditEvent | func (l *FileLog) EmitAuditEvent(event Event, fields EventFields) error {
// see if the log needs to be rotated
err := l.rotateLog()
if err != nil {
log.Error(err)
}
err = UpdateEventFields(event, fields, l.Clock, l.UIDGenerator)
if err != nil {
log.Error(err)
}
// line is the text to be logged
line, err :... | go | func (l *FileLog) EmitAuditEvent(event Event, fields EventFields) error {
// see if the log needs to be rotated
err := l.rotateLog()
if err != nil {
log.Error(err)
}
err = UpdateEventFields(event, fields, l.Clock, l.UIDGenerator)
if err != nil {
log.Error(err)
}
// line is the text to be logged
line, err :... | [
"func",
"(",
"l",
"*",
"FileLog",
")",
"EmitAuditEvent",
"(",
"event",
"Event",
",",
"fields",
"EventFields",
")",
"error",
"{",
"// see if the log needs to be rotated",
"err",
":=",
"l",
".",
"rotateLog",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"lo... | // EmitAuditEvent adds a new event to the log. Part of auth.IFileLog interface. | [
"EmitAuditEvent",
"adds",
"a",
"new",
"event",
"to",
"the",
"log",
".",
"Part",
"of",
"auth",
".",
"IFileLog",
"interface",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L117-L137 | train |
gravitational/teleport | lib/events/filelog.go | Close | func (l *FileLog) Close() error {
l.Lock()
defer l.Unlock()
var err error
if l.file != nil {
err = l.file.Close()
l.file = nil
}
return err
} | go | func (l *FileLog) Close() error {
l.Lock()
defer l.Unlock()
var err error
if l.file != nil {
err = l.file.Close()
l.file = nil
}
return err
} | [
"func",
"(",
"l",
"*",
"FileLog",
")",
"Close",
"(",
")",
"error",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"if",
"l",
".",
"file",
"!=",
"nil",
"{",
"err",
"=",
"l",
... | // Close closes the audit log, which inluces closing all file handles and releasing
// all session loggers | [
"Close",
"closes",
"the",
"audit",
"log",
"which",
"inluces",
"closing",
"all",
"file",
"handles",
"and",
"releasing",
"all",
"session",
"loggers"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L230-L240 | train |
gravitational/teleport | lib/events/filelog.go | rotateLog | func (l *FileLog) rotateLog() (err error) {
l.Lock()
defer l.Unlock()
// determine the timestamp for the current log file
fileTime := l.Clock.Now().In(time.UTC)
// truncate time to the resolution of one day, cutting at the day end boundary
fileTime = time.Date(fileTime.Year(), fileTime.Month(), fileTime.Day(), ... | go | func (l *FileLog) rotateLog() (err error) {
l.Lock()
defer l.Unlock()
// determine the timestamp for the current log file
fileTime := l.Clock.Now().In(time.UTC)
// truncate time to the resolution of one day, cutting at the day end boundary
fileTime = time.Date(fileTime.Year(), fileTime.Month(), fileTime.Day(), ... | [
"func",
"(",
"l",
"*",
"FileLog",
")",
"rotateLog",
"(",
")",
"(",
"err",
"error",
")",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n\n",
"// determine the timestamp for the current log file",
"fileTime",
":=",
"l",
".... | // rotateLog checks if the current log file is older than a given duration,
// and if it is, closes it and opens a new one. | [
"rotateLog",
"checks",
"if",
"the",
"current",
"log",
"file",
"is",
"older",
"than",
"a",
"given",
"duration",
"and",
"if",
"it",
"is",
"closes",
"it",
"and",
"opens",
"a",
"new",
"one",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L292-L342 | train |
gravitational/teleport | lib/events/filelog.go | matchingFiles | func (l *FileLog) matchingFiles(fromUTC, toUTC time.Time) ([]eventFile, error) {
var dirs []string
var err error
if l.SearchDirs != nil {
dirs, err = l.SearchDirs()
if err != nil {
return nil, trace.Wrap(err)
}
} else {
dirs = []string{l.Dir}
}
var filtered []eventFile
for _, dir := range dirs {
//... | go | func (l *FileLog) matchingFiles(fromUTC, toUTC time.Time) ([]eventFile, error) {
var dirs []string
var err error
if l.SearchDirs != nil {
dirs, err = l.SearchDirs()
if err != nil {
return nil, trace.Wrap(err)
}
} else {
dirs = []string{l.Dir}
}
var filtered []eventFile
for _, dir := range dirs {
//... | [
"func",
"(",
"l",
"*",
"FileLog",
")",
"matchingFiles",
"(",
"fromUTC",
",",
"toUTC",
"time",
".",
"Time",
")",
"(",
"[",
"]",
"eventFile",
",",
"error",
")",
"{",
"var",
"dirs",
"[",
"]",
"string",
"\n",
"var",
"err",
"error",
"\n",
"if",
"l",
"... | // matchingFiles returns files matching the time restrictions of the query
// across multiple auth servers, returns a list of file names | [
"matchingFiles",
"returns",
"files",
"matching",
"the",
"time",
"restrictions",
"of",
"the",
"query",
"across",
"multiple",
"auth",
"servers",
"returns",
"a",
"list",
"of",
"file",
"names"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L346-L398 | train |
gravitational/teleport | lib/events/filelog.go | parseFileTime | func parseFileTime(filename string) (time.Time, error) {
base := strings.TrimSuffix(filename, filepath.Ext(filename))
return time.Parse(defaults.AuditLogTimeFormat, base)
} | go | func parseFileTime(filename string) (time.Time, error) {
base := strings.TrimSuffix(filename, filepath.Ext(filename))
return time.Parse(defaults.AuditLogTimeFormat, base)
} | [
"func",
"parseFileTime",
"(",
"filename",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"base",
":=",
"strings",
".",
"TrimSuffix",
"(",
"filename",
",",
"filepath",
".",
"Ext",
"(",
"filename",
")",
")",
"\n",
"return",
"time",
".",... | // parseFileTime parses file's timestamp encoded into filename | [
"parseFileTime",
"parses",
"file",
"s",
"timestamp",
"encoded",
"into",
"filename"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L401-L404 | train |
gravitational/teleport | lib/events/filelog.go | getTime | func getTime(v interface{}) time.Time {
sval, ok := v.(string)
if !ok {
return time.Time{}
}
t, err := time.Parse(time.RFC3339, sval)
if err != nil {
return time.Time{}
}
return t
} | go | func getTime(v interface{}) time.Time {
sval, ok := v.(string)
if !ok {
return time.Time{}
}
t, err := time.Parse(time.RFC3339, sval)
if err != nil {
return time.Time{}
}
return t
} | [
"func",
"getTime",
"(",
"v",
"interface",
"{",
"}",
")",
"time",
".",
"Time",
"{",
"sval",
",",
"ok",
":=",
"v",
".",
"(",
"string",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"time",
".",
"Time",
"{",
"}",
"\n",
"}",
"\n",
"t",
",",
"err",
... | // getTime converts json time to string | [
"getTime",
"converts",
"json",
"time",
"to",
"string"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/filelog.go#L501-L511 | train |
gravitational/teleport | lib/utils/equals.go | StringMapsEqual | func StringMapsEqual(a, b map[string]string) bool {
if len(a) != len(b) {
return false
}
for key := range a {
if a[key] != b[key] {
return false
}
}
return true
} | go | func StringMapsEqual(a, b map[string]string) bool {
if len(a) != len(b) {
return false
}
for key := range a {
if a[key] != b[key] {
return false
}
}
return true
} | [
"func",
"StringMapsEqual",
"(",
"a",
",",
"b",
"map",
"[",
"string",
"]",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"a",
")",
"!=",
"len",
"(",
"b",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"key",
":=",
"range",
"a",
"{",
"if",
... | // StringMapsEqual returns true if two strings maps are equal | [
"StringMapsEqual",
"returns",
"true",
"if",
"two",
"strings",
"maps",
"are",
"equal"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/equals.go#L33-L43 | train |
gravitational/teleport | lib/utils/equals.go | StringMapSlicesEqual | func StringMapSlicesEqual(a, b map[string][]string) bool {
if len(a) != len(b) {
return false
}
for key := range a {
if !StringSlicesEqual(a[key], b[key]) {
return false
}
}
return true
} | go | func StringMapSlicesEqual(a, b map[string][]string) bool {
if len(a) != len(b) {
return false
}
for key := range a {
if !StringSlicesEqual(a[key], b[key]) {
return false
}
}
return true
} | [
"func",
"StringMapSlicesEqual",
"(",
"a",
",",
"b",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"bool",
"{",
"if",
"len",
"(",
"a",
")",
"!=",
"len",
"(",
"b",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"for",
"key",
":=",
"range",
"... | // StringMapSlicesEqual returns true if two maps of string slices are equal | [
"StringMapSlicesEqual",
"returns",
"true",
"if",
"two",
"maps",
"of",
"string",
"slices",
"are",
"equal"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/equals.go#L59-L69 | train |
gravitational/teleport | lib/services/saml.go | NewSAMLConnector | func NewSAMLConnector(name string, spec SAMLConnectorSpecV2) SAMLConnector {
return &SAMLConnectorV2{
Kind: KindSAMLConnector,
Version: V2,
Metadata: Metadata{
Name: name,
Namespace: defaults.Namespace,
},
Spec: spec,
}
} | go | func NewSAMLConnector(name string, spec SAMLConnectorSpecV2) SAMLConnector {
return &SAMLConnectorV2{
Kind: KindSAMLConnector,
Version: V2,
Metadata: Metadata{
Name: name,
Namespace: defaults.Namespace,
},
Spec: spec,
}
} | [
"func",
"NewSAMLConnector",
"(",
"name",
"string",
",",
"spec",
"SAMLConnectorSpecV2",
")",
"SAMLConnector",
"{",
"return",
"&",
"SAMLConnectorV2",
"{",
"Kind",
":",
"KindSAMLConnector",
",",
"Version",
":",
"V2",
",",
"Metadata",
":",
"Metadata",
"{",
"Name",
... | // NewSAMLConnector returns a new SAMLConnector based off a name and SAMLConnectorSpecV2. | [
"NewSAMLConnector",
"returns",
"a",
"new",
"SAMLConnector",
"based",
"off",
"a",
"name",
"and",
"SAMLConnectorSpecV2",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/saml.go#L110-L120 | train |
gravitational/teleport | lib/services/saml.go | UnmarshalSAMLConnector | func (*TeleportSAMLConnectorMarshaler) UnmarshalSAMLConnector(bytes []byte, opts ...MarshalOption) (SAMLConnector, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
var h ResourceHeader
err = utils.FastUnmarshal(bytes, &h)
if err != nil {
return nil, trace.Wrap(err)
}
s... | go | func (*TeleportSAMLConnectorMarshaler) UnmarshalSAMLConnector(bytes []byte, opts ...MarshalOption) (SAMLConnector, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
var h ResourceHeader
err = utils.FastUnmarshal(bytes, &h)
if err != nil {
return nil, trace.Wrap(err)
}
s... | [
"func",
"(",
"*",
"TeleportSAMLConnectorMarshaler",
")",
"UnmarshalSAMLConnector",
"(",
"bytes",
"[",
"]",
"byte",
",",
"opts",
"...",
"MarshalOption",
")",
"(",
"SAMLConnector",
",",
"error",
")",
"{",
"cfg",
",",
"err",
":=",
"collectOptions",
"(",
"opts",
... | // UnmarshalSAMLConnector unmarshals connector from | [
"UnmarshalSAMLConnector",
"unmarshals",
"connector",
"from"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/saml.go#L155-L193 | train |
gravitational/teleport | lib/services/saml.go | MarshalSAMLConnector | func (*TeleportSAMLConnectorMarshaler) MarshalSAMLConnector(c SAMLConnector, opts ...MarshalOption) ([]byte, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
type connv2 interface {
V2() *SAMLConnectorV2
}
version := cfg.GetVersion()
switch version {
case V2:
v, ok :... | go | func (*TeleportSAMLConnectorMarshaler) MarshalSAMLConnector(c SAMLConnector, opts ...MarshalOption) ([]byte, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
type connv2 interface {
V2() *SAMLConnectorV2
}
version := cfg.GetVersion()
switch version {
case V2:
v, ok :... | [
"func",
"(",
"*",
"TeleportSAMLConnectorMarshaler",
")",
"MarshalSAMLConnector",
"(",
"c",
"SAMLConnector",
",",
"opts",
"...",
"MarshalOption",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"cfg",
",",
"err",
":=",
"collectOptions",
"(",
"opts",
")",
... | // MarshalUser marshals SAML connector into JSON | [
"MarshalUser",
"marshals",
"SAML",
"connector",
"into",
"JSON"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/saml.go#L196-L223 | train |
gravitational/teleport | lib/services/saml.go | Equals | func (o *SAMLConnectorV2) Equals(other SAMLConnector) bool {
if o.GetName() != other.GetName() {
return false
}
if o.GetCert() != other.GetCert() {
return false
}
if o.GetAudience() != other.GetAudience() {
return false
}
if o.GetEntityDescriptor() != other.GetEntityDescriptor() {
return false
}
if o.E... | go | func (o *SAMLConnectorV2) Equals(other SAMLConnector) bool {
if o.GetName() != other.GetName() {
return false
}
if o.GetCert() != other.GetCert() {
return false
}
if o.GetAudience() != other.GetAudience() {
return false
}
if o.GetEntityDescriptor() != other.GetEntityDescriptor() {
return false
}
if o.E... | [
"func",
"(",
"o",
"*",
"SAMLConnectorV2",
")",
"Equals",
"(",
"other",
"SAMLConnector",
")",
"bool",
"{",
"if",
"o",
".",
"GetName",
"(",
")",
"!=",
"other",
".",
"GetName",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"if",
"o",
".",
"GetCer... | // Equals returns true if the connectors are identical | [
"Equals",
"returns",
"true",
"if",
"the",
"connectors",
"are",
"identical"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/saml.go#L340-L389 | train |
gravitational/teleport | lib/services/saml.go | GetAttributes | func (o *SAMLConnectorV2) GetAttributes() []string {
var out []string
for _, mapping := range o.Spec.AttributesToRoles {
out = append(out, mapping.Name)
}
return utils.Deduplicate(out)
} | go | func (o *SAMLConnectorV2) GetAttributes() []string {
var out []string
for _, mapping := range o.Spec.AttributesToRoles {
out = append(out, mapping.Name)
}
return utils.Deduplicate(out)
} | [
"func",
"(",
"o",
"*",
"SAMLConnectorV2",
")",
"GetAttributes",
"(",
")",
"[",
"]",
"string",
"{",
"var",
"out",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"mapping",
":=",
"range",
"o",
".",
"Spec",
".",
"AttributesToRoles",
"{",
"out",
"=",
"append... | // GetAttributes returns list of attributes expected by mappings | [
"GetAttributes",
"returns",
"list",
"of",
"attributes",
"expected",
"by",
"mappings"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/saml.go#L470-L476 | train |
gravitational/teleport | lib/services/saml.go | MapAttributes | func (o *SAMLConnectorV2) MapAttributes(assertionInfo saml2.AssertionInfo) []string {
var roles []string
for _, mapping := range o.Spec.AttributesToRoles {
for _, attr := range assertionInfo.Values {
if attr.Name != mapping.Name {
continue
}
mappingLoop:
for _, value := range attr.Values {
for _,... | go | func (o *SAMLConnectorV2) MapAttributes(assertionInfo saml2.AssertionInfo) []string {
var roles []string
for _, mapping := range o.Spec.AttributesToRoles {
for _, attr := range assertionInfo.Values {
if attr.Name != mapping.Name {
continue
}
mappingLoop:
for _, value := range attr.Values {
for _,... | [
"func",
"(",
"o",
"*",
"SAMLConnectorV2",
")",
"MapAttributes",
"(",
"assertionInfo",
"saml2",
".",
"AssertionInfo",
")",
"[",
"]",
"string",
"{",
"var",
"roles",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"mapping",
":=",
"range",
"o",
".",
"Spec",
".... | // MapClaims maps SAML attributes to roles | [
"MapClaims",
"maps",
"SAML",
"attributes",
"to",
"roles"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/saml.go#L479-L508 | train |
gravitational/teleport | lib/services/saml.go | GetAttributeNames | func GetAttributeNames(attributes map[string]types.Attribute) []string {
var out []string
for _, attr := range attributes {
out = append(out, attr.Name)
}
return out
} | go | func GetAttributeNames(attributes map[string]types.Attribute) []string {
var out []string
for _, attr := range attributes {
out = append(out, attr.Name)
}
return out
} | [
"func",
"GetAttributeNames",
"(",
"attributes",
"map",
"[",
"string",
"]",
"types",
".",
"Attribute",
")",
"[",
"]",
"string",
"{",
"var",
"out",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"attr",
":=",
"range",
"attributes",
"{",
"out",
"=",
"append",... | // GetAttributeNames returns a list of claim names from the claim values | [
"GetAttributeNames",
"returns",
"a",
"list",
"of",
"claim",
"names",
"from",
"the",
"claim",
"values"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/saml.go#L792-L798 | train |
gravitational/teleport | lib/services/presence.go | NewNamespace | func NewNamespace(name string) Namespace {
return Namespace{
Kind: KindNamespace,
Version: V2,
Metadata: Metadata{
Name: name,
},
}
} | go | func NewNamespace(name string) Namespace {
return Namespace{
Kind: KindNamespace,
Version: V2,
Metadata: Metadata{
Name: name,
},
}
} | [
"func",
"NewNamespace",
"(",
"name",
"string",
")",
"Namespace",
"{",
"return",
"Namespace",
"{",
"Kind",
":",
"KindNamespace",
",",
"Version",
":",
"V2",
",",
"Metadata",
":",
"Metadata",
"{",
"Name",
":",
"name",
",",
"}",
",",
"}",
"\n",
"}"
] | // NewNamespace returns new namespace | [
"NewNamespace",
"returns",
"new",
"namespace"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/presence.go#L159-L167 | train |
gravitational/teleport | lib/services/resource.go | AddOptions | func AddOptions(opts []MarshalOption, add ...MarshalOption) []MarshalOption {
out := make([]MarshalOption, len(opts), len(opts)+len(add))
copy(out, opts)
return append(opts, add...)
} | go | func AddOptions(opts []MarshalOption, add ...MarshalOption) []MarshalOption {
out := make([]MarshalOption, len(opts), len(opts)+len(add))
copy(out, opts)
return append(opts, add...)
} | [
"func",
"AddOptions",
"(",
"opts",
"[",
"]",
"MarshalOption",
",",
"add",
"...",
"MarshalOption",
")",
"[",
"]",
"MarshalOption",
"{",
"out",
":=",
"make",
"(",
"[",
"]",
"MarshalOption",
",",
"len",
"(",
"opts",
")",
",",
"len",
"(",
"opts",
")",
"+... | // AddOptions adds marshal options and returns a new copy | [
"AddOptions",
"adds",
"marshal",
"options",
"and",
"returns",
"a",
"new",
"copy"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L254-L258 | train |
gravitational/teleport | lib/services/resource.go | WithResourceID | func WithResourceID(id int64) MarshalOption {
return func(c *MarshalConfig) error {
c.ID = id
return nil
}
} | go | func WithResourceID(id int64) MarshalOption {
return func(c *MarshalConfig) error {
c.ID = id
return nil
}
} | [
"func",
"WithResourceID",
"(",
"id",
"int64",
")",
"MarshalOption",
"{",
"return",
"func",
"(",
"c",
"*",
"MarshalConfig",
")",
"error",
"{",
"c",
".",
"ID",
"=",
"id",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithResourceID assigns ID to the resource | [
"WithResourceID",
"assigns",
"ID",
"to",
"the",
"resource"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L261-L266 | train |
gravitational/teleport | lib/services/resource.go | WithExpires | func WithExpires(expires time.Time) MarshalOption {
return func(c *MarshalConfig) error {
c.Expires = expires
return nil
}
} | go | func WithExpires(expires time.Time) MarshalOption {
return func(c *MarshalConfig) error {
c.Expires = expires
return nil
}
} | [
"func",
"WithExpires",
"(",
"expires",
"time",
".",
"Time",
")",
"MarshalOption",
"{",
"return",
"func",
"(",
"c",
"*",
"MarshalConfig",
")",
"error",
"{",
"c",
".",
"Expires",
"=",
"expires",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithExpires assigns expiry value | [
"WithExpires",
"assigns",
"expiry",
"value"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L269-L274 | train |
gravitational/teleport | lib/services/resource.go | WithVersion | func WithVersion(v string) MarshalOption {
return func(c *MarshalConfig) error {
switch v {
case V1, V2:
c.Version = v
return nil
default:
return trace.BadParameter("version '%v' is not supported", v)
}
}
} | go | func WithVersion(v string) MarshalOption {
return func(c *MarshalConfig) error {
switch v {
case V1, V2:
c.Version = v
return nil
default:
return trace.BadParameter("version '%v' is not supported", v)
}
}
} | [
"func",
"WithVersion",
"(",
"v",
"string",
")",
"MarshalOption",
"{",
"return",
"func",
"(",
"c",
"*",
"MarshalConfig",
")",
"error",
"{",
"switch",
"v",
"{",
"case",
"V1",
",",
"V2",
":",
"c",
".",
"Version",
"=",
"v",
"\n",
"return",
"nil",
"\n",
... | // WithVersion sets marshal version | [
"WithVersion",
"sets",
"marshal",
"version"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L280-L290 | train |
gravitational/teleport | lib/services/resource.go | SetTTL | func (h *ResourceHeader) SetTTL(clock clockwork.Clock, ttl time.Duration) {
h.Metadata.SetTTL(clock, ttl)
} | go | func (h *ResourceHeader) SetTTL(clock clockwork.Clock, ttl time.Duration) {
h.Metadata.SetTTL(clock, ttl)
} | [
"func",
"(",
"h",
"*",
"ResourceHeader",
")",
"SetTTL",
"(",
"clock",
"clockwork",
".",
"Clock",
",",
"ttl",
"time",
".",
"Duration",
")",
"{",
"h",
".",
"Metadata",
".",
"SetTTL",
"(",
"clock",
",",
"ttl",
")",
"\n",
"}"
] | // SetTTL sets Expires header using current clock | [
"SetTTL",
"sets",
"Expires",
"header",
"using",
"current",
"clock"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L394-L396 | train |
gravitational/teleport | lib/services/resource.go | UnmarshalJSON | func (u *UnknownResource) UnmarshalJSON(raw []byte) error {
var h ResourceHeader
if err := json.Unmarshal(raw, &h); err != nil {
return trace.Wrap(err)
}
u.Raw = make([]byte, len(raw))
u.ResourceHeader = h
copy(u.Raw, raw)
return nil
} | go | func (u *UnknownResource) UnmarshalJSON(raw []byte) error {
var h ResourceHeader
if err := json.Unmarshal(raw, &h); err != nil {
return trace.Wrap(err)
}
u.Raw = make([]byte, len(raw))
u.ResourceHeader = h
copy(u.Raw, raw)
return nil
} | [
"func",
"(",
"u",
"*",
"UnknownResource",
")",
"UnmarshalJSON",
"(",
"raw",
"[",
"]",
"byte",
")",
"error",
"{",
"var",
"h",
"ResourceHeader",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"raw",
",",
"&",
"h",
")",
";",
"err",
"!=",
"nil... | // UnmarshalJSON unmarshals header and captures raw state | [
"UnmarshalJSON",
"unmarshals",
"header",
"and",
"captures",
"raw",
"state"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L419-L428 | train |
gravitational/teleport | lib/services/resource.go | CheckAndSetDefaults | func (m *Metadata) CheckAndSetDefaults() error {
if m.Name == "" {
return trace.BadParameter("missing parameter Name")
}
if m.Namespace == "" {
m.Namespace = defaults.Namespace
}
// adjust expires time to utc if it's set
if m.Expires != nil {
utils.UTC(m.Expires)
}
return nil
} | go | func (m *Metadata) CheckAndSetDefaults() error {
if m.Name == "" {
return trace.BadParameter("missing parameter Name")
}
if m.Namespace == "" {
m.Namespace = defaults.Namespace
}
// adjust expires time to utc if it's set
if m.Expires != nil {
utils.UTC(m.Expires)
}
return nil
} | [
"func",
"(",
"m",
"*",
"Metadata",
")",
"CheckAndSetDefaults",
"(",
")",
"error",
"{",
"if",
"m",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"trace",
".",
"BadParameter",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"Namespace",
"==",
... | // CheckAndSetDefaults checks validity of all parameters and sets defaults | [
"CheckAndSetDefaults",
"checks",
"validity",
"of",
"all",
"parameters",
"and",
"sets",
"defaults"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L503-L517 | train |
gravitational/teleport | lib/services/resource.go | ParseShortcut | func ParseShortcut(in string) (string, error) {
if in == "" {
return "", trace.BadParameter("missing resource name")
}
switch strings.ToLower(in) {
case "role", "roles":
return KindRole, nil
case "namespaces", "ns":
return KindNamespace, nil
case "auth_servers", "auth":
return KindAuthServer, nil
case "p... | go | func ParseShortcut(in string) (string, error) {
if in == "" {
return "", trace.BadParameter("missing resource name")
}
switch strings.ToLower(in) {
case "role", "roles":
return KindRole, nil
case "namespaces", "ns":
return KindNamespace, nil
case "auth_servers", "auth":
return KindAuthServer, nil
case "p... | [
"func",
"ParseShortcut",
"(",
"in",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"in",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"trace",
".",
"BadParameter",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"switch",
"strings",
".",
... | // ParseShortcut parses resource shortcut | [
"ParseShortcut",
"parses",
"resource",
"shortcut"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/resource.go#L520-L557 | train |
gravitational/teleport | lib/utils/parse/parse.go | walk | func walk(node ast.Node) ([]string, error) {
var l []string
switch n := node.(type) {
case *ast.IndexExpr:
ret, err := walk(n.X)
if err != nil {
return nil, err
}
l = append(l, ret...)
ret, err = walk(n.Index)
if err != nil {
return nil, err
}
l = append(l, ret...)
case *ast.SelectorExpr:
... | go | func walk(node ast.Node) ([]string, error) {
var l []string
switch n := node.(type) {
case *ast.IndexExpr:
ret, err := walk(n.X)
if err != nil {
return nil, err
}
l = append(l, ret...)
ret, err = walk(n.Index)
if err != nil {
return nil, err
}
l = append(l, ret...)
case *ast.SelectorExpr:
... | [
"func",
"walk",
"(",
"node",
"ast",
".",
"Node",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"l",
"[",
"]",
"string",
"\n\n",
"switch",
"n",
":=",
"node",
".",
"(",
"type",
")",
"{",
"case",
"*",
"ast",
".",
"IndexExpr",
":",
... | // walk will walk the ast tree and gather all the variable parts into a slice and return it. | [
"walk",
"will",
"walk",
"the",
"ast",
"tree",
"and",
"gather",
"all",
"the",
"variable",
"parts",
"into",
"a",
"slice",
"and",
"return",
"it",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/utils/parse/parse.go#L64-L105 | train |
gravitational/teleport | lib/events/auditlog.go | NewAuditLog | func NewAuditLog(cfg AuditLogConfig) (*AuditLog, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
ctx, cancel := context.WithCancel(cfg.Context)
al := &AuditLog{
playbackDir: filepath.Join(cfg.DataDir, PlaybackDir, SessionLogsDir, defaults.Namespace),
AuditLogConfig:... | go | func NewAuditLog(cfg AuditLogConfig) (*AuditLog, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
ctx, cancel := context.WithCancel(cfg.Context)
al := &AuditLog{
playbackDir: filepath.Join(cfg.DataDir, PlaybackDir, SessionLogsDir, defaults.Namespace),
AuditLogConfig:... | [
"func",
"NewAuditLog",
"(",
"cfg",
"AuditLogConfig",
")",
"(",
"*",
"AuditLog",
",",
"error",
")",
"{",
"if",
"err",
":=",
"cfg",
".",
"CheckAndSetDefaults",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"Wrap",
"(",
"er... | // Creates and returns a new Audit Log object whish will store its logfiles in
// a given directory. Session recording can be disabled by setting
// recordSessions to false. | [
"Creates",
"and",
"returns",
"a",
"new",
"Audit",
"Log",
"object",
"whish",
"will",
"store",
"its",
"logfiles",
"in",
"a",
"given",
"directory",
".",
"Session",
"recording",
"can",
"be",
"disabled",
"by",
"setting",
"recordSessions",
"to",
"false",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L235-L300 | train |
gravitational/teleport | lib/events/auditlog.go | CheckAndSetDefaults | func (l *SessionRecording) CheckAndSetDefaults() error {
if l.Recording == nil {
return trace.BadParameter("missing parameter Recording")
}
if l.SessionID.IsZero() {
return trace.BadParameter("missing parameter session ID")
}
if l.Namespace == "" {
l.Namespace = defaults.Namespace
}
return nil
} | go | func (l *SessionRecording) CheckAndSetDefaults() error {
if l.Recording == nil {
return trace.BadParameter("missing parameter Recording")
}
if l.SessionID.IsZero() {
return trace.BadParameter("missing parameter session ID")
}
if l.Namespace == "" {
l.Namespace = defaults.Namespace
}
return nil
} | [
"func",
"(",
"l",
"*",
"SessionRecording",
")",
"CheckAndSetDefaults",
"(",
")",
"error",
"{",
"if",
"l",
".",
"Recording",
"==",
"nil",
"{",
"return",
"trace",
".",
"BadParameter",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"l",
".",
"SessionID",
... | // CheckAndSetDefaults checks and sets default parameters | [
"CheckAndSetDefaults",
"checks",
"and",
"sets",
"default",
"parameters"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L317-L328 | train |
gravitational/teleport | lib/events/auditlog.go | chunkFileNames | func (idx *sessionIndex) chunkFileNames() []string {
fileNames := make([]string, len(idx.chunks))
for i := 0; i < len(idx.chunks); i++ {
fileNames[i] = idx.chunksFileName(i)
}
return fileNames
} | go | func (idx *sessionIndex) chunkFileNames() []string {
fileNames := make([]string, len(idx.chunks))
for i := 0; i < len(idx.chunks); i++ {
fileNames[i] = idx.chunksFileName(i)
}
return fileNames
} | [
"func",
"(",
"idx",
"*",
"sessionIndex",
")",
"chunkFileNames",
"(",
")",
"[",
"]",
"string",
"{",
"fileNames",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"idx",
".",
"chunks",
")",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
... | // chunkFileNames returns file names of all session chunk files | [
"chunkFileNames",
"returns",
"file",
"names",
"of",
"all",
"session",
"chunk",
"files"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L469-L475 | train |
gravitational/teleport | lib/events/auditlog.go | createOrGetDownload | func (l *AuditLog) createOrGetDownload(path string) (context.Context, context.CancelFunc) {
l.Lock()
defer l.Unlock()
ctx, ok := l.activeDownloads[path]
if ok {
return ctx, nil
}
ctx, cancel := context.WithCancel(context.TODO())
l.activeDownloads[path] = ctx
return ctx, func() {
cancel()
l.Lock()
defer ... | go | func (l *AuditLog) createOrGetDownload(path string) (context.Context, context.CancelFunc) {
l.Lock()
defer l.Unlock()
ctx, ok := l.activeDownloads[path]
if ok {
return ctx, nil
}
ctx, cancel := context.WithCancel(context.TODO())
l.activeDownloads[path] = ctx
return ctx, func() {
cancel()
l.Lock()
defer ... | [
"func",
"(",
"l",
"*",
"AuditLog",
")",
"createOrGetDownload",
"(",
"path",
"string",
")",
"(",
"context",
".",
"Context",
",",
"context",
".",
"CancelFunc",
")",
"{",
"l",
".",
"Lock",
"(",
")",
"\n",
"defer",
"l",
".",
"Unlock",
"(",
")",
"\n",
"... | // createOrGetDownload creates a new download sync entry for a given session,
// if there is no active download in progress, or returns an existing one.
// if the new context has been created, cancel function is returned as a
// second argument. Caller should call this function to signal that download has been
// compl... | [
"createOrGetDownload",
"creates",
"a",
"new",
"download",
"sync",
"entry",
"for",
"a",
"given",
"session",
"if",
"there",
"is",
"no",
"active",
"download",
"in",
"progress",
"or",
"returns",
"an",
"existing",
"one",
".",
"if",
"the",
"new",
"context",
"has",... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L560-L575 | train |
gravitational/teleport | lib/events/auditlog.go | GetSessionChunk | func (l *AuditLog) GetSessionChunk(namespace string, sid session.ID, offsetBytes, maxBytes int) ([]byte, error) {
if l.UploadHandler != nil {
if err := l.downloadSession(namespace, sid); err != nil {
return nil, trace.Wrap(err)
}
}
var data []byte
for {
out, err := l.getSessionChunk(namespace, sid, offsetB... | go | func (l *AuditLog) GetSessionChunk(namespace string, sid session.ID, offsetBytes, maxBytes int) ([]byte, error) {
if l.UploadHandler != nil {
if err := l.downloadSession(namespace, sid); err != nil {
return nil, trace.Wrap(err)
}
}
var data []byte
for {
out, err := l.getSessionChunk(namespace, sid, offsetB... | [
"func",
"(",
"l",
"*",
"AuditLog",
")",
"GetSessionChunk",
"(",
"namespace",
"string",
",",
"sid",
"session",
".",
"ID",
",",
"offsetBytes",
",",
"maxBytes",
"int",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"l",
".",
"UploadHandler",
... | // GetSessionChunk returns a reader which console and web clients request
// to receive a live stream of a given session. The reader allows access to a
// session stream range from offsetBytes to offsetBytes+maxBytes | [
"GetSessionChunk",
"returns",
"a",
"reader",
"which",
"console",
"and",
"web",
"clients",
"request",
"to",
"receive",
"a",
"live",
"stream",
"of",
"a",
"given",
"session",
".",
"The",
"reader",
"allows",
"access",
"to",
"a",
"session",
"stream",
"range",
"fr... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L646-L668 | train |
gravitational/teleport | lib/events/auditlog.go | EmitAuditEvent | func (l *AuditLog) EmitAuditEvent(event Event, fields EventFields) error {
// If an external logger has been set, use it as the emitter, otherwise
// fallback to the local disk based emitter.
var emitAuditEvent func(event Event, fields EventFields) error
if l.ExternalLog != nil {
emitAuditEvent = l.ExternalLog.Em... | go | func (l *AuditLog) EmitAuditEvent(event Event, fields EventFields) error {
// If an external logger has been set, use it as the emitter, otherwise
// fallback to the local disk based emitter.
var emitAuditEvent func(event Event, fields EventFields) error
if l.ExternalLog != nil {
emitAuditEvent = l.ExternalLog.Em... | [
"func",
"(",
"l",
"*",
"AuditLog",
")",
"EmitAuditEvent",
"(",
"event",
"Event",
",",
"fields",
"EventFields",
")",
"error",
"{",
"// If an external logger has been set, use it as the emitter, otherwise",
"// fallback to the local disk based emitter.",
"var",
"emitAuditEvent",
... | // EmitAuditEvent adds a new event to the log. If emitting fails, a Prometheus
// counter is incremented. | [
"EmitAuditEvent",
"adds",
"a",
"new",
"event",
"to",
"the",
"log",
".",
"If",
"emitting",
"fails",
"a",
"Prometheus",
"counter",
"is",
"incremented",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L879-L898 | train |
gravitational/teleport | lib/events/auditlog.go | emitEvent | func (l *AuditLog) emitEvent(e AuditLogEvent) {
if l.EventsC == nil {
return
}
select {
case l.EventsC <- &e:
return
default:
l.Warningf("Blocked on the events channel.")
}
} | go | func (l *AuditLog) emitEvent(e AuditLogEvent) {
if l.EventsC == nil {
return
}
select {
case l.EventsC <- &e:
return
default:
l.Warningf("Blocked on the events channel.")
}
} | [
"func",
"(",
"l",
"*",
"AuditLog",
")",
"emitEvent",
"(",
"e",
"AuditLogEvent",
")",
"{",
"if",
"l",
".",
"EventsC",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"select",
"{",
"case",
"l",
".",
"EventsC",
"<-",
"&",
"e",
":",
"return",
"\n",
"de... | // emitEvent emits event for test purposes | [
"emitEvent",
"emits",
"event",
"for",
"test",
"purposes"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L901-L911 | train |
gravitational/teleport | lib/events/auditlog.go | auditDirs | func (l *AuditLog) auditDirs() ([]string, error) {
authServers, err := l.getAuthServers()
if err != nil {
return nil, trace.Wrap(err)
}
var out []string
for _, serverID := range authServers {
out = append(out, filepath.Join(l.DataDir, serverID))
}
return out, nil
} | go | func (l *AuditLog) auditDirs() ([]string, error) {
authServers, err := l.getAuthServers()
if err != nil {
return nil, trace.Wrap(err)
}
var out []string
for _, serverID := range authServers {
out = append(out, filepath.Join(l.DataDir, serverID))
}
return out, nil
} | [
"func",
"(",
"l",
"*",
"AuditLog",
")",
"auditDirs",
"(",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"authServers",
",",
"err",
":=",
"l",
".",
"getAuthServers",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"tra... | // auditDirs returns directories used for audit log storage | [
"auditDirs",
"returns",
"directories",
"used",
"for",
"audit",
"log",
"storage"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L914-L925 | train |
gravitational/teleport | lib/events/auditlog.go | Close | func (l *AuditLog) Close() error {
if l.ExternalLog != nil {
if err := l.ExternalLog.Close(); err != nil {
log.Warningf("Close failure: %v", err)
}
}
l.cancel()
l.Lock()
defer l.Unlock()
if l.localLog != nil {
if err := l.localLog.Close(); err != nil {
log.Warningf("Close failure: %v", err)
}
l.l... | go | func (l *AuditLog) Close() error {
if l.ExternalLog != nil {
if err := l.ExternalLog.Close(); err != nil {
log.Warningf("Close failure: %v", err)
}
}
l.cancel()
l.Lock()
defer l.Unlock()
if l.localLog != nil {
if err := l.localLog.Close(); err != nil {
log.Warningf("Close failure: %v", err)
}
l.l... | [
"func",
"(",
"l",
"*",
"AuditLog",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"l",
".",
"ExternalLog",
"!=",
"nil",
"{",
"if",
"err",
":=",
"l",
".",
"ExternalLog",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
... | // Closes the audit log, which inluces closing all file handles and releasing
// all session loggers | [
"Closes",
"the",
"audit",
"log",
"which",
"inluces",
"closing",
"all",
"file",
"handles",
"and",
"releasing",
"all",
"session",
"loggers"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L955-L972 | train |
gravitational/teleport | lib/events/auditlog.go | periodicSpaceMonitor | func (l *AuditLog) periodicSpaceMonitor() {
ticker := time.NewTicker(defaults.DiskAlertInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
// Find out what percentage of disk space is used. If the syscall fails,
// emit that to prometheus as well.
usedPercent, err := percentUsed(l.DataDir)
... | go | func (l *AuditLog) periodicSpaceMonitor() {
ticker := time.NewTicker(defaults.DiskAlertInterval)
defer ticker.Stop()
for {
select {
case <-ticker.C:
// Find out what percentage of disk space is used. If the syscall fails,
// emit that to prometheus as well.
usedPercent, err := percentUsed(l.DataDir)
... | [
"func",
"(",
"l",
"*",
"AuditLog",
")",
"periodicSpaceMonitor",
"(",
")",
"{",
"ticker",
":=",
"time",
".",
"NewTicker",
"(",
"defaults",
".",
"DiskAlertInterval",
")",
"\n",
"defer",
"ticker",
".",
"Stop",
"(",
")",
"\n\n",
"for",
"{",
"select",
"{",
... | // periodicSpaceMonitor run forever monitoring how much disk space has been
// used on disk. Values are emitted to a Prometheus gauge. | [
"periodicSpaceMonitor",
"run",
"forever",
"monitoring",
"how",
"much",
"disk",
"space",
"has",
"been",
"used",
"on",
"disk",
".",
"Values",
"are",
"emitted",
"to",
"a",
"Prometheus",
"gauge",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/events/auditlog.go#L992-L1019 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | New | func New(params legacy.Params) (*Backend, error) {
rootDir := params.GetString("path")
if rootDir == "" {
rootDir = params.GetString("data_dir")
}
if rootDir == "" {
return nil, trace.BadParameter("filesystem backend: 'path' is not set")
}
// Ensure that the path to the root directory exists.
err := os.Mkdi... | go | func New(params legacy.Params) (*Backend, error) {
rootDir := params.GetString("path")
if rootDir == "" {
rootDir = params.GetString("data_dir")
}
if rootDir == "" {
return nil, trace.BadParameter("filesystem backend: 'path' is not set")
}
// Ensure that the path to the root directory exists.
err := os.Mkdi... | [
"func",
"New",
"(",
"params",
"legacy",
".",
"Params",
")",
"(",
"*",
"Backend",
",",
"error",
")",
"{",
"rootDir",
":=",
"params",
".",
"GetString",
"(",
"\"",
"\"",
")",
"\n",
"if",
"rootDir",
"==",
"\"",
"\"",
"{",
"rootDir",
"=",
"params",
".",... | // New creates a new instance of a directory based backend that implements
// backend.Backend. | [
"New",
"creates",
"a",
"new",
"instance",
"of",
"a",
"directory",
"based",
"backend",
"that",
"implements",
"backend",
".",
"Backend",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L77-L111 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | GetKeys | func (bk *Backend) GetKeys(bucket []string) ([]string, error) {
// Get all the key/value pairs for this bucket.
items, err := bk.GetItems(bucket)
if err != nil {
return nil, trace.Wrap(err)
}
// Return only the keys, the keys are already sorted by GetItems.
keys := make([]string, len(items))
for i, e := range... | go | func (bk *Backend) GetKeys(bucket []string) ([]string, error) {
// Get all the key/value pairs for this bucket.
items, err := bk.GetItems(bucket)
if err != nil {
return nil, trace.Wrap(err)
}
// Return only the keys, the keys are already sorted by GetItems.
keys := make([]string, len(items))
for i, e := range... | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"GetKeys",
"(",
"bucket",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"// Get all the key/value pairs for this bucket.",
"items",
",",
"err",
":=",
"bk",
".",
"GetItems",
"(",
"bucket",
... | // GetKeys returns a list of keys for a given bucket. | [
"GetKeys",
"returns",
"a",
"list",
"of",
"keys",
"for",
"a",
"given",
"bucket",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L119-L133 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | GetVal | func (bk *Backend) GetVal(bucket []string, key string) ([]byte, error) {
// Open the bucket to work on the items.
b, err := bk.openBucket(bk.flatten(bucket), os.O_RDWR)
if err != nil {
// GetVal on a bucket needs to return trace.BadParameter. If opening the
// bucket failed a partial match up to a bucket may sti... | go | func (bk *Backend) GetVal(bucket []string, key string) ([]byte, error) {
// Open the bucket to work on the items.
b, err := bk.openBucket(bk.flatten(bucket), os.O_RDWR)
if err != nil {
// GetVal on a bucket needs to return trace.BadParameter. If opening the
// bucket failed a partial match up to a bucket may sti... | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"GetVal",
"(",
"bucket",
"[",
"]",
"string",
",",
"key",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"// Open the bucket to work on the items.",
"b",
",",
"err",
":=",
"bk",
".",
"openBucket",
"... | // GetVal return a value for a given key in the bucket | [
"GetVal",
"return",
"a",
"value",
"for",
"a",
"given",
"key",
"in",
"the",
"bucket"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L327-L374 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | CompareAndSwapVal | func (bk *Backend) CompareAndSwapVal(bucket []string, key string, val []byte, prevVal []byte, ttl time.Duration) error {
// Open the bucket to work on the items.
b, err := bk.openBucket(bk.flatten(bucket), os.O_CREATE|os.O_RDWR)
if err != nil {
er := trace.ConvertSystemError(err)
if trace.IsNotFound(er) {
ret... | go | func (bk *Backend) CompareAndSwapVal(bucket []string, key string, val []byte, prevVal []byte, ttl time.Duration) error {
// Open the bucket to work on the items.
b, err := bk.openBucket(bk.flatten(bucket), os.O_CREATE|os.O_RDWR)
if err != nil {
er := trace.ConvertSystemError(err)
if trace.IsNotFound(er) {
ret... | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"CompareAndSwapVal",
"(",
"bucket",
"[",
"]",
"string",
",",
"key",
"string",
",",
"val",
"[",
"]",
"byte",
",",
"prevVal",
"[",
"]",
"byte",
",",
"ttl",
"time",
".",
"Duration",
")",
"error",
"{",
"// Open the... | // CompareAndSwapVal compares and swap values in atomic operation | [
"CompareAndSwapVal",
"compares",
"and",
"swap",
"values",
"in",
"atomic",
"operation"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L377-L406 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | DeleteKey | func (bk *Backend) DeleteKey(bucket []string, key string) error {
// Open the bucket to work on the items.
b, err := bk.openBucket(bk.flatten(bucket), os.O_RDWR)
if err != nil {
return trace.Wrap(err)
}
defer b.Close()
// If the key doesn't exist, return trace.NotFound.
_, ok := b.getItem(key)
if !ok {
ret... | go | func (bk *Backend) DeleteKey(bucket []string, key string) error {
// Open the bucket to work on the items.
b, err := bk.openBucket(bk.flatten(bucket), os.O_RDWR)
if err != nil {
return trace.Wrap(err)
}
defer b.Close()
// If the key doesn't exist, return trace.NotFound.
_, ok := b.getItem(key)
if !ok {
ret... | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"DeleteKey",
"(",
"bucket",
"[",
"]",
"string",
",",
"key",
"string",
")",
"error",
"{",
"// Open the bucket to work on the items.",
"b",
",",
"err",
":=",
"bk",
".",
"openBucket",
"(",
"bk",
".",
"flatten",
"(",
"... | // DeleteKey deletes a key in a bucket. | [
"DeleteKey",
"deletes",
"a",
"key",
"in",
"a",
"bucket",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L409-L427 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | DeleteBucket | func (bk *Backend) DeleteBucket(parent []string, bucket string) error {
fullBucket := append(parent, bucket)
err := os.Remove(bk.flatten(fullBucket))
if err != nil {
return trace.ConvertSystemError(err)
}
return nil
} | go | func (bk *Backend) DeleteBucket(parent []string, bucket string) error {
fullBucket := append(parent, bucket)
err := os.Remove(bk.flatten(fullBucket))
if err != nil {
return trace.ConvertSystemError(err)
}
return nil
} | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"DeleteBucket",
"(",
"parent",
"[",
"]",
"string",
",",
"bucket",
"string",
")",
"error",
"{",
"fullBucket",
":=",
"append",
"(",
"parent",
",",
"bucket",
")",
"\n\n",
"err",
":=",
"os",
".",
"Remove",
"(",
"bk... | // DeleteBucket deletes the bucket by a given path. | [
"DeleteBucket",
"deletes",
"the",
"bucket",
"by",
"a",
"given",
"path",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L430-L439 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | AcquireLock | func (bk *Backend) AcquireLock(token string, ttl time.Duration) (err error) {
bk.log.Debugf("AcquireLock(%s)", token)
if err = legacy.ValidateLockTTL(ttl); err != nil {
return trace.Wrap(err)
}
bucket := []string{locksBucket}
for {
// GetVal will clear TTL on a lock
bk.GetVal(bucket, token)
// CreateVal... | go | func (bk *Backend) AcquireLock(token string, ttl time.Duration) (err error) {
bk.log.Debugf("AcquireLock(%s)", token)
if err = legacy.ValidateLockTTL(ttl); err != nil {
return trace.Wrap(err)
}
bucket := []string{locksBucket}
for {
// GetVal will clear TTL on a lock
bk.GetVal(bucket, token)
// CreateVal... | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"AcquireLock",
"(",
"token",
"string",
",",
"ttl",
"time",
".",
"Duration",
")",
"(",
"err",
"error",
")",
"{",
"bk",
".",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"token",
")",
"\n\n",
"if",
"err",
"=",... | // AcquireLock grabs a lock that will be released automatically in TTL. | [
"AcquireLock",
"grabs",
"a",
"lock",
"that",
"will",
"be",
"released",
"automatically",
"in",
"TTL",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L442-L467 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | ReleaseLock | func (bk *Backend) ReleaseLock(token string) (err error) {
bk.log.Debugf("ReleaseLock(%s)", token)
if err = bk.DeleteKey([]string{locksBucket}, token); err != nil {
if !os.IsNotExist(err) {
return trace.ConvertSystemError(err)
}
}
return nil
} | go | func (bk *Backend) ReleaseLock(token string) (err error) {
bk.log.Debugf("ReleaseLock(%s)", token)
if err = bk.DeleteKey([]string{locksBucket}, token); err != nil {
if !os.IsNotExist(err) {
return trace.ConvertSystemError(err)
}
}
return nil
} | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"ReleaseLock",
"(",
"token",
"string",
")",
"(",
"err",
"error",
")",
"{",
"bk",
".",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"token",
")",
"\n\n",
"if",
"err",
"=",
"bk",
".",
"DeleteKey",
"(",
"[",
... | // ReleaseLock forces lock release before TTL. | [
"ReleaseLock",
"forces",
"lock",
"release",
"before",
"TTL",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L470-L479 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | pathToBucket | func (bk *Backend) pathToBucket(bucket string) string {
return filepath.Join(bk.rootDir, bucket)
} | go | func (bk *Backend) pathToBucket(bucket string) string {
return filepath.Join(bk.rootDir, bucket)
} | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"pathToBucket",
"(",
"bucket",
"string",
")",
"string",
"{",
"return",
"filepath",
".",
"Join",
"(",
"bk",
".",
"rootDir",
",",
"bucket",
")",
"\n",
"}"
] | // pathToBucket prepends the root directory to the bucket returning the full
// path to the bucket on the filesystem. | [
"pathToBucket",
"prepends",
"the",
"root",
"directory",
"to",
"the",
"bucket",
"returning",
"the",
"full",
"path",
"to",
"the",
"bucket",
"on",
"the",
"filesystem",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L483-L485 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | decodeBucket | func decodeBucket(bucket string) ([]string, error) {
decoded, err := url.QueryUnescape(bucket)
if err != nil {
return nil, trace.Wrap(err)
}
return filepath.SplitList(decoded), nil
} | go | func decodeBucket(bucket string) ([]string, error) {
decoded, err := url.QueryUnescape(bucket)
if err != nil {
return nil, trace.Wrap(err)
}
return filepath.SplitList(decoded), nil
} | [
"func",
"decodeBucket",
"(",
"bucket",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"decoded",
",",
"err",
":=",
"url",
".",
"QueryUnescape",
"(",
"bucket",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trace",
... | // decodeBucket decodes bucket into parts of path | [
"decodeBucket",
"decodes",
"bucket",
"into",
"parts",
"of",
"path"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L488-L494 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | isExpired | func (bk *Backend) isExpired(bv bucketItem) bool {
if bv.ExpiryTime.IsZero() {
return false
}
return bk.Clock().Now().After(bv.ExpiryTime)
} | go | func (bk *Backend) isExpired(bv bucketItem) bool {
if bv.ExpiryTime.IsZero() {
return false
}
return bk.Clock().Now().After(bv.ExpiryTime)
} | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"isExpired",
"(",
"bv",
"bucketItem",
")",
"bool",
"{",
"if",
"bv",
".",
"ExpiryTime",
".",
"IsZero",
"(",
")",
"{",
"return",
"false",
"\n",
"}",
"\n",
"return",
"bk",
".",
"Clock",
"(",
")",
".",
"Now",
"... | // isExpired checks if the bucket item is expired or not. | [
"isExpired",
"checks",
"if",
"the",
"bucket",
"item",
"is",
"expired",
"or",
"not",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L509-L514 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | openBucket | func (bk *Backend) openBucket(prefix string, openFlag int) (*bucket, error) {
// Open bucket with requested flags.
file, err := os.OpenFile(prefix, openFlag, defaultFileMode)
if err != nil {
return nil, trace.ConvertSystemError(err)
}
// Lock the bucket so no one else can access it.
if err := utils.FSWriteLock... | go | func (bk *Backend) openBucket(prefix string, openFlag int) (*bucket, error) {
// Open bucket with requested flags.
file, err := os.OpenFile(prefix, openFlag, defaultFileMode)
if err != nil {
return nil, trace.ConvertSystemError(err)
}
// Lock the bucket so no one else can access it.
if err := utils.FSWriteLock... | [
"func",
"(",
"bk",
"*",
"Backend",
")",
"openBucket",
"(",
"prefix",
"string",
",",
"openFlag",
"int",
")",
"(",
"*",
"bucket",
",",
"error",
")",
"{",
"// Open bucket with requested flags.",
"file",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"prefix",
... | // openBucket will open a file, lock it, and then read in all the items in
// the bucket. | [
"openBucket",
"will",
"open",
"a",
"file",
"lock",
"it",
"and",
"then",
"read",
"in",
"all",
"the",
"items",
"in",
"the",
"bucket",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L543-L566 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | readBucket | func readBucket(f *os.File) (map[string]bucketItem, error) {
// If the file is empty, return an empty bucket.
ok, err := isEmpty(f)
if err != nil {
return nil, trace.Wrap(err)
}
if ok {
return map[string]bucketItem{}, nil
}
// The file is not empty, read it into a map.
var items map[string]bucketItem
byte... | go | func readBucket(f *os.File) (map[string]bucketItem, error) {
// If the file is empty, return an empty bucket.
ok, err := isEmpty(f)
if err != nil {
return nil, trace.Wrap(err)
}
if ok {
return map[string]bucketItem{}, nil
}
// The file is not empty, read it into a map.
var items map[string]bucketItem
byte... | [
"func",
"readBucket",
"(",
"f",
"*",
"os",
".",
"File",
")",
"(",
"map",
"[",
"string",
"]",
"bucketItem",
",",
"error",
")",
"{",
"// If the file is empty, return an empty bucket.",
"ok",
",",
"err",
":=",
"isEmpty",
"(",
"f",
")",
"\n",
"if",
"err",
"!... | // readBucket will read in the bucket and return a map of keys. The second return
// value returns true to false to indicate if the file was empty or not. | [
"readBucket",
"will",
"read",
"in",
"the",
"bucket",
"and",
"return",
"a",
"map",
"of",
"keys",
".",
"The",
"second",
"return",
"value",
"returns",
"true",
"to",
"false",
"to",
"indicate",
"if",
"the",
"file",
"was",
"empty",
"or",
"not",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L617-L639 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | writeBucket | func writeBucket(f *os.File, items map[string]bucketItem) error {
// Marshal items to disk format.
bytes, err := json.Marshal(items)
if err != nil {
return trace.Wrap(err)
}
// Truncate the file.
if _, err := f.Seek(0, 0); err != nil {
return trace.ConvertSystemError(err)
}
if err := f.Truncate(0); err != ... | go | func writeBucket(f *os.File, items map[string]bucketItem) error {
// Marshal items to disk format.
bytes, err := json.Marshal(items)
if err != nil {
return trace.Wrap(err)
}
// Truncate the file.
if _, err := f.Seek(0, 0); err != nil {
return trace.ConvertSystemError(err)
}
if err := f.Truncate(0); err != ... | [
"func",
"writeBucket",
"(",
"f",
"*",
"os",
".",
"File",
",",
"items",
"map",
"[",
"string",
"]",
"bucketItem",
")",
"error",
"{",
"// Marshal items to disk format.",
"bytes",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"items",
")",
"\n",
"if",
"err"... | // writeBucket will truncate the file and write out the items to the file f. | [
"writeBucket",
"will",
"truncate",
"the",
"file",
"and",
"write",
"out",
"the",
"items",
"to",
"the",
"file",
"f",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L642-L664 | train |
gravitational/teleport | lib/backend/legacy/dir/impl.go | isEmpty | func isEmpty(f *os.File) (bool, error) {
fi, err := f.Stat()
if err != nil {
return false, trace.Wrap(err)
}
if fi.Size() > 0 {
return false, nil
}
return true, nil
} | go | func isEmpty(f *os.File) (bool, error) {
fi, err := f.Stat()
if err != nil {
return false, trace.Wrap(err)
}
if fi.Size() > 0 {
return false, nil
}
return true, nil
} | [
"func",
"isEmpty",
"(",
"f",
"*",
"os",
".",
"File",
")",
"(",
"bool",
",",
"error",
")",
"{",
"fi",
",",
"err",
":=",
"f",
".",
"Stat",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
",",
"trace",
".",
"Wrap",
"(",
"err",
... | // isEmpty checks if the file is empty or not. | [
"isEmpty",
"checks",
"if",
"the",
"file",
"is",
"empty",
"or",
"not",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/legacy/dir/impl.go#L667-L678 | train |
gravitational/teleport | lib/backend/memory/item.go | Less | func (i *btreeItem) Less(iother btree.Item) bool {
switch other := iother.(type) {
case *btreeItem:
return bytes.Compare(i.Key, other.Key) < 0
case *prefixItem:
return !iother.Less(i)
default:
return false
}
} | go | func (i *btreeItem) Less(iother btree.Item) bool {
switch other := iother.(type) {
case *btreeItem:
return bytes.Compare(i.Key, other.Key) < 0
case *prefixItem:
return !iother.Less(i)
default:
return false
}
} | [
"func",
"(",
"i",
"*",
"btreeItem",
")",
"Less",
"(",
"iother",
"btree",
".",
"Item",
")",
"bool",
"{",
"switch",
"other",
":=",
"iother",
".",
"(",
"type",
")",
"{",
"case",
"*",
"btreeItem",
":",
"return",
"bytes",
".",
"Compare",
"(",
"i",
".",
... | // Less is used for Btree operations,
// returns true if item is less than the other one | [
"Less",
"is",
"used",
"for",
"Btree",
"operations",
"returns",
"true",
"if",
"item",
"is",
"less",
"than",
"the",
"other",
"one"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/memory/item.go#L37-L46 | train |
gravitational/teleport | lib/backend/memory/item.go | Less | func (p *prefixItem) Less(iother btree.Item) bool {
other := iother.(*btreeItem)
if bytes.HasPrefix(other.Key, p.prefix) {
return false
}
return true
} | go | func (p *prefixItem) Less(iother btree.Item) bool {
other := iother.(*btreeItem)
if bytes.HasPrefix(other.Key, p.prefix) {
return false
}
return true
} | [
"func",
"(",
"p",
"*",
"prefixItem",
")",
"Less",
"(",
"iother",
"btree",
".",
"Item",
")",
"bool",
"{",
"other",
":=",
"iother",
".",
"(",
"*",
"btreeItem",
")",
"\n",
"if",
"bytes",
".",
"HasPrefix",
"(",
"other",
".",
"Key",
",",
"p",
".",
"pr... | // Less is used for Btree operations | [
"Less",
"is",
"used",
"for",
"Btree",
"operations"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/backend/memory/item.go#L55-L61 | train |
gravitational/teleport | lib/services/remotecluster.go | NewRemoteCluster | func NewRemoteCluster(name string) (RemoteCluster, error) {
return &RemoteClusterV3{
Kind: KindRemoteCluster,
Version: V3,
Metadata: Metadata{
Name: name,
Namespace: defaults.Namespace,
},
}, nil
} | go | func NewRemoteCluster(name string) (RemoteCluster, error) {
return &RemoteClusterV3{
Kind: KindRemoteCluster,
Version: V3,
Metadata: Metadata{
Name: name,
Namespace: defaults.Namespace,
},
}, nil
} | [
"func",
"NewRemoteCluster",
"(",
"name",
"string",
")",
"(",
"RemoteCluster",
",",
"error",
")",
"{",
"return",
"&",
"RemoteClusterV3",
"{",
"Kind",
":",
"KindRemoteCluster",
",",
"Version",
":",
"V3",
",",
"Metadata",
":",
"Metadata",
"{",
"Name",
":",
"n... | // NewRemoteCluster is a convenience wa to create a RemoteCluster resource. | [
"NewRemoteCluster",
"is",
"a",
"convenience",
"wa",
"to",
"create",
"a",
"RemoteCluster",
"resource",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/remotecluster.go#L50-L59 | train |
gravitational/teleport | lib/services/remotecluster.go | SetLastHeartbeat | func (c *RemoteClusterV3) SetLastHeartbeat(t time.Time) {
c.Status.LastHeartbeat = t
} | go | func (c *RemoteClusterV3) SetLastHeartbeat(t time.Time) {
c.Status.LastHeartbeat = t
} | [
"func",
"(",
"c",
"*",
"RemoteClusterV3",
")",
"SetLastHeartbeat",
"(",
"t",
"time",
".",
"Time",
")",
"{",
"c",
".",
"Status",
".",
"LastHeartbeat",
"=",
"t",
"\n",
"}"
] | // SetLastHeartbeat sets last heartbeat of the cluster | [
"SetLastHeartbeat",
"sets",
"last",
"heartbeat",
"of",
"the",
"cluster"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/remotecluster.go#L128-L130 | train |
gravitational/teleport | lib/services/remotecluster.go | String | func (r *RemoteClusterV3) String() string {
return fmt.Sprintf("RemoteCluster(%v, %v)", r.Metadata.Name, r.Status.Connection)
} | go | func (r *RemoteClusterV3) String() string {
return fmt.Sprintf("RemoteCluster(%v, %v)", r.Metadata.Name, r.Status.Connection)
} | [
"func",
"(",
"r",
"*",
"RemoteClusterV3",
")",
"String",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"r",
".",
"Metadata",
".",
"Name",
",",
"r",
".",
"Status",
".",
"Connection",
")",
"\n",
"}"
] | // String represents a human readable version of remote cluster settings. | [
"String",
"represents",
"a",
"human",
"readable",
"version",
"of",
"remote",
"cluster",
"settings",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/remotecluster.go#L173-L175 | train |
gravitational/teleport | lib/services/remotecluster.go | UnmarshalRemoteCluster | func UnmarshalRemoteCluster(bytes []byte, opts ...MarshalOption) (RemoteCluster, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
var cluster RemoteClusterV3
if len(bytes) == 0 {
return nil, trace.BadParameter("missing resource data")
}
if cfg.SkipValidation {
err ... | go | func UnmarshalRemoteCluster(bytes []byte, opts ...MarshalOption) (RemoteCluster, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
var cluster RemoteClusterV3
if len(bytes) == 0 {
return nil, trace.BadParameter("missing resource data")
}
if cfg.SkipValidation {
err ... | [
"func",
"UnmarshalRemoteCluster",
"(",
"bytes",
"[",
"]",
"byte",
",",
"opts",
"...",
"MarshalOption",
")",
"(",
"RemoteCluster",
",",
"error",
")",
"{",
"cfg",
",",
"err",
":=",
"collectOptions",
"(",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
... | // UnmarshalRemoteCluster unmarshals remote cluster from JSON or YAML. | [
"UnmarshalRemoteCluster",
"unmarshals",
"remote",
"cluster",
"from",
"JSON",
"or",
"YAML",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/remotecluster.go#L207-L237 | train |
gravitational/teleport | lib/services/remotecluster.go | MarshalRemoteCluster | func MarshalRemoteCluster(c RemoteCluster, opts ...MarshalOption) ([]byte, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
switch resource := c.(type) {
case *RemoteClusterV3:
if !cfg.PreserveResourceID {
// avoid modifying the original object
// to prevent unexpec... | go | func MarshalRemoteCluster(c RemoteCluster, opts ...MarshalOption) ([]byte, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
switch resource := c.(type) {
case *RemoteClusterV3:
if !cfg.PreserveResourceID {
// avoid modifying the original object
// to prevent unexpec... | [
"func",
"MarshalRemoteCluster",
"(",
"c",
"RemoteCluster",
",",
"opts",
"...",
"MarshalOption",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"cfg",
",",
"err",
":=",
"collectOptions",
"(",
"opts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"retur... | // MarshalRemoteCluster marshals remote cluster to JSON. | [
"MarshalRemoteCluster",
"marshals",
"remote",
"cluster",
"to",
"JSON",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/services/remotecluster.go#L240-L258 | train |
gravitational/teleport | lib/tlsca/ca.go | New | func New(certPEM, keyPEM []byte) (*CertAuthority, error) {
ca := &CertAuthority{}
var err error
ca.Cert, err = ParseCertificatePEM(certPEM)
if err != nil {
return nil, trace.Wrap(err)
}
if len(keyPEM) != 0 {
ca.Signer, err = ParsePrivateKeyPEM(keyPEM)
if err != nil {
return nil, trace.Wrap(err)
}
}
r... | go | func New(certPEM, keyPEM []byte) (*CertAuthority, error) {
ca := &CertAuthority{}
var err error
ca.Cert, err = ParseCertificatePEM(certPEM)
if err != nil {
return nil, trace.Wrap(err)
}
if len(keyPEM) != 0 {
ca.Signer, err = ParsePrivateKeyPEM(keyPEM)
if err != nil {
return nil, trace.Wrap(err)
}
}
r... | [
"func",
"New",
"(",
"certPEM",
",",
"keyPEM",
"[",
"]",
"byte",
")",
"(",
"*",
"CertAuthority",
",",
"error",
")",
"{",
"ca",
":=",
"&",
"CertAuthority",
"{",
"}",
"\n",
"var",
"err",
"error",
"\n",
"ca",
".",
"Cert",
",",
"err",
"=",
"ParseCertifi... | // New returns new CA from PEM encoded certificate and private
// key. Private Key is optional, if omitted CA won't be able to
// issue new certificates, only verify them | [
"New",
"returns",
"new",
"CA",
"from",
"PEM",
"encoded",
"certificate",
"and",
"private",
"key",
".",
"Private",
"Key",
"is",
"optional",
"if",
"omitted",
"CA",
"won",
"t",
"be",
"able",
"to",
"issue",
"new",
"certificates",
"only",
"verify",
"them"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/ca.go#L43-L57 | train |
gravitational/teleport | lib/tlsca/ca.go | Subject | func (id *Identity) Subject() pkix.Name {
subject := pkix.Name{
CommonName: id.Username,
}
subject.Organization = append([]string{}, id.Groups...)
subject.OrganizationalUnit = append([]string{}, id.Usage...)
subject.Locality = append([]string{}, id.Principals...)
subject.Province = append([]string{}, id.Kuberne... | go | func (id *Identity) Subject() pkix.Name {
subject := pkix.Name{
CommonName: id.Username,
}
subject.Organization = append([]string{}, id.Groups...)
subject.OrganizationalUnit = append([]string{}, id.Usage...)
subject.Locality = append([]string{}, id.Principals...)
subject.Province = append([]string{}, id.Kuberne... | [
"func",
"(",
"id",
"*",
"Identity",
")",
"Subject",
"(",
")",
"pkix",
".",
"Name",
"{",
"subject",
":=",
"pkix",
".",
"Name",
"{",
"CommonName",
":",
"id",
".",
"Username",
",",
"}",
"\n",
"subject",
".",
"Organization",
"=",
"append",
"(",
"[",
"]... | // Subject converts identity to X.509 subject name | [
"Subject",
"converts",
"identity",
"to",
"X",
".",
"509",
"subject",
"name"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/ca.go#L93-L102 | train |
gravitational/teleport | lib/tlsca/ca.go | FromSubject | func FromSubject(subject pkix.Name) (*Identity, error) {
i := &Identity{
Username: subject.CommonName,
Groups: subject.Organization,
Usage: subject.OrganizationalUnit,
Principals: subject.Locality,
KubernetesGroups: subject.Province,
}
if err := i.CheckAndSetDefaults(); e... | go | func FromSubject(subject pkix.Name) (*Identity, error) {
i := &Identity{
Username: subject.CommonName,
Groups: subject.Organization,
Usage: subject.OrganizationalUnit,
Principals: subject.Locality,
KubernetesGroups: subject.Province,
}
if err := i.CheckAndSetDefaults(); e... | [
"func",
"FromSubject",
"(",
"subject",
"pkix",
".",
"Name",
")",
"(",
"*",
"Identity",
",",
"error",
")",
"{",
"i",
":=",
"&",
"Identity",
"{",
"Username",
":",
"subject",
".",
"CommonName",
",",
"Groups",
":",
"subject",
".",
"Organization",
",",
"Usa... | // FromSubject returns identity from subject name | [
"FromSubject",
"returns",
"identity",
"from",
"subject",
"name"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/ca.go#L105-L117 | train |
gravitational/teleport | lib/tlsca/ca.go | GenerateCertificate | func (ca *CertAuthority) GenerateCertificate(req CertificateRequest) ([]byte, error) {
if err := req.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
return n... | go | func (ca *CertAuthority) GenerateCertificate(req CertificateRequest) ([]byte, error) {
if err := req.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
return n... | [
"func",
"(",
"ca",
"*",
"CertAuthority",
")",
"GenerateCertificate",
"(",
"req",
"CertificateRequest",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"err",
":=",
"req",
".",
"CheckAndSetDefaults",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"re... | // GenerateCertificate generates certificate from request | [
"GenerateCertificate",
"generates",
"certificate",
"from",
"request"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/tlsca/ca.go#L152-L200 | train |
gravitational/teleport | lib/srv/termhandlers.go | HandleExec | func (t *TermHandlers) HandleExec(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
execRequest, err := parseExecRequest(req, ctx)
if err != nil {
return trace.Wrap(err)
}
// a terminal has been previously allocate for this command.
// run this inside an interactive session
if ctx.GetTerm() != nil ... | go | func (t *TermHandlers) HandleExec(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
execRequest, err := parseExecRequest(req, ctx)
if err != nil {
return trace.Wrap(err)
}
// a terminal has been previously allocate for this command.
// run this inside an interactive session
if ctx.GetTerm() != nil ... | [
"func",
"(",
"t",
"*",
"TermHandlers",
")",
"HandleExec",
"(",
"ch",
"ssh",
".",
"Channel",
",",
"req",
"*",
"ssh",
".",
"Request",
",",
"ctx",
"*",
"ServerContext",
")",
"error",
"{",
"execRequest",
",",
"err",
":=",
"parseExecRequest",
"(",
"req",
",... | // HandleExec handles requests of type "exec" which can execute with or
// without a TTY. Result of execution is propagated back on the ExecResult
// channel of the context. | [
"HandleExec",
"handles",
"requests",
"of",
"type",
"exec",
"which",
"can",
"execute",
"with",
"or",
"without",
"a",
"TTY",
".",
"Result",
"of",
"execution",
"is",
"propagated",
"back",
"on",
"the",
"ExecResult",
"channel",
"of",
"the",
"context",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/termhandlers.go#L39-L119 | train |
gravitational/teleport | lib/srv/termhandlers.go | HandlePTYReq | func (t *TermHandlers) HandlePTYReq(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
// parse and extract the requested window size of the pty
ptyRequest, err := parsePTYReq(req)
if err != nil {
return trace.Wrap(err)
}
termModes, err := ptyRequest.TerminalModes()
if err != nil {
return trace.Wr... | go | func (t *TermHandlers) HandlePTYReq(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
// parse and extract the requested window size of the pty
ptyRequest, err := parsePTYReq(req)
if err != nil {
return trace.Wrap(err)
}
termModes, err := ptyRequest.TerminalModes()
if err != nil {
return trace.Wr... | [
"func",
"(",
"t",
"*",
"TermHandlers",
")",
"HandlePTYReq",
"(",
"ch",
"ssh",
".",
"Channel",
",",
"req",
"*",
"ssh",
".",
"Request",
",",
"ctx",
"*",
"ServerContext",
")",
"error",
"{",
"// parse and extract the requested window size of the pty",
"ptyRequest",
... | // HandlePTYReq handles requests of type "pty-req" which allocate a TTY for
// "exec" or "shell" requests. The "pty-req" includes the size of the TTY as
// well as the terminal type requested. | [
"HandlePTYReq",
"handles",
"requests",
"of",
"type",
"pty",
"-",
"req",
"which",
"allocate",
"a",
"TTY",
"for",
"exec",
"or",
"shell",
"requests",
".",
"The",
"pty",
"-",
"req",
"includes",
"the",
"size",
"of",
"the",
"TTY",
"as",
"well",
"as",
"the",
... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/termhandlers.go#L124-L162 | train |
gravitational/teleport | lib/srv/termhandlers.go | HandleShell | func (t *TermHandlers) HandleShell(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
var err error
// creating an empty exec request implies a interactive shell was requested
ctx.ExecRequest, err = NewExecRequest(ctx, "")
if err != nil {
return trace.Wrap(err)
}
if err := t.SessionRegistry.OpenSes... | go | func (t *TermHandlers) HandleShell(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
var err error
// creating an empty exec request implies a interactive shell was requested
ctx.ExecRequest, err = NewExecRequest(ctx, "")
if err != nil {
return trace.Wrap(err)
}
if err := t.SessionRegistry.OpenSes... | [
"func",
"(",
"t",
"*",
"TermHandlers",
")",
"HandleShell",
"(",
"ch",
"ssh",
".",
"Channel",
",",
"req",
"*",
"ssh",
".",
"Request",
",",
"ctx",
"*",
"ServerContext",
")",
"error",
"{",
"var",
"err",
"error",
"\n\n",
"// creating an empty exec request implie... | // HandleShell handles requests of type "shell" which request a interactive
// shell be created within a TTY. | [
"HandleShell",
"handles",
"requests",
"of",
"type",
"shell",
"which",
"request",
"a",
"interactive",
"shell",
"be",
"created",
"within",
"a",
"TTY",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/termhandlers.go#L166-L180 | train |
gravitational/teleport | lib/srv/termhandlers.go | HandleWinChange | func (t *TermHandlers) HandleWinChange(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
params, err := parseWinChange(req)
if err != nil {
return trace.Wrap(err)
}
// Update any other members in the party that the window size has changed
// and to update their terminal windows accordingly.
err = t... | go | func (t *TermHandlers) HandleWinChange(ch ssh.Channel, req *ssh.Request, ctx *ServerContext) error {
params, err := parseWinChange(req)
if err != nil {
return trace.Wrap(err)
}
// Update any other members in the party that the window size has changed
// and to update their terminal windows accordingly.
err = t... | [
"func",
"(",
"t",
"*",
"TermHandlers",
")",
"HandleWinChange",
"(",
"ch",
"ssh",
".",
"Channel",
",",
"req",
"*",
"ssh",
".",
"Request",
",",
"ctx",
"*",
"ServerContext",
")",
"error",
"{",
"params",
",",
"err",
":=",
"parseWinChange",
"(",
"req",
")",... | // HandleWinChange handles requests of type "window-change" which update the
// size of the PTY running on the server and update any other members in the
// party. | [
"HandleWinChange",
"handles",
"requests",
"of",
"type",
"window",
"-",
"change",
"which",
"update",
"the",
"size",
"of",
"the",
"PTY",
"running",
"on",
"the",
"server",
"and",
"update",
"any",
"other",
"members",
"in",
"the",
"party",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/srv/termhandlers.go#L185-L199 | train |
gravitational/teleport | lib/reversetunnel/srv.go | NewServer | func NewServer(cfg Config) (Server, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
ctx, cancel := context.WithCancel(cfg.Context)
srv := &server{
Config: cfg,
localSites: []*localSite{},
remoteSites: []*remoteSite{},
localAuthClient: cfg.Loca... | go | func NewServer(cfg Config) (Server, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
ctx, cancel := context.WithCancel(cfg.Context)
srv := &server{
Config: cfg,
localSites: []*localSite{},
remoteSites: []*remoteSite{},
localAuthClient: cfg.Loca... | [
"func",
"NewServer",
"(",
"cfg",
"Config",
")",
"(",
"Server",
",",
"error",
")",
"{",
"if",
"err",
":=",
"cfg",
".",
"CheckAndSetDefaults",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trace",
".",
"Wrap",
"(",
"err",
")",
"\n",
... | // NewServer creates and returns a reverse tunnel server which is fully
// initialized but hasn't been started yet | [
"NewServer",
"creates",
"and",
"returns",
"a",
"reverse",
"tunnel",
"server",
"which",
"is",
"fully",
"initialized",
"but",
"hasn",
"t",
"been",
"started",
"yet"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/srv.go#L216-L268 | train |
gravitational/teleport | lib/reversetunnel/srv.go | disconnectClusters | func (s *server) disconnectClusters() error {
connectedRemoteClusters := s.getRemoteClusters()
if len(connectedRemoteClusters) == 0 {
return nil
}
remoteClusters, err := s.localAuthClient.GetRemoteClusters()
if err != nil {
return trace.Wrap(err)
}
remoteMap := remoteClustersMap(remoteClusters)
for _, clust... | go | func (s *server) disconnectClusters() error {
connectedRemoteClusters := s.getRemoteClusters()
if len(connectedRemoteClusters) == 0 {
return nil
}
remoteClusters, err := s.localAuthClient.GetRemoteClusters()
if err != nil {
return trace.Wrap(err)
}
remoteMap := remoteClustersMap(remoteClusters)
for _, clust... | [
"func",
"(",
"s",
"*",
"server",
")",
"disconnectClusters",
"(",
")",
"error",
"{",
"connectedRemoteClusters",
":=",
"s",
".",
"getRemoteClusters",
"(",
")",
"\n",
"if",
"len",
"(",
"connectedRemoteClusters",
")",
"==",
"0",
"{",
"return",
"nil",
"\n",
"}"... | // disconnectClusters disconnects reverse tunnel connections from remote clusters
// that were deleted from the the local cluster side and cleans up in memory objects.
// In this case all local trust has been deleted, so all the tunnel connections have to be dropped. | [
"disconnectClusters",
"disconnects",
"reverse",
"tunnel",
"connections",
"from",
"remote",
"clusters",
"that",
"were",
"deleted",
"from",
"the",
"the",
"local",
"cluster",
"side",
"and",
"cleans",
"up",
"in",
"memory",
"objects",
".",
"In",
"this",
"case",
"all"... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/srv.go#L281-L302 | train |
gravitational/teleport | lib/reversetunnel/srv.go | isHostAuthority | func (s *server) isHostAuthority(auth ssh.PublicKey, address string) bool {
keys, err := s.getTrustedCAKeys(services.HostCA)
if err != nil {
s.Errorf("failed to retrieve trusted keys, err: %v", err)
return false
}
for _, k := range keys {
if sshutils.KeysEqual(k, auth) {
return true
}
}
return false
} | go | func (s *server) isHostAuthority(auth ssh.PublicKey, address string) bool {
keys, err := s.getTrustedCAKeys(services.HostCA)
if err != nil {
s.Errorf("failed to retrieve trusted keys, err: %v", err)
return false
}
for _, k := range keys {
if sshutils.KeysEqual(k, auth) {
return true
}
}
return false
} | [
"func",
"(",
"s",
"*",
"server",
")",
"isHostAuthority",
"(",
"auth",
"ssh",
".",
"PublicKey",
",",
"address",
"string",
")",
"bool",
"{",
"keys",
",",
"err",
":=",
"s",
".",
"getTrustedCAKeys",
"(",
"services",
".",
"HostCA",
")",
"\n",
"if",
"err",
... | // isHostAuthority is called during checking the client key, to see if the signing
// key is the real host CA authority key. | [
"isHostAuthority",
"is",
"called",
"during",
"checking",
"the",
"client",
"key",
"to",
"see",
"if",
"the",
"signing",
"key",
"is",
"the",
"real",
"host",
"CA",
"authority",
"key",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/srv.go#L618-L630 | train |
gravitational/teleport | lib/reversetunnel/srv.go | isUserAuthority | func (s *server) isUserAuthority(auth ssh.PublicKey) bool {
keys, err := s.getTrustedCAKeys(services.UserCA)
if err != nil {
s.Errorf("failed to retrieve trusted keys, err: %v", err)
return false
}
for _, k := range keys {
if sshutils.KeysEqual(k, auth) {
return true
}
}
return false
} | go | func (s *server) isUserAuthority(auth ssh.PublicKey) bool {
keys, err := s.getTrustedCAKeys(services.UserCA)
if err != nil {
s.Errorf("failed to retrieve trusted keys, err: %v", err)
return false
}
for _, k := range keys {
if sshutils.KeysEqual(k, auth) {
return true
}
}
return false
} | [
"func",
"(",
"s",
"*",
"server",
")",
"isUserAuthority",
"(",
"auth",
"ssh",
".",
"PublicKey",
")",
"bool",
"{",
"keys",
",",
"err",
":=",
"s",
".",
"getTrustedCAKeys",
"(",
"services",
".",
"UserCA",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"s",
... | // isUserAuthority is called during checking the client key, to see if the signing
// key is the real user CA authority key. | [
"isUserAuthority",
"is",
"called",
"during",
"checking",
"the",
"client",
"key",
"to",
"see",
"if",
"the",
"signing",
"key",
"is",
"the",
"real",
"user",
"CA",
"authority",
"key",
"."
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/srv.go#L634-L646 | train |
gravitational/teleport | lib/reversetunnel/srv.go | checkHostCert | func (s *server) checkHostCert(logger *log.Entry, user string, clusterName string, cert *ssh.Certificate) error {
if cert.CertType != ssh.HostCert {
return trace.BadParameter("expected host cert, got wrong cert type: %d", cert.CertType)
}
// fetch keys of the certificate authority to check
// if there is a match... | go | func (s *server) checkHostCert(logger *log.Entry, user string, clusterName string, cert *ssh.Certificate) error {
if cert.CertType != ssh.HostCert {
return trace.BadParameter("expected host cert, got wrong cert type: %d", cert.CertType)
}
// fetch keys of the certificate authority to check
// if there is a match... | [
"func",
"(",
"s",
"*",
"server",
")",
"checkHostCert",
"(",
"logger",
"*",
"log",
".",
"Entry",
",",
"user",
"string",
",",
"clusterName",
"string",
",",
"cert",
"*",
"ssh",
".",
"Certificate",
")",
"error",
"{",
"if",
"cert",
".",
"CertType",
"!=",
... | // checkHostCert verifies that host certificate is signed
// by the recognized certificate authority | [
"checkHostCert",
"verifies",
"that",
"host",
"certificate",
"is",
"signed",
"by",
"the",
"recognized",
"certificate",
"authority"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/srv.go#L718-L751 | train |
gravitational/teleport | lib/reversetunnel/srv.go | GetSite | func (s *server) GetSite(name string) (RemoteSite, error) {
s.RLock()
defer s.RUnlock()
for i := range s.remoteSites {
if s.remoteSites[i].GetName() == name {
return s.remoteSites[i], nil
}
}
for i := range s.localSites {
if s.localSites[i].GetName() == name {
return s.localSites[i], nil
}
}
for i ... | go | func (s *server) GetSite(name string) (RemoteSite, error) {
s.RLock()
defer s.RUnlock()
for i := range s.remoteSites {
if s.remoteSites[i].GetName() == name {
return s.remoteSites[i], nil
}
}
for i := range s.localSites {
if s.localSites[i].GetName() == name {
return s.localSites[i], nil
}
}
for i ... | [
"func",
"(",
"s",
"*",
"server",
")",
"GetSite",
"(",
"name",
"string",
")",
"(",
"RemoteSite",
",",
"error",
")",
"{",
"s",
".",
"RLock",
"(",
")",
"\n",
"defer",
"s",
".",
"RUnlock",
"(",
")",
"\n",
"for",
"i",
":=",
"range",
"s",
".",
"remot... | // GetSite returns a RemoteSite. The first attempt is to find and return a
// remote site and that is what is returned if a remote remote agent has
// connected to this proxy. Next we loop over local sites and try and try and
// return a local site. If that fails, we return a cluster peer. This happens
// when you hit ... | [
"GetSite",
"returns",
"a",
"RemoteSite",
".",
"The",
"first",
"attempt",
"is",
"to",
"find",
"and",
"return",
"a",
"remote",
"site",
"and",
"that",
"is",
"what",
"is",
"returned",
"if",
"a",
"remote",
"remote",
"agent",
"has",
"connected",
"to",
"this",
... | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/srv.go#L855-L874 | train |
gravitational/teleport | lib/reversetunnel/srv.go | newRemoteSite | func newRemoteSite(srv *server, domainName string) (*remoteSite, error) {
connInfo, err := services.NewTunnelConnection(
fmt.Sprintf("%v-%v", srv.ID, domainName),
services.TunnelConnectionSpecV2{
ClusterName: domainName,
ProxyName: srv.ID,
LastHeartbeat: time.Now().UTC(),
},
)
if err != nil {
... | go | func newRemoteSite(srv *server, domainName string) (*remoteSite, error) {
connInfo, err := services.NewTunnelConnection(
fmt.Sprintf("%v-%v", srv.ID, domainName),
services.TunnelConnectionSpecV2{
ClusterName: domainName,
ProxyName: srv.ID,
LastHeartbeat: time.Now().UTC(),
},
)
if err != nil {
... | [
"func",
"newRemoteSite",
"(",
"srv",
"*",
"server",
",",
"domainName",
"string",
")",
"(",
"*",
"remoteSite",
",",
"error",
")",
"{",
"connInfo",
",",
"err",
":=",
"services",
".",
"NewTunnelConnection",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
... | // newRemoteSite helper creates and initializes 'remoteSite' instance | [
"newRemoteSite",
"helper",
"creates",
"and",
"initializes",
"remoteSite",
"instance"
] | d5243dbe8d36bba44bf640c08f1c49185ed2c8a4 | https://github.com/gravitational/teleport/blob/d5243dbe8d36bba44bf640c08f1c49185ed2c8a4/lib/reversetunnel/srv.go#L895-L956 | train |
tealeg/xlsx | xmlWorksheet.go | getExtent | func (mc *xlsxMergeCells) getExtent(cellRef string) (int, int, error) {
if mc == nil {
return 0, 0, nil
}
for _, cell := range mc.Cells {
if strings.HasPrefix(cell.Ref, cellRef+cellRangeChar) {
parts := strings.Split(cell.Ref, cellRangeChar)
startx, starty, err := GetCoordsFromCellIDString(parts[0])
if ... | go | func (mc *xlsxMergeCells) getExtent(cellRef string) (int, int, error) {
if mc == nil {
return 0, 0, nil
}
for _, cell := range mc.Cells {
if strings.HasPrefix(cell.Ref, cellRef+cellRangeChar) {
parts := strings.Split(cell.Ref, cellRangeChar)
startx, starty, err := GetCoordsFromCellIDString(parts[0])
if ... | [
"func",
"(",
"mc",
"*",
"xlsxMergeCells",
")",
"getExtent",
"(",
"cellRef",
"string",
")",
"(",
"int",
",",
"int",
",",
"error",
")",
"{",
"if",
"mc",
"==",
"nil",
"{",
"return",
"0",
",",
"0",
",",
"nil",
"\n",
"}",
"\n",
"for",
"_",
",",
"cel... | // Return the cartesian extent of a merged cell range from its origin
// cell (the closest merged cell to the to left of the sheet. | [
"Return",
"the",
"cartesian",
"extent",
"of",
"a",
"merged",
"cell",
"range",
"from",
"its",
"origin",
"cell",
"(",
"the",
"closest",
"merged",
"cell",
"to",
"the",
"to",
"left",
"of",
"the",
"sheet",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/xmlWorksheet.go#L312-L331 | train |
tealeg/xlsx | col.go | SetType | func (c *Col) SetType(cellType CellType) {
switch cellType {
case CellTypeString:
c.numFmt = builtInNumFmt[builtInNumFmtIndex_STRING]
case CellTypeNumeric:
c.numFmt = builtInNumFmt[builtInNumFmtIndex_INT]
case CellTypeBool:
c.numFmt = builtInNumFmt[builtInNumFmtIndex_GENERAL] //TEMP
case CellTypeInline:
c.... | go | func (c *Col) SetType(cellType CellType) {
switch cellType {
case CellTypeString:
c.numFmt = builtInNumFmt[builtInNumFmtIndex_STRING]
case CellTypeNumeric:
c.numFmt = builtInNumFmt[builtInNumFmtIndex_INT]
case CellTypeBool:
c.numFmt = builtInNumFmt[builtInNumFmtIndex_GENERAL] //TEMP
case CellTypeInline:
c.... | [
"func",
"(",
"c",
"*",
"Col",
")",
"SetType",
"(",
"cellType",
"CellType",
")",
"{",
"switch",
"cellType",
"{",
"case",
"CellTypeString",
":",
"c",
".",
"numFmt",
"=",
"builtInNumFmt",
"[",
"builtInNumFmtIndex_STRING",
"]",
"\n",
"case",
"CellTypeNumeric",
"... | // SetType will set the format string of a column based on the type that you want to set it to.
// This function does not really make a lot of sense. | [
"SetType",
"will",
"set",
"the",
"format",
"string",
"of",
"a",
"column",
"based",
"on",
"the",
"type",
"that",
"you",
"want",
"to",
"set",
"it",
"to",
".",
"This",
"function",
"does",
"not",
"really",
"make",
"a",
"lot",
"of",
"sense",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/col.go#L23-L42 | train |
tealeg/xlsx | col.go | SetDataValidation | func (c *Col) SetDataValidation(dd *xlsxCellDataValidation, start, end int) {
if end < 0 {
end = Excel2006MaxRowIndex
}
dd.minRow = start
dd.maxRow = end
tmpDD := make([]*xlsxCellDataValidation, 0)
for _, item := range c.DataValidation {
if item.maxRow < dd.minRow {
tmpDD = append(tmpDD, item) //No inter... | go | func (c *Col) SetDataValidation(dd *xlsxCellDataValidation, start, end int) {
if end < 0 {
end = Excel2006MaxRowIndex
}
dd.minRow = start
dd.maxRow = end
tmpDD := make([]*xlsxCellDataValidation, 0)
for _, item := range c.DataValidation {
if item.maxRow < dd.minRow {
tmpDD = append(tmpDD, item) //No inter... | [
"func",
"(",
"c",
"*",
"Col",
")",
"SetDataValidation",
"(",
"dd",
"*",
"xlsxCellDataValidation",
",",
"start",
",",
"end",
"int",
")",
"{",
"if",
"end",
"<",
"0",
"{",
"end",
"=",
"Excel2006MaxRowIndex",
"\n",
"}",
"\n\n",
"dd",
".",
"minRow",
"=",
... | // SetDataValidation set data validation with zero based start and end.
// Set end to -1 for all rows. | [
"SetDataValidation",
"set",
"data",
"validation",
"with",
"zero",
"based",
"start",
"and",
"end",
".",
"Set",
"end",
"to",
"-",
"1",
"for",
"all",
"rows",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/col.go#L56-L93 | train |
tealeg/xlsx | col.go | SetDataValidationWithStart | func (c *Col) SetDataValidationWithStart(dd *xlsxCellDataValidation, start int) {
c.SetDataValidation(dd, start, -1)
} | go | func (c *Col) SetDataValidationWithStart(dd *xlsxCellDataValidation, start int) {
c.SetDataValidation(dd, start, -1)
} | [
"func",
"(",
"c",
"*",
"Col",
")",
"SetDataValidationWithStart",
"(",
"dd",
"*",
"xlsxCellDataValidation",
",",
"start",
"int",
")",
"{",
"c",
".",
"SetDataValidation",
"(",
"dd",
",",
"start",
",",
"-",
"1",
")",
"\n",
"}"
] | // SetDataValidationWithStart set data validation with a zero basd start row.
// This will apply to the rest of the rest of the column. | [
"SetDataValidationWithStart",
"set",
"data",
"validation",
"with",
"a",
"zero",
"basd",
"start",
"row",
".",
"This",
"will",
"apply",
"to",
"the",
"rest",
"of",
"the",
"rest",
"of",
"the",
"column",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/col.go#L97-L99 | train |
tealeg/xlsx | stream_file_builder.go | NewStreamFileBuilder | func NewStreamFileBuilder(writer io.Writer) *StreamFileBuilder {
return &StreamFileBuilder{
zipWriter: zip.NewWriter(writer),
xlsxFile: NewFile(),
cellTypeToStyleIds: make(map[CellType]int),
maxStyleId: initMaxStyleId,
}
} | go | func NewStreamFileBuilder(writer io.Writer) *StreamFileBuilder {
return &StreamFileBuilder{
zipWriter: zip.NewWriter(writer),
xlsxFile: NewFile(),
cellTypeToStyleIds: make(map[CellType]int),
maxStyleId: initMaxStyleId,
}
} | [
"func",
"NewStreamFileBuilder",
"(",
"writer",
"io",
".",
"Writer",
")",
"*",
"StreamFileBuilder",
"{",
"return",
"&",
"StreamFileBuilder",
"{",
"zipWriter",
":",
"zip",
".",
"NewWriter",
"(",
"writer",
")",
",",
"xlsxFile",
":",
"NewFile",
"(",
")",
",",
... | // NewStreamFileBuilder creates an StreamFileBuilder that will write to the the provided io.writer | [
"NewStreamFileBuilder",
"creates",
"an",
"StreamFileBuilder",
"that",
"will",
"write",
"to",
"the",
"the",
"provided",
"io",
".",
"writer"
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L58-L65 | train |
tealeg/xlsx | stream_file_builder.go | NewStreamFileBuilderForPath | func NewStreamFileBuilderForPath(path string) (*StreamFileBuilder, error) {
file, err := os.Create(path)
if err != nil {
return nil, err
}
return NewStreamFileBuilder(file), nil
} | go | func NewStreamFileBuilderForPath(path string) (*StreamFileBuilder, error) {
file, err := os.Create(path)
if err != nil {
return nil, err
}
return NewStreamFileBuilder(file), nil
} | [
"func",
"NewStreamFileBuilderForPath",
"(",
"path",
"string",
")",
"(",
"*",
"StreamFileBuilder",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",... | // NewStreamFileBuilderForPath takes the name of an XLSX file and returns a builder for it.
// The file will be created if it does not exist, or truncated if it does. | [
"NewStreamFileBuilderForPath",
"takes",
"the",
"name",
"of",
"an",
"XLSX",
"file",
"and",
"returns",
"a",
"builder",
"for",
"it",
".",
"The",
"file",
"will",
"be",
"created",
"if",
"it",
"does",
"not",
"exist",
"or",
"truncated",
"if",
"it",
"does",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L69-L75 | train |
tealeg/xlsx | stream_file_builder.go | AddSheet | func (sb *StreamFileBuilder) AddSheet(name string, headers []string, cellTypes []*CellType) error {
if sb.built {
return BuiltStreamFileBuilderError
}
if len(cellTypes) > len(headers) {
return errors.New("cellTypes is longer than headers")
}
sheet, err := sb.xlsxFile.AddSheet(name)
if err != nil {
// Set bu... | go | func (sb *StreamFileBuilder) AddSheet(name string, headers []string, cellTypes []*CellType) error {
if sb.built {
return BuiltStreamFileBuilderError
}
if len(cellTypes) > len(headers) {
return errors.New("cellTypes is longer than headers")
}
sheet, err := sb.xlsxFile.AddSheet(name)
if err != nil {
// Set bu... | [
"func",
"(",
"sb",
"*",
"StreamFileBuilder",
")",
"AddSheet",
"(",
"name",
"string",
",",
"headers",
"[",
"]",
"string",
",",
"cellTypes",
"[",
"]",
"*",
"CellType",
")",
"error",
"{",
"if",
"sb",
".",
"built",
"{",
"return",
"BuiltStreamFileBuilderError",... | // AddSheet will add sheets with the given name with the provided headers. The headers cannot be edited later, and all
// rows written to the sheet must contain the same number of cells as the header. Sheet names must be unique, or an
// error will be thrown. | [
"AddSheet",
"will",
"add",
"sheets",
"with",
"the",
"given",
"name",
"with",
"the",
"provided",
"headers",
".",
"The",
"headers",
"cannot",
"be",
"edited",
"later",
"and",
"all",
"rows",
"written",
"to",
"the",
"sheet",
"must",
"contain",
"the",
"same",
"n... | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L80-L120 | train |
tealeg/xlsx | stream_file_builder.go | AddValidation | func (sb *StreamFileBuilder) AddValidation(sheetIndex, colIndex, rowStartIndex int, validation *xlsxCellDataValidation) {
sheet := sb.xlsxFile.Sheets[sheetIndex]
column := sheet.Col(colIndex)
column.SetDataValidationWithStart(validation, rowStartIndex)
} | go | func (sb *StreamFileBuilder) AddValidation(sheetIndex, colIndex, rowStartIndex int, validation *xlsxCellDataValidation) {
sheet := sb.xlsxFile.Sheets[sheetIndex]
column := sheet.Col(colIndex)
column.SetDataValidationWithStart(validation, rowStartIndex)
} | [
"func",
"(",
"sb",
"*",
"StreamFileBuilder",
")",
"AddValidation",
"(",
"sheetIndex",
",",
"colIndex",
",",
"rowStartIndex",
"int",
",",
"validation",
"*",
"xlsxCellDataValidation",
")",
"{",
"sheet",
":=",
"sb",
".",
"xlsxFile",
".",
"Sheets",
"[",
"sheetInde... | // AddValidation will add a validation to a specific column. | [
"AddValidation",
"will",
"add",
"a",
"validation",
"to",
"a",
"specific",
"column",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L123-L127 | train |
tealeg/xlsx | stream_file_builder.go | Build | func (sb *StreamFileBuilder) Build() (*StreamFile, error) {
if sb.built {
return nil, BuiltStreamFileBuilderError
}
sb.built = true
parts, err := sb.xlsxFile.MarshallParts()
if err != nil {
return nil, err
}
es := &StreamFile{
zipWriter: sb.zipWriter,
xlsxFile: sb.xlsxFile,
sheetXmlPrefix: m... | go | func (sb *StreamFileBuilder) Build() (*StreamFile, error) {
if sb.built {
return nil, BuiltStreamFileBuilderError
}
sb.built = true
parts, err := sb.xlsxFile.MarshallParts()
if err != nil {
return nil, err
}
es := &StreamFile{
zipWriter: sb.zipWriter,
xlsxFile: sb.xlsxFile,
sheetXmlPrefix: m... | [
"func",
"(",
"sb",
"*",
"StreamFileBuilder",
")",
"Build",
"(",
")",
"(",
"*",
"StreamFile",
",",
"error",
")",
"{",
"if",
"sb",
".",
"built",
"{",
"return",
"nil",
",",
"BuiltStreamFileBuilderError",
"\n",
"}",
"\n",
"sb",
".",
"built",
"=",
"true",
... | // Build begins streaming the XLSX file to the io, by writing all the XLSX metadata. It creates a StreamFile struct
// that can be used to write the rows to the sheets. | [
"Build",
"begins",
"streaming",
"the",
"XLSX",
"file",
"to",
"the",
"io",
"by",
"writing",
"all",
"the",
"XLSX",
"metadata",
".",
"It",
"creates",
"a",
"StreamFile",
"struct",
"that",
"can",
"be",
"used",
"to",
"write",
"the",
"rows",
"to",
"the",
"sheet... | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L131-L170 | train |
tealeg/xlsx | stream_file_builder.go | processEmptySheetXML | func (sb *StreamFileBuilder) processEmptySheetXML(sf *StreamFile, path, data string) error {
// Get the sheet index from the path
sheetIndex, err := getSheetIndex(sf, path)
if err != nil {
return err
}
// Remove the Dimension tag. Since more rows are going to be written to the sheet, it will be wrong.
// It is... | go | func (sb *StreamFileBuilder) processEmptySheetXML(sf *StreamFile, path, data string) error {
// Get the sheet index from the path
sheetIndex, err := getSheetIndex(sf, path)
if err != nil {
return err
}
// Remove the Dimension tag. Since more rows are going to be written to the sheet, it will be wrong.
// It is... | [
"func",
"(",
"sb",
"*",
"StreamFileBuilder",
")",
"processEmptySheetXML",
"(",
"sf",
"*",
"StreamFile",
",",
"path",
",",
"data",
"string",
")",
"error",
"{",
"// Get the sheet index from the path",
"sheetIndex",
",",
"err",
":=",
"getSheetIndex",
"(",
"sf",
","... | // processEmptySheetXML will take in the path and XML data of an empty sheet, and will save the beginning and end of the
// XML file so that these can be written at the right time. | [
"processEmptySheetXML",
"will",
"take",
"in",
"the",
"path",
"and",
"XML",
"data",
"of",
"an",
"empty",
"sheet",
"and",
"will",
"save",
"the",
"beginning",
"and",
"end",
"of",
"the",
"XML",
"file",
"so",
"that",
"these",
"can",
"be",
"written",
"at",
"th... | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L174-L196 | train |
tealeg/xlsx | stream_file_builder.go | removeDimensionTag | func removeDimensionTag(data string, sheet *Sheet) (string, error) {
x := len(sheet.Cols) - 1
y := len(sheet.Rows) - 1
if x < 0 {
x = 0
}
if y < 0 {
y = 0
}
var dimensionRef string
if x == 0 && y == 0 {
dimensionRef = "A1"
} else {
endCoordinate := GetCellIDStringFromCoords(x, y)
dimensionRef = "A1:"... | go | func removeDimensionTag(data string, sheet *Sheet) (string, error) {
x := len(sheet.Cols) - 1
y := len(sheet.Rows) - 1
if x < 0 {
x = 0
}
if y < 0 {
y = 0
}
var dimensionRef string
if x == 0 && y == 0 {
dimensionRef = "A1"
} else {
endCoordinate := GetCellIDStringFromCoords(x, y)
dimensionRef = "A1:"... | [
"func",
"removeDimensionTag",
"(",
"data",
"string",
",",
"sheet",
"*",
"Sheet",
")",
"(",
"string",
",",
"error",
")",
"{",
"x",
":=",
"len",
"(",
"sheet",
".",
"Cols",
")",
"-",
"1",
"\n",
"y",
":=",
"len",
"(",
"sheet",
".",
"Rows",
")",
"-",
... | // removeDimensionTag will return the passed in XLSX Spreadsheet XML with the dimension tag removed.
// data is the XML data for the sheet
// sheet is the Sheet struct that the XML was created from.
// Can return an error if the XML's dimension tag does not match was is expected based on the provided Sheet | [
"removeDimensionTag",
"will",
"return",
"the",
"passed",
"in",
"XLSX",
"Spreadsheet",
"XML",
"with",
"the",
"dimension",
"tag",
"removed",
".",
"data",
"is",
"the",
"XML",
"data",
"for",
"the",
"sheet",
"sheet",
"is",
"the",
"Sheet",
"struct",
"that",
"the",... | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L220-L241 | train |
tealeg/xlsx | stream_file_builder.go | splitSheetIntoPrefixAndSuffix | func splitSheetIntoPrefixAndSuffix(data string) (string, string, error) {
// Split the sheet at the end of its SheetData tag so that more rows can be added inside.
sheetParts := strings.Split(data, endSheetDataTag)
if len(sheetParts) != 2 {
return "", "", errors.New("unexpected Sheet XML: SheetData close tag not f... | go | func splitSheetIntoPrefixAndSuffix(data string) (string, string, error) {
// Split the sheet at the end of its SheetData tag so that more rows can be added inside.
sheetParts := strings.Split(data, endSheetDataTag)
if len(sheetParts) != 2 {
return "", "", errors.New("unexpected Sheet XML: SheetData close tag not f... | [
"func",
"splitSheetIntoPrefixAndSuffix",
"(",
"data",
"string",
")",
"(",
"string",
",",
"string",
",",
"error",
")",
"{",
"// Split the sheet at the end of its SheetData tag so that more rows can be added inside.",
"sheetParts",
":=",
"strings",
".",
"Split",
"(",
"data",
... | // splitSheetIntoPrefixAndSuffix will split the provided XML sheet into a prefix and a suffix so that
// more spreadsheet rows can be inserted in between. | [
"splitSheetIntoPrefixAndSuffix",
"will",
"split",
"the",
"provided",
"XML",
"sheet",
"into",
"a",
"prefix",
"and",
"a",
"suffix",
"so",
"that",
"more",
"spreadsheet",
"rows",
"can",
"be",
"inserted",
"in",
"between",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file_builder.go#L245-L252 | train |
tealeg/xlsx | stream_file.go | Write | func (sf *StreamFile) Write(cells []string) error {
if sf.err != nil {
return sf.err
}
err := sf.write(cells)
if err != nil {
sf.err = err
return err
}
return sf.zipWriter.Flush()
} | go | func (sf *StreamFile) Write(cells []string) error {
if sf.err != nil {
return sf.err
}
err := sf.write(cells)
if err != nil {
sf.err = err
return err
}
return sf.zipWriter.Flush()
} | [
"func",
"(",
"sf",
"*",
"StreamFile",
")",
"Write",
"(",
"cells",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"sf",
".",
"err",
"!=",
"nil",
"{",
"return",
"sf",
".",
"err",
"\n",
"}",
"\n",
"err",
":=",
"sf",
".",
"write",
"(",
"cells",
")",
... | // Write will write a row of cells to the current sheet. Every call to Write on the same sheet must contain the
// same number of cells as the header provided when the sheet was created or an error will be returned. This function
// will always trigger a flush on success. Currently the only supported data type is strin... | [
"Write",
"will",
"write",
"a",
"row",
"of",
"cells",
"to",
"the",
"current",
"sheet",
".",
"Every",
"call",
"to",
"Write",
"on",
"the",
"same",
"sheet",
"must",
"contain",
"the",
"same",
"number",
"of",
"cells",
"as",
"the",
"header",
"provided",
"when",... | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file.go#L42-L52 | train |
tealeg/xlsx | stream_file.go | NextSheet | func (sf *StreamFile) NextSheet() error {
if sf.err != nil {
return sf.err
}
var sheetIndex int
if sf.currentSheet != nil {
if sf.currentSheet.index >= len(sf.xlsxFile.Sheets) {
sf.err = AlreadyOnLastSheetError
return AlreadyOnLastSheetError
}
if err := sf.writeSheetEnd(); err != nil {
sf.currentSh... | go | func (sf *StreamFile) NextSheet() error {
if sf.err != nil {
return sf.err
}
var sheetIndex int
if sf.currentSheet != nil {
if sf.currentSheet.index >= len(sf.xlsxFile.Sheets) {
sf.err = AlreadyOnLastSheetError
return AlreadyOnLastSheetError
}
if err := sf.writeSheetEnd(); err != nil {
sf.currentSh... | [
"func",
"(",
"sf",
"*",
"StreamFile",
")",
"NextSheet",
"(",
")",
"error",
"{",
"if",
"sf",
".",
"err",
"!=",
"nil",
"{",
"return",
"sf",
".",
"err",
"\n",
"}",
"\n",
"var",
"sheetIndex",
"int",
"\n",
"if",
"sf",
".",
"currentSheet",
"!=",
"nil",
... | // NextSheet will switch to the next sheet. Sheets are selected in the same order they were added.
// Once you leave a sheet, you cannot return to it. | [
"NextSheet",
"will",
"switch",
"to",
"the",
"next",
"sheet",
".",
"Sheets",
"are",
"selected",
"in",
"the",
"same",
"order",
"they",
"were",
"added",
".",
"Once",
"you",
"leave",
"a",
"sheet",
"you",
"cannot",
"return",
"to",
"it",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file.go#L128-L165 | train |
tealeg/xlsx | stream_file.go | Close | func (sf *StreamFile) Close() error {
if sf.err != nil {
return sf.err
}
// If there are sheets that have not been written yet, call NextSheet() which will add files to the zip for them.
// XLSX readers may error if the sheets registered in the metadata are not present in the file.
if sf.currentSheet != nil {
... | go | func (sf *StreamFile) Close() error {
if sf.err != nil {
return sf.err
}
// If there are sheets that have not been written yet, call NextSheet() which will add files to the zip for them.
// XLSX readers may error if the sheets registered in the metadata are not present in the file.
if sf.currentSheet != nil {
... | [
"func",
"(",
"sf",
"*",
"StreamFile",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"sf",
".",
"err",
"!=",
"nil",
"{",
"return",
"sf",
".",
"err",
"\n",
"}",
"\n",
"// If there are sheets that have not been written yet, call NextSheet() which will add files to the zi... | // Close closes the Stream File.
// Any sheets that have not yet been written to will have an empty sheet created for them. | [
"Close",
"closes",
"the",
"Stream",
"File",
".",
"Any",
"sheets",
"that",
"have",
"not",
"yet",
"been",
"written",
"to",
"will",
"have",
"an",
"empty",
"sheet",
"created",
"for",
"them",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file.go#L169-L193 | train |
tealeg/xlsx | stream_file.go | writeSheetStart | func (sf *StreamFile) writeSheetStart() error {
if sf.currentSheet == nil {
return NoCurrentSheetError
}
return sf.currentSheet.write(sf.sheetXmlPrefix[sf.currentSheet.index-1])
} | go | func (sf *StreamFile) writeSheetStart() error {
if sf.currentSheet == nil {
return NoCurrentSheetError
}
return sf.currentSheet.write(sf.sheetXmlPrefix[sf.currentSheet.index-1])
} | [
"func",
"(",
"sf",
"*",
"StreamFile",
")",
"writeSheetStart",
"(",
")",
"error",
"{",
"if",
"sf",
".",
"currentSheet",
"==",
"nil",
"{",
"return",
"NoCurrentSheetError",
"\n",
"}",
"\n",
"return",
"sf",
".",
"currentSheet",
".",
"write",
"(",
"sf",
".",
... | // writeSheetStart will write the start of the Sheet's XML | [
"writeSheetStart",
"will",
"write",
"the",
"start",
"of",
"the",
"Sheet",
"s",
"XML"
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file.go#L196-L201 | train |
tealeg/xlsx | stream_file.go | writeSheetEnd | func (sf *StreamFile) writeSheetEnd() error {
if sf.currentSheet == nil {
return NoCurrentSheetError
}
if err := sf.currentSheet.write(endSheetDataTag); err != nil {
return err
}
return sf.currentSheet.write(sf.sheetXmlSuffix[sf.currentSheet.index-1])
} | go | func (sf *StreamFile) writeSheetEnd() error {
if sf.currentSheet == nil {
return NoCurrentSheetError
}
if err := sf.currentSheet.write(endSheetDataTag); err != nil {
return err
}
return sf.currentSheet.write(sf.sheetXmlSuffix[sf.currentSheet.index-1])
} | [
"func",
"(",
"sf",
"*",
"StreamFile",
")",
"writeSheetEnd",
"(",
")",
"error",
"{",
"if",
"sf",
".",
"currentSheet",
"==",
"nil",
"{",
"return",
"NoCurrentSheetError",
"\n",
"}",
"\n",
"if",
"err",
":=",
"sf",
".",
"currentSheet",
".",
"write",
"(",
"e... | // writeSheetEnd will write the end of the Sheet's XML | [
"writeSheetEnd",
"will",
"write",
"the",
"end",
"of",
"the",
"Sheet",
"s",
"XML"
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/stream_file.go#L204-L212 | train |
tealeg/xlsx | format_code.go | compareFormatString | func compareFormatString(fmt1, fmt2 string) bool {
if fmt1 == fmt2 {
return true
}
if fmt1 == "" || strings.EqualFold(fmt1, "general") {
fmt1 = "general"
}
if fmt2 == "" || strings.EqualFold(fmt2, "general") {
fmt2 = "general"
}
return fmt1 == fmt2
} | go | func compareFormatString(fmt1, fmt2 string) bool {
if fmt1 == fmt2 {
return true
}
if fmt1 == "" || strings.EqualFold(fmt1, "general") {
fmt1 = "general"
}
if fmt2 == "" || strings.EqualFold(fmt2, "general") {
fmt2 = "general"
}
return fmt1 == fmt2
} | [
"func",
"compareFormatString",
"(",
"fmt1",
",",
"fmt2",
"string",
")",
"bool",
"{",
"if",
"fmt1",
"==",
"fmt2",
"{",
"return",
"true",
"\n",
"}",
"\n",
"if",
"fmt1",
"==",
"\"",
"\"",
"||",
"strings",
".",
"EqualFold",
"(",
"fmt1",
",",
"\"",
"\"",
... | // Format strings are a little strange to compare because empty string needs to be taken as general, and general needs
// to be compared case insensitively. | [
"Format",
"strings",
"are",
"a",
"little",
"strange",
"to",
"compare",
"because",
"empty",
"string",
"needs",
"to",
"be",
"taken",
"as",
"general",
"and",
"general",
"needs",
"to",
"be",
"compared",
"case",
"insensitively",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/format_code.go#L224-L235 | train |
tealeg/xlsx | format_code.go | splitFormatOnSemicolon | func splitFormatOnSemicolon(format string) ([]string, error) {
var formats []string
prevIndex := 0
for i := 0; i < len(format); i++ {
if format[i] == ';' {
formats = append(formats, format[prevIndex:i])
prevIndex = i + 1
} else if format[i] == '\\' {
i++
} else if format[i] == '"' {
endQuoteIndex :... | go | func splitFormatOnSemicolon(format string) ([]string, error) {
var formats []string
prevIndex := 0
for i := 0; i < len(format); i++ {
if format[i] == ';' {
formats = append(formats, format[prevIndex:i])
prevIndex = i + 1
} else if format[i] == '\\' {
i++
} else if format[i] == '"' {
endQuoteIndex :... | [
"func",
"splitFormatOnSemicolon",
"(",
"format",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"var",
"formats",
"[",
"]",
"string",
"\n",
"prevIndex",
":=",
"0",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"len",
"(",
"format",
"... | // splitFormatOnSemicolon will split the format string into the format sections
// This logic to split the different formats on semicolon is fully correct, and will skip all literal semicolons,
// and will catch all breaking semicolons. | [
"splitFormatOnSemicolon",
"will",
"split",
"the",
"format",
"string",
"into",
"the",
"format",
"sections",
"This",
"logic",
"to",
"split",
"the",
"different",
"formats",
"on",
"semicolon",
"is",
"fully",
"correct",
"and",
"will",
"skip",
"all",
"literal",
"semic... | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/format_code.go#L315-L334 | train |
tealeg/xlsx | data_validation.go | SetError | func (dd *xlsxCellDataValidation) SetError(style DataValidationErrorStyle, title, msg *string) {
dd.ShowErrorMessage = true
dd.Error = msg
dd.ErrorTitle = title
strStyle := styleStop
switch style {
case StyleStop:
strStyle = styleStop
case StyleWarning:
strStyle = styleWarning
case StyleInformation:
strSt... | go | func (dd *xlsxCellDataValidation) SetError(style DataValidationErrorStyle, title, msg *string) {
dd.ShowErrorMessage = true
dd.Error = msg
dd.ErrorTitle = title
strStyle := styleStop
switch style {
case StyleStop:
strStyle = styleStop
case StyleWarning:
strStyle = styleWarning
case StyleInformation:
strSt... | [
"func",
"(",
"dd",
"*",
"xlsxCellDataValidation",
")",
"SetError",
"(",
"style",
"DataValidationErrorStyle",
",",
"title",
",",
"msg",
"*",
"string",
")",
"{",
"dd",
".",
"ShowErrorMessage",
"=",
"true",
"\n",
"dd",
".",
"Error",
"=",
"msg",
"\n",
"dd",
... | // SetError set error notice | [
"SetError",
"set",
"error",
"notice"
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/data_validation.go#L72-L87 | train |
tealeg/xlsx | data_validation.go | SetRange | func (dd *xlsxCellDataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error {
formula1 := fmt.Sprintf("%d", f1)
formula2 := fmt.Sprintf("%d", f2)
switch o {
case DataValidationOperatorBetween:
if f1 > f2 {
tmp := formula1
formula1 = formula2
formula2 = tmp
}
case Data... | go | func (dd *xlsxCellDataValidation) SetRange(f1, f2 int, t DataValidationType, o DataValidationOperator) error {
formula1 := fmt.Sprintf("%d", f1)
formula2 := fmt.Sprintf("%d", f2)
switch o {
case DataValidationOperatorBetween:
if f1 > f2 {
tmp := formula1
formula1 = formula2
formula2 = tmp
}
case Data... | [
"func",
"(",
"dd",
"*",
"xlsxCellDataValidation",
")",
"SetRange",
"(",
"f1",
",",
"f2",
"int",
",",
"t",
"DataValidationType",
",",
"o",
"DataValidationOperator",
")",
"error",
"{",
"formula1",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"f1",
")... | // SetDropList data validation range | [
"SetDropList",
"data",
"validation",
"range"
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/data_validation.go#L131-L155 | train |
tealeg/xlsx | style.go | NewStyle | func NewStyle() *Style {
return &Style{
Alignment: *DefaultAlignment(),
Border: *DefaultBorder(),
Fill: *DefaultFill(),
Font: *DefaultFont(),
}
} | go | func NewStyle() *Style {
return &Style{
Alignment: *DefaultAlignment(),
Border: *DefaultBorder(),
Fill: *DefaultFill(),
Font: *DefaultFont(),
}
} | [
"func",
"NewStyle",
"(",
")",
"*",
"Style",
"{",
"return",
"&",
"Style",
"{",
"Alignment",
":",
"*",
"DefaultAlignment",
"(",
")",
",",
"Border",
":",
"*",
"DefaultBorder",
"(",
")",
",",
"Fill",
":",
"*",
"DefaultFill",
"(",
")",
",",
"Font",
":",
... | // Return a new Style structure initialised with the default values. | [
"Return",
"a",
"new",
"Style",
"structure",
"initialised",
"with",
"the",
"default",
"values",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/style.go#L20-L27 | train |
tealeg/xlsx | style.go | makeXLSXStyleElements | func (style *Style) makeXLSXStyleElements() (xFont xlsxFont, xFill xlsxFill, xBorder xlsxBorder, xCellXf xlsxXf) {
xFont = xlsxFont{}
xFill = xlsxFill{}
xBorder = xlsxBorder{}
xCellXf = xlsxXf{}
xFont.Sz.Val = strconv.Itoa(style.Font.Size)
xFont.Name.Val = style.Font.Name
xFont.Family.Val = strconv.Itoa(style.Fo... | go | func (style *Style) makeXLSXStyleElements() (xFont xlsxFont, xFill xlsxFill, xBorder xlsxBorder, xCellXf xlsxXf) {
xFont = xlsxFont{}
xFill = xlsxFill{}
xBorder = xlsxBorder{}
xCellXf = xlsxXf{}
xFont.Sz.Val = strconv.Itoa(style.Font.Size)
xFont.Name.Val = style.Font.Name
xFont.Family.Val = strconv.Itoa(style.Fo... | [
"func",
"(",
"style",
"*",
"Style",
")",
"makeXLSXStyleElements",
"(",
")",
"(",
"xFont",
"xlsxFont",
",",
"xFill",
"xlsxFill",
",",
"xBorder",
"xlsxBorder",
",",
"xCellXf",
"xlsxXf",
")",
"{",
"xFont",
"=",
"xlsxFont",
"{",
"}",
"\n",
"xFill",
"=",
"xls... | // Generate the underlying XLSX style elements that correspond to the Style. | [
"Generate",
"the",
"underlying",
"XLSX",
"style",
"elements",
"that",
"correspond",
"to",
"the",
"Style",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/style.go#L30-L85 | train |
tealeg/xlsx | lib.go | ColIndexToLetters | func ColIndexToLetters(colRef int) string {
parts := intToBase26(colRef)
return formatColumnName(smooshBase26Slice(parts))
} | go | func ColIndexToLetters(colRef int) string {
parts := intToBase26(colRef)
return formatColumnName(smooshBase26Slice(parts))
} | [
"func",
"ColIndexToLetters",
"(",
"colRef",
"int",
")",
"string",
"{",
"parts",
":=",
"intToBase26",
"(",
"colRef",
")",
"\n",
"return",
"formatColumnName",
"(",
"smooshBase26Slice",
"(",
"parts",
")",
")",
"\n",
"}"
] | // ColIndexToLetters is used to convert a zero based, numeric column
// indentifier into a character code. | [
"ColIndexToLetters",
"is",
"used",
"to",
"convert",
"a",
"zero",
"based",
"numeric",
"column",
"indentifier",
"into",
"a",
"character",
"code",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/lib.go#L147-L150 | train |
tealeg/xlsx | lib.go | GetCellIDStringFromCoords | func GetCellIDStringFromCoords(x, y int) string {
return GetCellIDStringFromCoordsWithFixed(x, y, false, false)
} | go | func GetCellIDStringFromCoords(x, y int) string {
return GetCellIDStringFromCoordsWithFixed(x, y, false, false)
} | [
"func",
"GetCellIDStringFromCoords",
"(",
"x",
",",
"y",
"int",
")",
"string",
"{",
"return",
"GetCellIDStringFromCoordsWithFixed",
"(",
"x",
",",
"y",
",",
"false",
",",
"false",
")",
"\n",
"}"
] | // GetCellIDStringFromCoords returns the Excel format cell name that
// represents a pair of zero based cartesian coordinates. | [
"GetCellIDStringFromCoords",
"returns",
"the",
"Excel",
"format",
"cell",
"name",
"that",
"represents",
"a",
"pair",
"of",
"zero",
"based",
"cartesian",
"coordinates",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/lib.go#L195-L197 | train |
tealeg/xlsx | lib.go | GetCellIDStringFromCoordsWithFixed | func GetCellIDStringFromCoordsWithFixed(x, y int, xFixed, yFixed bool) string {
xStr := ColIndexToLetters(x)
if xFixed {
xStr = fixedCellRefChar + xStr
}
yStr := RowIndexToString(y)
if yFixed {
yStr = fixedCellRefChar + yStr
}
return xStr + yStr
} | go | func GetCellIDStringFromCoordsWithFixed(x, y int, xFixed, yFixed bool) string {
xStr := ColIndexToLetters(x)
if xFixed {
xStr = fixedCellRefChar + xStr
}
yStr := RowIndexToString(y)
if yFixed {
yStr = fixedCellRefChar + yStr
}
return xStr + yStr
} | [
"func",
"GetCellIDStringFromCoordsWithFixed",
"(",
"x",
",",
"y",
"int",
",",
"xFixed",
",",
"yFixed",
"bool",
")",
"string",
"{",
"xStr",
":=",
"ColIndexToLetters",
"(",
"x",
")",
"\n",
"if",
"xFixed",
"{",
"xStr",
"=",
"fixedCellRefChar",
"+",
"xStr",
"\... | // GetCellIDStringFromCoordsWithFixed returns the Excel format cell name that
// represents a pair of zero based cartesian coordinates.
// It can specify either value as fixed. | [
"GetCellIDStringFromCoordsWithFixed",
"returns",
"the",
"Excel",
"format",
"cell",
"name",
"that",
"represents",
"a",
"pair",
"of",
"zero",
"based",
"cartesian",
"coordinates",
".",
"It",
"can",
"specify",
"either",
"value",
"as",
"fixed",
"."
] | b7005b5d48cbd240baa323f68fb644fe072ef088 | https://github.com/tealeg/xlsx/blob/b7005b5d48cbd240baa323f68fb644fe072ef088/lib.go#L202-L212 | 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.