// Regenerate regenerates a session store from old session ID to new one.
775949
func (p *MemProvider) Regenerate(oldsid, sid string) (RawStore, error) {
	if p.Exist(sid) {
		return nil, fmt.Errorf("new sid '%s' already exists", sid)
	}

	s, err := p.Read(oldsid)
	if err != nil {
		return nil, err
	}

	if err = p.Destory(oldsid); err != nil {
		return nil, err
	}

	s.(*MemStore).sid = sid

	p.lock.Lock()
	defer p.lock.Unlock()
	p.data[sid] = p.list.PushBack(s)
	return s, nil
}
997898
func (s *Session) Renew(args *structs.SessionSpecificRequest,
	reply *structs.IndexedSessions) error {
	if done, err := s.srv.forward("Session.Renew", args, args, reply); done {
		return err
	}
	defer metrics.MeasureSince([]string{"session", "renew"}, time.Now())

	// Get the session, from local state.
	state := s.srv.fsm.State()
	index, session, err := state.SessionGet(nil, args.Session)
	if err != nil {
		return err
	}

	reply.Index = index
	if session == nil {
		return nil
	}

	// Fetch the ACL token, if any, and apply the policy.
	rule, err := s.srv.ResolveToken(args.Token)
	if err != nil {
		return err
	}
	if rule != nil && s.srv.config.ACLEnforceVersion8 {
		if !rule.SessionWrite(session.Node) {
			return acl.ErrPermissionDenied
		}
	}

	// Reset the session TTL timer.
	reply.Sessions = structs.Sessions{session}
	if err := s.srv.resetSessionTimer(args.Session, session); err != nil {
		s.srv.logger.Printf("[ERR] consul.session: Session renew failed: %v", err)
		return err
	}

	return nil
}
1022079
func (r *RedisStorer) ResetExpiry(key string) error {
	return r.client.Expire(key, r.maxAge).Err()
}
1195401
func (m *Manager) Destroy(s *Session) error {
	return m.config.Store.Del(s.id, makeStoreOption(m, s))
}
820758
func (b *backend) ResetSession(_ context.Context) {
	b.lock.Lock()
	defer b.lock.Unlock()

	if b.session != nil {
		b.session.Close()
	}

	b.session = nil
}
643001
func (c *cmd) renewSession(id string, stopCh chan struct{}) {
	session := c.apiclient.Session()
	for {
		select {
		case <-time.After(rExecRenewInterval):
			_, _, err := session.Renew(id, nil)
			if err != nil {
				c.UI.Error(fmt.Sprintf("Session renew failed: %v", err))
				return
			}
		case <-stopCh:
			return
		}
	}
}
783136
func (p *NodbProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error) {
	if p.Exist(sid) {
		return nil, fmt.Errorf("new sid '%s' already exists", sid)
	}

	kvs := make([]byte, 0)
	if p.Exist(oldsid) {
		if kvs, err = p.c.Get([]byte(oldsid)); err != nil {
			return nil, err
		} else if _, err = p.c.Del([]byte(oldsid)); err != nil {
			return nil, err
		}
	}

	if err = p.c.Set([]byte(sid), kvs); err != nil {
		return nil, err
	} else if _, err = p.c.Expire([]byte(sid), p.expire); err != nil {
		return nil, err
	}

	var kv map[interface{}]interface{}
	if len(kvs) == 0 {
		kv = make(map[interface{}]interface{})
	} else {
		kv, err = session.DecodeGob([]byte(kvs))
		if err != nil {
			return nil, err
		}
	}

	return NewNodbStore(p.c, sid, p.expire, kv), nil
}
894207
func (m *Manager) Renew(w http.ResponseWriter, s *Session) error {
	s.data = make(Data)
	return m.Regenerate(w, s)
}
869264
func (store *store) Refresh() error {
	store.mu.Lock()
	defer store.mu.Unlock()

	return store.refresh(true)
}
208514
func (s *Service) RenewSession(ctx context.Context, session *platform.Session, newExpiration time.Time) error {
	if session == nil {
		return &platform.Error{
			Msg: "session is nil",
		}
	}
	session.ExpiresAt = newExpiration
	return s.PutSession(ctx, session)
}
1010096
func (ch *CredHub) Regenerate(name string) (credentials.Credential, error) {
	var cred credentials.Credential

	regenerateEndpoint := "/api/v1/data"

	requestBody := map[string]interface{}{}
	requestBody["name"] = name
	requestBody["regenerate"] = true

	resp, err := ch.Request(http.MethodPost, regenerateEndpoint, nil, requestBody, true)

	if err != nil {
		return credentials.Credential{}, err
	}

	defer resp.Body.Close()
	defer io.Copy(ioutil.Discard, resp.Body)
	dec := json.NewDecoder(resp.Body)
	err = dec.Decode(&cred)

	return cred, err
}
1193019
func (s *ScanService) sessionCreate(req *restful.Request, resp *restful.Response, sc *scan.Scan) {
	// TODO (m0sth8): Check permissions for this scan to create other session
	// TODO (m0sth8): Check permissions for this scan to create session with this plugin
	raw := &scan.Session{}
	if err := req.ReadEntity(raw); err != nil {
		logrus.Warn(stackerr.Wrap(err))
		resp.WriteServiceError(http.StatusBadRequest, services.WrongEntityErr)
		return
	}

	if raw.Step == nil {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("step is required"))
		return
	}

	if raw.Step.Plugin == "" {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("step.plugin is required"))
		return
	}

	//	if raw.Step.Conf == nil {
	//		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("step.conf is required"))
	//		return
	//	}

	if raw.Scan != sc.Id {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("wrong scan id"))
		return
	}
	if sc.Status != scan.StatusWorking {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("scan should have working status"))
		return
	}
	if raw.Parent == "" {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("parent field is required"))
		return
	}
	parent := sc.GetSession(raw.Parent)
	if parent == nil {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("parent not found"))
		return
	}
	if parent.Status != scan.StatusWorking {
		resp.WriteServiceError(http.StatusBadRequest, services.NewBadReq("parent should have working status"))
		return
	}

	mgr := s.Manager()
	defer mgr.Close()

	pl, err := mgr.Plugins.GetByName(raw.Step.Plugin)
	if err != nil {
		if mgr.IsNotFound(err) {
			resp.WriteServiceError(http.StatusBadRequest,
				services.NewBadReq(fmt.Sprintf("plugin %s is not found", raw.Step.Plugin)))
			return
		}
		logrus.Error(stackerr.Wrap(err))
		resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
		return
	}

	now := time.Now().UTC()
	sess := scan.Session{
		Id:     mgr.NewId(),
		Status: scan.StatusCreated,
		Scan:   sc.Id,
		Parent: parent.Id,
		Step:   raw.Step,
		Plugin: pl.Id,
		Dates: scan.Dates{
			Created: &now,
			Updated: &now,
		},
	}

	parent.Children = append(parent.Children, &sess)
	if err := mgr.Scans.Update(sc); err != nil {
		logrus.Error(stackerr.Wrap(err))
		resp.WriteServiceError(http.StatusInternalServerError, services.DbErr)
		return
	}

	s.Scheduler().UpdateScan(sc)

	resp.WriteHeader(http.StatusCreated)
	resp.WriteEntity(sess)
}
36834
func (s *Storage) Reset() {
	s.setBoltDB(storage.TotalCountKey, 0)
	s.setBoltDB(storage.IosSuccessKey, 0)
	s.setBoltDB(storage.IosErrorKey, 0)
	s.setBoltDB(storage.AndroidSuccessKey, 0)
	s.setBoltDB(storage.AndroidErrorKey, 0)
}
836121
func Regenerate(username string, all bool) error {
	c, err := client.New()

	if err != nil {
		return err
	}

	token, err := auth.Regenerate(c, username, all)

	if err != nil {
		return err
	}

	if username == "" && all == false {
		c.Token = token

		err = c.Save()

		if err != nil {
			return err
		}
	}

	fmt.Println("Token Regenerated")
	return nil
}
151779
func (p *PostgresProvider) Regenerate(oldsid, sid string) (_ session.RawStore, err error) {
	if p.Exist(sid) {
		return nil, fmt.Errorf("new sid '%s' already exists", sid)
	}

	if !p.Exist(oldsid) {
		if _, err = p.c.Exec("INSERT INTO session(key,data,expiry) VALUES($1,$2,$3)",
			oldsid, "", time.Now().Unix()); err != nil {
			return nil, err
		}
	}

	if _, err = p.c.Exec("UPDATE session SET key=$1 WHERE key=$2", sid, oldsid); err != nil {
		return nil, err
	}

	return p.Read(sid)
}
1004088
func (s *StorageOverseer) ResetExpiry(w http.ResponseWriter, r *http.Request) error {
	sessID, err := s.options.getCookieValue(w, r)
	if err != nil {
		return errors.Wrap(err, "unable to get session id from cookie")
	}

	// Reset the expiry of the server-side session
	err = s.Storer.ResetExpiry(sessID)
	if err != nil {
		return errors.Wrap(err, "unable to reset expiry of server side session")
	}

	// Reset the expiry in the client-side cookie
	if s.options.MaxAge != 0 {
		w.(cookieWriter).SetCookie(s.options.makeCookie(sessID))
	}

	return nil
}
968480
func (pder *CookieProvider) SessionRegenerate(oldsid, sid string) (Store, error) {
	return nil, nil
}