func NewSession(resp *apitypes.Self) (*Session, error) {
	switch resp.Type {
	case apitypes.UserSession:
		if _, ok := resp.Identity.(envelope.UserInf); !ok {
			return nil, errors.New("Identity must be a user object")
		}
		if _, ok := resp.Auth.(envelope.UserInf); !ok {
			return nil, errors.New("Auth must be a user object")
		}
	case apitypes.MachineSession:
		if _, ok := resp.Identity.(*envelope.Machine); !ok {
			return nil, errors.New("Identity must be a machine object")
		}
		if _, ok := resp.Auth.(*envelope.MachineToken); !ok {
			return nil, errors.New("Auth must be a machine token object")
		}
	default:
		return nil, errors.New("did not recognize session type")
	}
	return &Session{
		sessionType: resp.Type,
		identity:    resp.Identity,
		auth:        resp.Auth,
	}, nil
}
NewSession returns a new session constructed from the payload of the current
identity as returned from the Daemon
package api
import (
	"context"
	"encoding/json"
	"errors"
	"github.com/manifoldco/go-base64"
	"github.com/manifoldco/torus-cli/apitypes"
	"github.com/manifoldco/torus-cli/envelope"
	"github.com/manifoldco/torus-cli/identity"
)
var errUnknownSessionType = errors.New("Unknown session type")
type Session struct {
	sessionType apitypes.SessionType
	identity    envelope.Envelope
	auth        envelope.Envelope
}
func (s *Session) Type() apitypes.SessionType {
	return s.sessionType
}
func (s *Session) ID() *identity.ID {
	return s.identity.GetID()
}
func (s *Session) AuthID() *identity.ID {
	return s.auth.GetID()
}
func (s *Session) Username() string {
	if s.sessionType == apitypes.MachineSession {
		return s.identity.(*envelope.Machine).Body.Name
	}
	return s.identity.(envelope.UserInf).Username()
}
func (s *Session) Name() string {
	if s.sessionType == apitypes.MachineSession {
		return s.identity.(*envelope.Machine).Body.Name
	}
	return s.identity.(envelope.UserInf).Name()
}
func (s *Session) Email() string {
	if s.sessionType == apitypes.MachineSession {
		return "none"
	}
	return s.identity.(envelope.UserInf).Email()
}
func (s *Session) State() string {
	if s.sessionType == apitypes.MachineSession {
		return s.identity.(*envelope.Machine).Body.State
	}
	return s.identity.(envelope.UserInf).State()
}