_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q23600 | Play | train | func (tc *TeleportClient) Play(ctx context.Context, namespace, sessionId string) (err error) {
if namespace == "" {
return trace.BadParameter(auth.MissingNamespaceError)
}
sid, err := session.ParseID(sessionId)
if err != nil {
return fmt.Errorf("'%v' is not a valid session ID (must be GUID)", sid)
}
// connec... | go | {
"resource": ""
} |
q23601 | ExecuteSCP | train | func (tc *TeleportClient) ExecuteSCP(ctx context.Context, cmd scp.Command) (err error) {
// connect to proxy first:
if !tc.Config.ProxySpecified() {
return trace.BadParameter("proxy server is not specified")
}
proxyClient, err := tc.ConnectToProxy(ctx)
if err != nil {
return trace.Wrap(err)
}
defer proxyCli... | go | {
"resource": ""
} |
q23602 | ListNodes | train | func (tc *TeleportClient) ListNodes(ctx context.Context) ([]services.Server, error) {
var err error
// userhost is specified? that must be labels
if tc.Host != "" {
tc.Labels, err = ParseLabelSpec(tc.Host)
if err != nil {
return nil, trace.Wrap(err)
}
}
// connect to the proxy and ask it to return a full... | go | {
"resource": ""
} |
q23603 | runCommand | train | func (tc *TeleportClient) runCommand(
ctx context.Context, siteName string, nodeAddresses []string, proxyClient *ProxyClient, command []string) error {
resultsC := make(chan error, len(nodeAddresses))
for _, address := range nodeAddresses {
go func(address string) {
var (
err error
nodeSession ... | go | {
"resource": ""
} |
q23604 | getProxySSHPrincipal | train | func (tc *TeleportClient) getProxySSHPrincipal() string {
proxyPrincipal := tc.Config.HostLogin
if tc.DefaultPrincipal != "" {
proxyPrincipal = tc.DefaultPrincipal
}
// see if we already have a signed key in the cache, we'll use that instead
if !tc.Config.SkipLocalAuth && tc.LocalAgent() != nil {
signers, err ... | go | {
"resource": ""
} |
q23605 | ConnectToProxy | train | func (tc *TeleportClient) ConnectToProxy(ctx context.Context) (*ProxyClient, error) {
var err error
var proxyClient *ProxyClient
// Use connectContext and the cancel function to signal when a response is
// returned from connectToProxy.
connectContext, cancel := context.WithCancel(context.Background())
go func()... | go | {
"resource": ""
} |
q23606 | connectToProxy | train | func (tc *TeleportClient) connectToProxy(ctx context.Context) (*ProxyClient, error) {
var err error
proxyPrincipal := tc.getProxySSHPrincipal()
sshConfig := &ssh.ClientConfig{
User: proxyPrincipal,
HostKeyCallback: tc.HostKeyCallback,
}
// helper to create a ProxyClient struct
makeProxyClient := ... | go | {
"resource": ""
} |
q23607 | Logout | train | func (tc *TeleportClient) Logout() error {
err := tc.localAgent.DeleteKey()
if err != nil {
return trace.Wrap(err)
}
return nil
} | go | {
"resource": ""
} |
q23608 | LogoutAll | train | func (tc *TeleportClient) LogoutAll() error {
err := tc.localAgent.DeleteKeys()
if err != nil {
return trace.Wrap(err)
}
return nil
} | go | {
"resource": ""
} |
q23609 | GetTrustedCA | train | func (tc *TeleportClient) GetTrustedCA(ctx context.Context, clusterName string) ([]services.CertAuthority, error) {
// Connect to the proxy.
if !tc.Config.ProxySpecified() {
return nil, trace.BadParameter("proxy server is not specified")
}
proxyClient, err := tc.ConnectToProxy(ctx)
if err != nil {
return nil, ... | go | {
"resource": ""
} |
q23610 | applyProxySettings | train | func (tc *TeleportClient) applyProxySettings(proxySettings ProxySettings) error {
// Kubernetes proxy settings.
if proxySettings.Kube.Enabled && proxySettings.Kube.PublicAddr != "" && tc.KubeProxyAddr == "" {
_, err := utils.ParseAddr(proxySettings.Kube.PublicAddr)
if err != nil {
return trace.BadParameter(
... | go | {
"resource": ""
} |
q23611 | AddTrustedCA | train | func (tc *TeleportClient) AddTrustedCA(ca services.CertAuthority) error {
err := tc.LocalAgent().AddHostSignersToCache(auth.AuthoritiesToTrustedCerts([]services.CertAuthority{ca}))
if err != nil {
return trace.Wrap(err)
}
// only host CA has TLS certificates, user CA will overwrite trusted certs
// to empty fil... | go | {
"resource": ""
} |
q23612 | directLogin | train | func (tc *TeleportClient) directLogin(ctx context.Context, secondFactorType string, pub []byte) (*auth.SSHLoginResponse, error) {
var err error
var password string
var otpToken string
password, err = tc.AskPassword()
if err != nil {
return nil, trace.Wrap(err)
}
// only ask for a second factor if it's enabl... | go | {
"resource": ""
} |
q23613 | ssoLogin | train | func (tc *TeleportClient) ssoLogin(ctx context.Context, connectorID string, pub []byte, protocol string) (*auth.SSHLoginResponse, error) {
log.Debugf("samlLogin start")
// ask the CA (via proxy) to sign our public key:
response, err := tc.credClient.SSHAgentSSOLogin(SSHLogin{
Context: ctx,
ConnectorID: c... | go | {
"resource": ""
} |
q23614 | u2fLogin | train | func (tc *TeleportClient) u2fLogin(ctx context.Context, pub []byte) (*auth.SSHLoginResponse, error) {
// U2F login requires the official u2f-host executable
_, err := exec.LookPath("u2f-host")
if err != nil {
return nil, trace.Wrap(err)
}
password, err := tc.AskPassword()
if err != nil {
return nil, trace.Wr... | go | {
"resource": ""
} |
q23615 | SendEvent | train | func (tc *TeleportClient) SendEvent(ctx context.Context, e events.EventFields) error {
// Try and send the event to the eventsCh. If blocking, keep blocking until
// the passed in context in canceled.
select {
case tc.eventsCh <- e:
return nil
case <-ctx.Done():
return trace.Wrap(ctx.Err())
}
} | go | {
"resource": ""
} |
q23616 | loopbackPool | train | func loopbackPool(proxyAddr string) *x509.CertPool {
if !utils.IsLoopback(proxyAddr) {
log.Debugf("not using loopback pool for remote proxy addr: %v", proxyAddr)
return nil
}
log.Debugf("attempting to use loopback pool for local proxy addr: %v", proxyAddr)
certPool := x509.NewCertPool()
certPath := filepath.J... | go | {
"resource": ""
} |
q23617 | connectToSSHAgent | train | func connectToSSHAgent() agent.Agent {
socketPath := os.Getenv(teleport.SSHAuthSock)
conn, err := agentconn.Dial(socketPath)
if err != nil {
log.Errorf("[KEY AGENT] Unable to connect to SSH agent on socket: %q.", socketPath)
return nil
}
log.Infof("[KEY AGENT] Connected to the system agent: %q", socketPath)
... | go | {
"resource": ""
} |
q23618 | Username | train | func Username() (string, error) {
u, err := user.Current()
if err != nil {
return "", trace.Wrap(err)
}
return u.Username, nil
} | go | {
"resource": ""
} |
q23619 | AskOTP | train | func (tc *TeleportClient) AskOTP() (token string, err error) {
fmt.Printf("Enter your OTP token:\n")
token, err = lineFromConsole()
if err != nil {
fmt.Fprintln(tc.Stderr, err)
return "", trace.Wrap(err)
}
return token, nil
} | go | {
"resource": ""
} |
q23620 | AskPassword | train | func (tc *TeleportClient) AskPassword() (pwd string, err error) {
fmt.Printf("Enter password for Teleport user %v:\n", tc.Config.Username)
pwd, err = passwordFromConsole()
if err != nil {
fmt.Fprintln(tc.Stderr, err)
return "", trace.Wrap(err)
}
return pwd, nil
} | go | {
"resource": ""
} |
q23621 | passwordFromConsole | train | func passwordFromConsole() (string, error) {
fd := syscall.Stdin
state, err := terminal.GetState(int(fd))
// intercept Ctr+C and restore terminal
sigCh := make(chan os.Signal, 1)
closeCh := make(chan int)
if err != nil {
log.Warnf("failed reading terminal state: %v", err)
} else {
signal.Notify(sigCh, sysca... | go | {
"resource": ""
} |
q23622 | lineFromConsole | train | func lineFromConsole() (string, error) {
bytes, _, err := bufio.NewReader(os.Stdin).ReadLine()
return string(bytes), err
} | go | {
"resource": ""
} |
q23623 | String | train | func (fp DynamicForwardedPorts) String() (retval []string) {
for _, p := range fp {
retval = append(retval, p.ToString())
}
return retval
} | go | {
"resource": ""
} |
q23624 | InsecureSkipHostKeyChecking | train | func InsecureSkipHostKeyChecking(host string, remote net.Addr, key ssh.PublicKey) error {
return nil
} | go | {
"resource": ""
} |
q23625 | OpenChannel | train | func (c *remoteConn) OpenChannel(name string, data []byte) (ssh.Channel, error) {
channel, _, err := c.sconn.OpenChannel(name, data)
if err != nil {
return nil, trace.Wrap(err)
}
return channel, nil
} | go | {
"resource": ""
} |
q23626 | ChannelConn | train | func (c *remoteConn) ChannelConn(channel ssh.Channel) net.Conn {
return utils.NewChConn(c.sconn, channel)
} | go | {
"resource": ""
} |
q23627 | findAndSend | train | func (c *remoteConn) findAndSend() error {
// Find all proxies that don't have a connection to a remote agent. If all
// proxies have connections, return right away.
disconnectedProxies, err := c.findDisconnectedProxies()
if err != nil {
return trace.Wrap(err)
}
if len(disconnectedProxies) == 0 {
return nil
... | go | {
"resource": ""
} |
q23628 | findDisconnectedProxies | train | func (c *remoteConn) findDisconnectedProxies() ([]services.Server, error) {
// Find all proxies that have connection from the remote domain.
conns, err := c.accessPoint.GetTunnelConnections(c.clusterName, services.SkipValidation())
if err != nil {
return nil, trace.Wrap(err)
}
connected := make(map[string]bool)
... | go | {
"resource": ""
} |
q23629 | sendDiscoveryRequests | train | func (c *remoteConn) sendDiscoveryRequests(req discoveryRequest) error {
discoveryCh, err := c.openDiscoveryChannel()
if err != nil {
return trace.Wrap(err)
}
// Marshal and send the request. If the connection failed, mark the
// connection as invalid so it will be removed later.
payload, err := marshalDiscove... | go | {
"resource": ""
} |
q23630 | TunnelAuthDialer | train | func TunnelAuthDialer(proxyAddr string, sshConfig *ssh.ClientConfig) auth.DialContext {
return func(ctx context.Context, network string, addr string) (net.Conn, error) {
// Connect to the reverse tunnel server.
dialer := proxy.DialerFromEnvironment(proxyAddr)
sconn, err := dialer.Dial("tcp", proxyAddr, sshConfig... | go | {
"resource": ""
} |
q23631 | connectProxyTransport | train | func connectProxyTransport(sconn ssh.Conn, addr string) (net.Conn, error) {
channel, _, err := sconn.OpenChannel(chanTransport, nil)
if err != nil {
return nil, trace.Wrap(err)
}
// Send a special SSH out-of-band request called "teleport-transport"
// the agent on the other side will create a new TCP/IP connect... | go | {
"resource": ""
} |
q23632 | Close | train | func (c *Connector) Close() error {
if c.Client != nil {
return c.Close()
}
return nil
} | go | {
"resource": ""
} |
q23633 | getConnectors | train | func (process *TeleportProcess) getConnectors() []*Connector {
process.Lock()
defer process.Unlock()
out := make([]*Connector, 0, len(process.connectors))
for role := range process.connectors {
out = append(out, process.connectors[role])
}
return out
} | go | {
"resource": ""
} |
q23634 | addConnector | train | func (process *TeleportProcess) addConnector(connector *Connector) {
process.Lock()
defer process.Unlock()
process.connectors[connector.ClientIdentity.ID.Role] = connector
} | go | {
"resource": ""
} |
q23635 | Run | train | func Run(ctx context.Context, cfg Config, newTeleport NewProcess) error {
if newTeleport == nil {
newTeleport = newTeleportProcess
}
copyCfg := cfg
srv, err := newTeleport(©Cfg)
if err != nil {
return trace.Wrap(err, "initialization failed")
}
if srv == nil {
return trace.BadParameter("process has retu... | go | {
"resource": ""
} |
q23636 | notifyParent | train | func (process *TeleportProcess) notifyParent() {
signalPipe, err := process.importSignalPipe()
if err != nil {
if !trace.IsNotFound(err) {
process.Warningf("Failed to import signal pipe")
}
process.Debugf("No signal pipe to import, must be first Teleport process.")
return
}
defer signalPipe.Close()
ctx... | go | {
"resource": ""
} |
q23637 | adminCreds | train | func adminCreds() (*int, *int, error) {
if runtime.GOOS != teleport.LinuxOS {
return nil, nil, nil
}
// if the user member of adm linux group,
// make audit log folder readable by admins
isAdmin, err := utils.IsGroupMember(teleport.LinuxAdminGID)
if err != nil {
return nil, nil, trace.Wrap(err)
}
if !isAdmi... | go | {
"resource": ""
} |
q23638 | initUploadHandler | train | func initUploadHandler(auditConfig services.AuditConfig) (events.UploadHandler, error) {
if auditConfig.AuditSessionsURI == "" {
return nil, trace.NotFound("no upload handler is setup")
}
uri, err := utils.ParseSessionsURI(auditConfig.AuditSessionsURI)
if err != nil {
return nil, trace.Wrap(err)
}
switch uri... | go | {
"resource": ""
} |
q23639 | initExternalLog | train | func initExternalLog(auditConfig services.AuditConfig) (events.IAuditLog, error) {
if auditConfig.AuditTableName != "" {
log.Warningf("Please note that 'audit_table_name' is deprecated and will be removed in several releases. Use audit_events_uri: '%v://%v' instead.", dynamo.GetName(), auditConfig.AuditTableName)
... | go | {
"resource": ""
} |
q23640 | onExit | train | func (process *TeleportProcess) onExit(serviceName string, callback func(interface{})) {
process.RegisterFunc(serviceName, func() error {
eventC := make(chan Event)
process.WaitForEvent(context.TODO(), TeleportExitEvent, eventC)
select {
case event := <-eventC:
callback(event.Payload)
}
return nil
})
} | go | {
"resource": ""
} |
q23641 | newAccessCache | train | func (process *TeleportProcess) newAccessCache(cfg accessCacheConfig) (*cache.Cache, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
var cacheBackend backend.Backend
if cfg.inMemory {
mem, err := memory.New(memory.Config{
Context: process.ExitContext(),
EventsOff... | go | {
"resource": ""
} |
q23642 | setupCachePolicy | train | func (process *TeleportProcess) setupCachePolicy(in cache.SetupConfigFn) cache.SetupConfigFn {
return func(c cache.Config) cache.Config {
config := in(c)
config.PreferRecent = cache.PreferRecent{
Enabled: process.Config.CachePolicy.Enabled,
NeverExpires: process.Config.CachePolicy.NeverExpires,
MaxTT... | go | {
"resource": ""
} |
q23643 | newLocalCacheForProxy | train | func (process *TeleportProcess) newLocalCacheForProxy(clt auth.ClientI, cacheName []string) (auth.AccessPoint, error) {
return process.newLocalCache(clt, cache.ForProxy, cacheName)
} | go | {
"resource": ""
} |
q23644 | newLocalCache | train | func (process *TeleportProcess) newLocalCache(clt auth.ClientI, setupConfig cache.SetupConfigFn, cacheName []string) (auth.AccessPoint, error) {
// if caching is disabled, return access point
if !process.Config.CachePolicy.Enabled {
return clt, nil
}
cache, err := process.newAccessCache(accessCacheConfig{
servi... | go | {
"resource": ""
} |
q23645 | registerWithAuthServer | train | func (process *TeleportProcess) registerWithAuthServer(role teleport.Role, eventName string) {
serviceName := strings.ToLower(role.String())
process.RegisterCriticalFunc(fmt.Sprintf("register.%v", serviceName), func() error {
connector, err := process.reconnectToAuthService(role)
if err != nil {
return trace.W... | go | {
"resource": ""
} |
q23646 | getAdditionalPrincipals | train | func (process *TeleportProcess) getAdditionalPrincipals(role teleport.Role) ([]string, []string, error) {
var principals []string
var dnsNames []string
if process.Config.Hostname != "" {
principals = append(principals, process.Config.Hostname)
}
var addrs []utils.NetAddr
switch role {
case teleport.RoleProxy:
... | go | {
"resource": ""
} |
q23647 | initAuthStorage | train | func (process *TeleportProcess) initAuthStorage() (bk backend.Backend, err error) {
bc := &process.Config.Auth.StorageConfig
process.Debugf("Using %v backend.", bc.Type)
switch bc.Type {
case lite.GetName():
bk, err = lite.New(context.TODO(), bc.Params)
// legacy bolt backend, import all data into SQLite and re... | go | {
"resource": ""
} |
q23648 | WaitWithContext | train | func (process *TeleportProcess) WaitWithContext(ctx context.Context) {
local, cancel := context.WithCancel(ctx)
go func() {
defer cancel()
process.Supervisor.Wait()
}()
select {
case <-local.Done():
return
}
} | go | {
"resource": ""
} |
q23649 | StartShutdown | train | func (process *TeleportProcess) StartShutdown(ctx context.Context) context.Context {
process.BroadcastEvent(Event{Name: TeleportExitEvent, Payload: ctx})
localCtx, cancel := context.WithCancel(ctx)
go func() {
defer cancel()
process.Supervisor.Wait()
process.Debugf("All supervisor functions are completed.")
... | go | {
"resource": ""
} |
q23650 | Shutdown | train | func (process *TeleportProcess) Shutdown(ctx context.Context) {
localCtx := process.StartShutdown(ctx)
// wait until parent context closes
select {
case <-localCtx.Done():
process.Debugf("Process completed.")
}
} | go | {
"resource": ""
} |
q23651 | Close | train | func (process *TeleportProcess) Close() error {
process.BroadcastEvent(Event{Name: TeleportExitEvent})
process.Config.Keygen.Close()
var errors []error
localAuth := process.getLocalAuth()
if localAuth != nil {
errors = append(errors, process.localAuth.Close())
}
if process.storage != nil {
errors = append... | go | {
"resource": ""
} |
q23652 | initSelfSignedHTTPSCert | train | func initSelfSignedHTTPSCert(cfg *Config) (err error) {
log.Warningf("No TLS Keys provided, using self signed certificate.")
keyPath := filepath.Join(cfg.DataDir, defaults.SelfSignedKeyPath)
certPath := filepath.Join(cfg.DataDir, defaults.SelfSignedCertPath)
cfg.Proxy.TLSKey = keyPath
cfg.Proxy.TLSCert = certPat... | go | {
"resource": ""
} |
q23653 | GetKubeClient | train | func GetKubeClient(configPath string) (client *kubernetes.Clientset, config *rest.Config, err error) {
// if path to kubeconfig was provided, init config from it
if configPath != "" {
config, err = clientcmd.BuildConfigFromFlags("", configPath)
if err != nil {
return nil, nil, trace.Wrap(err)
}
} else {
/... | go | {
"resource": ""
} |
q23654 | GetKubeConfig | train | func GetKubeConfig(configPath string) (*rest.Config, error) {
// if path to kubeconfig was provided, init config from it
if configPath != "" {
return clientcmd.BuildConfigFromFlags("", configPath)
}
return rest.InClusterConfig()
} | go | {
"resource": ""
} |
q23655 | MustCreateProvisionToken | train | func MustCreateProvisionToken(token string, roles teleport.Roles, expires time.Time) ProvisionToken {
t, err := NewProvisionToken(token, roles, expires)
if err != nil {
panic(err)
}
return t
} | go | {
"resource": ""
} |
q23656 | NewProvisionToken | train | func NewProvisionToken(token string, roles teleport.Roles, expires time.Time) (ProvisionToken, error) {
t := &ProvisionTokenV2{
Kind: KindToken,
Version: V2,
Metadata: Metadata{
Name: token,
Expires: &expires,
Namespace: defaults.Namespace,
},
Spec: ProvisionTokenSpecV2{
Roles: roles,
... | go | {
"resource": ""
} |
q23657 | ProvisionTokensToV1 | train | func ProvisionTokensToV1(in []ProvisionToken) []ProvisionTokenV1 {
if in == nil {
return nil
}
out := make([]ProvisionTokenV1, len(in))
for i := range in {
out[i] = *in[i].V1()
}
return out
} | go | {
"resource": ""
} |
q23658 | ProvisionTokensFromV1 | train | func ProvisionTokensFromV1(in []ProvisionTokenV1) []ProvisionToken {
if in == nil {
return nil
}
out := make([]ProvisionToken, len(in))
for i := range in {
out[i] = in[i].V2()
}
return out
} | go | {
"resource": ""
} |
q23659 | SetRoles | train | func (p *ProvisionTokenV2) SetRoles(r teleport.Roles) {
p.Spec.Roles = r
} | go | {
"resource": ""
} |
q23660 | UnmarshalProvisionToken | train | func UnmarshalProvisionToken(data []byte, opts ...MarshalOption) (ProvisionToken, error) {
if len(data) == 0 {
return nil, trace.BadParameter("missing provision token data")
}
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
var h ResourceHeader
err = utils.FastUnmarshal(data,... | go | {
"resource": ""
} |
q23661 | MarshalProvisionToken | train | func MarshalProvisionToken(t ProvisionToken, opts ...MarshalOption) ([]byte, error) {
cfg, err := collectOptions(opts)
if err != nil {
return nil, trace.Wrap(err)
}
type token1 interface {
V1() *ProvisionTokenV1
}
type token2 interface {
V2() *ProvisionTokenV2
}
version := cfg.GetVersion()
switch version... | go | {
"resource": ""
} |
q23662 | NewClientConnWithDeadline | train | func NewClientConnWithDeadline(conn net.Conn, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
if config.Timeout > 0 {
conn.SetReadDeadline(time.Now().Add(config.Timeout))
}
c, chans, reqs, err := ssh.NewClientConn(conn, addr, config)
if err != nil {
return nil, err
}
if config.Timeout > 0 {
co... | go | {
"resource": ""
} |
q23663 | DialWithDeadline | train | func DialWithDeadline(network string, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
conn, err := net.DialTimeout(network, addr, config.Timeout)
if err != nil {
return nil, err
}
return NewClientConnWithDeadline(conn, addr, config)
} | go | {
"resource": ""
} |
q23664 | Dial | train | func (d directDial) Dial(network string, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
return DialWithDeadline(network, addr, config)
} | go | {
"resource": ""
} |
q23665 | Dial | train | func (d proxyDial) Dial(network string, addr string, config *ssh.ClientConfig) (*ssh.Client, error) {
// Build a proxy connection first.
pconn, err := dialProxy(context.Background(), d.proxyHost, addr)
if err != nil {
return nil, trace.Wrap(err)
}
if config.Timeout > 0 {
pconn.SetReadDeadline(time.Now().Add(co... | go | {
"resource": ""
} |
q23666 | DialerFromEnvironment | train | func DialerFromEnvironment(addr string) Dialer {
// Try and get proxy addr from the environment.
proxyAddr := getProxyAddress(addr)
// If no proxy settings are in environment return regular ssh dialer,
// otherwise return a proxy dialer.
if proxyAddr == "" {
log.Debugf("No proxy set in environment, returning di... | go | {
"resource": ""
} |
q23667 | New | train | func New(ctx context.Context, params backend.Params) (*EtcdBackend, error) {
var err error
if params == nil {
return nil, trace.BadParameter("missing etcd configuration")
}
// convert generic backend parameters structure to etcd config:
var cfg *Config
if err = utils.ObjectToStruct(params, &cfg); err != nil {
... | go | {
"resource": ""
} |
q23668 | KeepAlive | train | func (b *EtcdBackend) KeepAlive(ctx context.Context, lease backend.Lease, expires time.Time) error {
if lease.ID == 0 {
return trace.BadParameter("lease is not specified")
}
re, err := b.client.Get(ctx, prependPrefix(lease.Key), clientv3.WithSerializable(), clientv3.WithKeysOnly())
if err != nil {
return conver... | go | {
"resource": ""
} |
q23669 | seconds | train | func seconds(ttl time.Duration) int64 {
i := int64(ttl / time.Second)
if i <= 0 {
i = 1
}
return i
} | go | {
"resource": ""
} |
q23670 | GenerateKeys | train | func (a *AuthCommand) GenerateKeys() error {
keygen, err := native.New(context.TODO(), native.PrecomputeKeys(0))
if err != nil {
return trace.Wrap(err)
}
defer keygen.Close()
privBytes, pubBytes, err := keygen.GenerateKeyPair("")
if err != nil {
return trace.Wrap(err)
}
err = ioutil.WriteFile(a.genPubPath, ... | go | {
"resource": ""
} |
q23671 | GenerateAndSignKeys | train | func (a *AuthCommand) GenerateAndSignKeys(clusterApi auth.ClientI) error {
switch {
case a.genUser != "" && a.genHost == "":
return a.generateUserKeys(clusterApi)
case a.genUser == "" && a.genHost != "":
return a.generateHostKeys(clusterApi)
default:
return trace.BadParameter("--user or --host must be specifi... | go | {
"resource": ""
} |
q23672 | RotateCertAuthority | train | func (a *AuthCommand) RotateCertAuthority(client auth.ClientI) error {
req := auth.RotateRequest{
Type: services.CertAuthType(a.rotateType),
GracePeriod: &a.rotateGracePeriod,
TargetPhase: a.rotateTargetPhase,
}
if a.rotateManualMode {
req.Mode = services.RotationModeManual
} else {
req.Mode = serv... | go | {
"resource": ""
} |
q23673 | CollectOptions | train | func CollectOptions(opts []OpOption) (*OpConfig, error) {
cfg := OpConfig{}
for _, o := range opts {
if err := o(&cfg); err != nil {
return nil, trace.Wrap(err)
}
}
return &cfg, nil
} | go | {
"resource": ""
} |
q23674 | ValidateLockTTL | train | func ValidateLockTTL(ttl time.Duration) error {
if ttl == Forever || ttl > MaxLockDuration {
return trace.BadParameter("locks cannot exceed %v", MaxLockDuration)
}
return nil
} | go | {
"resource": ""
} |
q23675 | TTL | train | func TTL(clock clockwork.Clock, t time.Time) time.Duration {
if t.IsZero() {
return Forever
}
diff := t.UTC().Sub(clock.Now().UTC())
if diff < 0 {
return Forever
}
return diff
} | go | {
"resource": ""
} |
q23676 | AnyTTL | train | func AnyTTL(clock clockwork.Clock, times ...time.Time) time.Duration {
for _, t := range times {
if !t.IsZero() {
return TTL(clock, t)
}
}
return Forever
} | go | {
"resource": ""
} |
q23677 | NewConnectionsLimiter | train | func NewConnectionsLimiter(config LimiterConfig) (*ConnectionsLimiter, error) {
limiter := ConnectionsLimiter{
Mutex: &sync.Mutex{},
maxConnections: config.MaxConnections,
connections: make(map[string]int64),
}
ipExtractor, err := utils.NewExtractor("client.ip")
if err != nil {
return nil, trac... | go | {
"resource": ""
} |
q23678 | WrapHandle | train | func (l *ConnectionsLimiter) WrapHandle(h http.Handler) {
l.ConnLimiter.Wrap(h)
} | go | {
"resource": ""
} |
q23679 | AcquireConnection | train | func (l *ConnectionsLimiter) AcquireConnection(token string) error {
l.Lock()
defer l.Unlock()
if l.maxConnections == 0 {
return nil
}
numberOfConnections, exists := l.connections[token]
if !exists {
l.connections[token] = 1
return nil
}
if numberOfConnections >= l.maxConnections {
return trace.LimitE... | go | {
"resource": ""
} |
q23680 | ReleaseConnection | train | func (l *ConnectionsLimiter) ReleaseConnection(token string) {
l.Lock()
defer l.Unlock()
if l.maxConnections == 0 {
return
}
numberOfConnections, exists := l.connections[token]
if !exists {
log.Errorf("Trying to set negative number of connections")
} else {
if numberOfConnections <= 1 {
delete(l.conn... | go | {
"resource": ""
} |
q23681 | MinTTL | train | func MinTTL(a, b time.Duration) time.Duration {
if a == 0 {
return b
}
if b == 0 {
return a
}
if a < b {
return a
}
return b
} | go | {
"resource": ""
} |
q23682 | ToTTL | train | func ToTTL(c clockwork.Clock, tm time.Time) time.Duration {
now := c.Now().UTC()
if tm.IsZero() || tm.Before(now) {
return 0
}
return tm.Sub(now)
} | go | {
"resource": ""
} |
q23683 | UTC | train | func UTC(t *time.Time) {
if t == nil {
return
}
if t.IsZero() {
// to fix issue with timezones for tests
*t = time.Time{}
return
}
*t = t.UTC()
} | go | {
"resource": ""
} |
q23684 | ChangePassword | train | func (s *AuthServer) ChangePassword(req services.ChangePasswordReq) error {
// validate new password
err := services.VerifyPassword(req.NewPassword)
if err != nil {
return trace.Wrap(err)
}
authPreference, err := s.GetAuthPreference()
if err != nil {
return trace.Wrap(err)
}
userID := req.User
fn := func... | go | {
"resource": ""
} |
q23685 | CheckPasswordWOToken | train | func (s *AuthServer) CheckPasswordWOToken(user string, password []byte) error {
const errMsg = "invalid username or password"
err := services.VerifyPassword(password)
if err != nil {
return trace.BadParameter(errMsg)
}
hash, err := s.GetPasswordHash(user)
if err != nil && !trace.IsNotFound(err) {
return tra... | go | {
"resource": ""
} |
q23686 | GetOTPData | train | func (s *AuthServer) GetOTPData(user string) (string, []byte, error) {
// get otp key from backend
otpSecret, err := s.GetTOTP(user)
if err != nil {
return "", nil, trace.Wrap(err)
}
// create otp url
params := map[string][]byte{"secret": []byte(otpSecret)}
otpURL := utils.GenerateOTPURL("totp", user, params)... | go | {
"resource": ""
} |
q23687 | NewWhereParser | train | func NewWhereParser(ctx RuleContext) (predicate.Parser, error) {
return predicate.NewParser(predicate.Def{
Operators: predicate.Operators{
AND: predicate.And,
OR: predicate.Or,
NOT: predicate.Not,
},
Functions: map[string]interface{}{
"equals": predicate.Equals,
"contains": predicate.Contains,
... | go | {
"resource": ""
} |
q23688 | NewActionsParser | train | func NewActionsParser(ctx RuleContext) (predicate.Parser, error) {
return predicate.NewParser(predicate.Def{
Operators: predicate.Operators{},
Functions: map[string]interface{}{
"log": NewLogActionFn(ctx),
},
GetIdentifier: ctx.GetIdentifier,
GetProperty: predicate.GetStringMapValue,
})
} | go | {
"resource": ""
} |
q23689 | NewLogActionFn | train | func NewLogActionFn(ctx RuleContext) interface{} {
l := &LogAction{ctx: ctx}
writer, ok := ctx.(io.Writer)
if ok && writer != nil {
l.writer = writer
}
return l.Log
} | go | {
"resource": ""
} |
q23690 | Log | train | func (l *LogAction) Log(level, format string, args ...interface{}) predicate.BoolPredicate {
return func() bool {
ilevel, err := log.ParseLevel(level)
if err != nil {
ilevel = log.DebugLevel
}
var writer io.Writer
if l.writer != nil {
writer = l.writer
} else {
writer = log.StandardLogger().Writer... | go | {
"resource": ""
} |
q23691 | String | train | func (ctx *Context) String() string {
return fmt.Sprintf("user %v, resource: %v", ctx.User, ctx.Resource)
} | go | {
"resource": ""
} |
q23692 | GetResource | train | func (ctx *Context) GetResource() (Resource, error) {
if ctx.Resource == nil {
return nil, trace.NotFound("resource is not set in the context")
}
return ctx.Resource, nil
} | go | {
"resource": ""
} |
q23693 | GetIdentifier | train | func (ctx *Context) GetIdentifier(fields []string) (interface{}, error) {
switch fields[0] {
case UserIdentifier:
var user User
if ctx.User == nil {
user = emptyUser
} else {
user = ctx.User
}
return predicate.GetFieldByTag(user, teleport.JSON, fields[1:])
case ResourceIdentifier:
var resource Reso... | go | {
"resource": ""
} |
q23694 | ParseKey | train | func ParseKey(k []byte) (Key, error) {
key, err := hex.DecodeString(string(k))
if err != nil {
return nil, trace.Wrap(err)
}
return Key(key), nil
} | go | {
"resource": ""
} |
q23695 | Seal | train | func (k Key) Seal(plaintext []byte) ([]byte, error) {
block, err := aes.NewCipher([]byte(k))
if err != nil {
return nil, trace.Wrap(err)
}
aesgcm, err := cipher.NewGCM(block)
if err != nil {
return nil, trace.Wrap(err)
}
nonce := make([]byte, aesgcm.NonceSize())
_, err = io.ReadFull(rand.Reader, nonce)
i... | go | {
"resource": ""
} |
q23696 | Open | train | func (k Key) Open(ciphertext []byte) ([]byte, error) {
var data sealedData
err := json.Unmarshal(ciphertext, &data)
if err != nil {
return nil, trace.Wrap(err)
}
block, err := aes.NewCipher(k)
if err != nil {
return nil, trace.Wrap(err)
}
aesgcm, err := cipher.NewGCM(block)
if err != nil {
return nil,... | go | {
"resource": ""
} |
q23697 | NewForwarder | train | func NewForwarder(cfg ForwarderConfig) (*Forwarder, error) {
if err := cfg.CheckAndSetDefaults(); err != nil {
return nil, trace.Wrap(err)
}
diskLogger, err := NewDiskSessionLogger(DiskSessionLoggerConfig{
SessionID: cfg.SessionID,
DataDir: cfg.DataDir,
RecordSessions: cfg.RecordSessions,
Names... | go | {
"resource": ""
} |
q23698 | Close | train | func (l *Forwarder) Close() error {
l.Lock()
defer l.Unlock()
if l.isClosed {
return nil
}
l.isClosed = true
return l.sessionLogger.Finalize()
} | go | {
"resource": ""
} |
q23699 | WaitForDelivery | train | func (l *Forwarder) WaitForDelivery(ctx context.Context) error {
return l.ForwardTo.WaitForDelivery(ctx)
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.