// OrdererAdminSession execute a gexec.Session as an orderer node admin user. This is used primarily
// to generate orderer configuration updates
516771
func (n *Network) OrdererAdminSession(o *Orderer, p *Peer, command Command) (*gexec.Session, error) {
	cmd := n.peerCommand(
		command,
		"CORE_PEER_LOCALMSPID=OrdererMSP",
		fmt.Sprintf("FABRIC_CFG_PATH=%s", n.PeerDir(p)),
		fmt.Sprintf("CORE_PEER_MSPCONFIGPATH=%s", n.OrdererUserMSPDir(o, "Admin")),
	)
	return n.StartSession(cmd, command.SessionName())
}
733841
func (engine *Engine) OrderBy(order string) *Session {
	session := engine.NewSession()
	session.isAutoClose = true
	return session.OrderBy(order)
}
986281
func (c *dbinitCmd) mongoSession() (*mgo.Session, error) {
	if c.dbType != "mongo" {
		return nil, nil
	}
	url := ""
	if c.user == "" || c.password == "" {
		url = c.host
	} else {
		url = c.user + ":" + c.password + "@" + c.host + "/" + c.dbName
	}
	return mgo.Dial(url)
}
509441
func handleSession(wsc *wsClient, icmd interface{}) (interface{}, error) {
	return &btcjson.SessionResult{SessionID: wsc.sessionID}, nil
}
31493
func (s *server) UpdateSession(req UpdateRequest) error {
	if err := req.Check(); err != nil {
		return trace.Wrap(err)
	}

	key := activeKey(req.Namespace, string(req.ID))

	// Try several times, then give up
	for i := 0; i < sessionUpdateAttempts; i++ {
		item, err := s.bk.Get(context.TODO(), key)
		if err != nil {
			return trace.Wrap(err)
		}

		var session Session
		if err := json.Unmarshal(item.Value, &session); err != nil {
			return trace.Wrap(err)
		}

		if req.TerminalParams != nil {
			session.TerminalParams = *req.TerminalParams
		}
		if req.Active != nil {
			session.Active = *req.Active
		}
		if req.Parties != nil {
			session.Parties = *req.Parties
		}
		newValue, err := json.Marshal(session)
		if err != nil {
			return trace.Wrap(err)
		}
		newItem := backend.Item{
			Key:     key,
			Value:   newValue,
			Expires: s.clock.Now().UTC().Add(s.activeSessionTTL),
		}

		_, err = s.bk.CompareAndSwap(context.TODO(), *item, newItem)
		if err != nil {
			if trace.IsCompareFailed(err) || trace.IsConnectionProblem(err) {
				s.clock.Sleep(sessionUpdateRetryPeriod)
				continue
			}
			return trace.Wrap(err)
		} else {
			return nil
		}
	}
	return trace.ConnectionProblem(nil, "failed concurrently update the session")
}
983147
func (k *KeybaseServiceBase) CurrentSession(
	ctx context.Context, sessionID int) (
	idutil.SessionInfo, error) {
	ctx = CtxWithRandomIDReplayable(
		ctx, CtxKeybaseServiceIDKey, CtxKeybaseServiceOpID, k.log)

	s, newSession, err := k.getCurrentSession(ctx, sessionID)
	if err != nil {
		return idutil.SessionInfo{}, err
	}

	if newSession && k.config != nil {
		// Don't hold the lock while calling `serviceLoggedIn`.
		_ = serviceLoggedIn(ctx, k.config, s, TLFJournalBackgroundWorkEnabled)
	}

	return s, nil
}
529205
func (c *Client) CreateSession(sess session.Session) error {
	if sess.Namespace == "" {
		return trace.BadParameter(MissingNamespaceError)
	}
	_, err := c.PostJSON(c.Endpoint("namespaces", sess.Namespace, "sessions"), createSessionReq{Session: sess})
	return trace.Wrap(err)
}
1322197
func NewSessionHandler(b *SessionBackend) *SessionHandler {
	h := &SessionHandler{
		Router: NewRouter(),
		Logger: b.Logger,

		PasswordsService: b.PasswordsService,
		SessionService:   b.SessionService,
	}

	h.HandlerFunc("POST", "/api/v2/signin", h.handleSignin)
	h.HandlerFunc("POST", "/api/v2/signout", h.handleSignout)
	return h
}
373357
func GetSession() (*mgo.Session, error) {
	var err error

	if mgoSession == nil {
		mgoSession, err = mgo.Dial(servers)
		if err != nil {
			return nil, err
		}
	}

	return mgoSession.Clone(), nil
}
875095
func newSession(maxAge int) *Session {
	uid, err := uuid.NewV4()
	if err != nil {
		panic(ErrNoSessionID)
	}
	return &Session{
		true, // is new
		internalSession{
			make(map[string]interface{}),
			uid.String(),
			time.Now(),
			time.Duration(maxAge) * time.Second,
		},
	}
}
479150
func PgReplicationOriginSessionSetup(db XODB, v0 string) error {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.pg_replication_origin_session_setup($1)`

	// run query
	XOLog(sqlstr)
	_, err = db.Exec(sqlstr)
	return err
}
983197
func NewSessionOptions(o *SessOptions) Session {
	now := time.Now()
	idLength := o.IDLength
	if idLength <= 0 {
		idLength = 18
	}
	timeout := o.Timeout
	if timeout == 0 {
		timeout = 30 * time.Minute
	}

	sess := sessionImpl{
		IDF:       genID(idLength),
		CreatedF:  now,
		AccessedF: now,
		AttrsF:    make(map[string]interface{}),
		TimeoutF:  timeout,
		mux:       &sync.RWMutex{},
	}

	if len(o.CAttrs) > 0 {
		sess.CAttrsF = make(map[string]interface{}, len(o.CAttrs))
		for k, v := range o.CAttrs {
			sess.CAttrsF[k] = v
		}
	}

	for k, v := range o.Attrs {
		sess.AttrsF[k] = v
	}

	return &sess
}
448493
func (c *Client) NewSession() (*Session, error) {
	ch, in, err := c.OpenChannel("session", nil)
	if err != nil {
		return nil, err
	}
	return newSession(ch, in)
}
962763
func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) (*Session, error) {
	if err := authorizeClient(client, authConfig, endpoint); err != nil {
		return nil, err
	}

	return newSession(client, authConfig, endpoint), nil
}
658915
func (s *Service) CreateSession(ctx context.Context, user string) (*platform.Session, error) {
	u, pe := s.findUserByName(ctx, user)
	if pe != nil {
		return nil, &platform.Error{
			Err: pe,
		}
	}

	sess := &platform.Session{}
	sess.ID = s.IDGenerator.ID()
	k, err := s.TokenGenerator.Token()
	if err != nil {
		return nil, &platform.Error{
			Err: err,
		}
	}
	sess.Key = k
	sess.UserID = u.ID
	sess.CreatedAt = time.Now()
	// TODO(desa): make this configurable
	sess.ExpiresAt = sess.CreatedAt.Add(time.Hour)
	// TODO(desa): not totally sure what to do here. Possibly we should have a maximal privilege permission.
	sess.Permissions = []platform.Permission{}

	if err := s.PutSession(ctx, sess); err != nil {
		return nil, err
	}

	return sess, nil
}
91018
func NewSession(ro *RequestOptions) *Session {
	if ro == nil {
		ro = &RequestOptions{}
	}

	ro.UseCookieJar = true

	return &Session{RequestOptions: ro, HTTPClient: BuildHTTPClient(*ro)}
}
1223921
func (s *SessionService) ExpireSession(ctx context.Context, key string) error {
	return s.ExpireSessionFn(ctx, key)
}