func NewUndecryptedCredentialValue() *CredentialValue {
	return &CredentialValue{
		cvtype: undecryptedCV,
	}
}
NewUndecryptedCredentialValue creates a CredentialValue with an undecrypted
value
package apitypes
import (
	"encoding/json"
	"errors"
	"reflect"
	"strconv"
	"github.com/manifoldco/torus-cli/identity"
	"github.com/manifoldco/torus-cli/pathexp"
)
var errMistmatchedType = errors.New("Mismatched type and value in credential")
const (
	unsetCV = iota
	stringCV
	intCV
	floatCV
	undecryptedCV  
)
type CredentialEnvelope struct {
	ID      *identity.ID `json:"id"`
	Version uint8        `json:"version"`
	Body    *Credential  `json:"body"`
}
type CredentialResp struct {
	ID      *identity.ID    `json:"id"`
	Version uint8           `json:"version"`
	Body    json.RawMessage `json:"body"`
}
type Credential interface {
	GetName() string
	GetOrgID() *identity.ID
	GetPathExp() *pathexp.PathExp
	GetProjectID() *identity.ID
	GetValue() *CredentialValue
}
type BaseCredential struct {
	Name      string           `json:"name"`
	OrgID     *identity.ID     `json:"org_id"`
	PathExp   *pathexp.PathExp `json:"pathexp"`
	ProjectID *identity.ID     `json:"project_id"`
	Value     *CredentialValue `json:"value"`
}
func (c *BaseCredential) GetName() string {
	return c.Name
}
func (c *BaseCredential) GetOrgID() *identity.ID {
	return c.OrgID
}
func (c *BaseCredential) GetPathExp() *pathexp.PathExp {
	return c.PathExp
}
func (c *BaseCredential) GetProjectID() *identity.ID {
	return c.ProjectID
}
func (c *BaseCredential) GetValue() *CredentialValue {
	if c.Value.cvtype == unsetCV {
		return nil
	}
	return c.Value
}
type CredentialV2 struct {
	BaseCredential
	State string `json:"state"`
}
func (c *CredentialV2) GetValue() *CredentialValue {
	if c.State == "unset" {  
		return nil
	}
	if c.Value == nil {  
		return nil
	}
	if c.Value.IsUnset() {  
		return nil
	}
	return c.Value
}
type CredentialValue struct {
	cvtype int
	value  string
	raw    interface{}
}
func (c *CredentialValue) IsUnset() bool {
	return c.cvtype == unsetCV
}
func (c *CredentialValue) IsUndecrypted() bool {
	return c.cvtype == undecryptedCV
}
func (c *CredentialValue) String() string {
	if c.cvtype == unsetCV {
		panic("CredentialValue has been unset")
	}
	if c.cvtype == undecryptedCV {
		panic("CredentialValue was not decrypted")
	}
	return c.value
}
type credentialImpl struct {
	Version uint8 `json:"version"`
	Body    struct {
		Type  string          `json:"type"`
		Value json.RawMessage `json:"value"`
	} `json:"body"`
}
func (c *CredentialValue) Raw() (interface{}, error) {
	if c.IsUnset() {
		return nil, errors.New("Cannot return raw value of an unset Credential")
	}
	return c.raw, nil
}
func (c *CredentialValue) MarshalJSON() ([]byte, error) {
	impl := credentialImpl{Version: 1}
	switch c.cvtype {
	case stringCV:
		impl.Body.Type = "string"
	case intCV:
		impl.Body.Type = "number"
	case floatCV:
		impl.Body.Type = "number"
	case unsetCV:
		impl.Body.Type = "undefined"
	case undecryptedCV:
		impl.Body.Type = "undecrypted"
	}
	if c.cvtype != unsetCV && c.cvtype != undecryptedCV {
		v, err := json.Marshal(c.raw)
		if err != nil {
			return nil, err
		}
		impl.Body.Value = v
	} else {
		impl.Body.Value = []byte(`""`)
	}
	b, err := json.Marshal(&impl)
	if err != nil {
		return nil, err
	}
	return []byte(strconv.Quote(string(b))), nil
}
func (c *CredentialValue) UnmarshalJSON(b []byte) error {
	impl := credentialImpl{}
	s, err := strconv.Unquote(string(b))
	if err != nil {
		return err
	}
	if len(s) == 0 {
		v := reflect.ValueOf(c).Elem()
		v.Set(reflect.Zero(v.Type()))
		return nil
	}
	err = json.Unmarshal([]byte(s), &impl)
	if err != nil {
		return err
	}
	switch impl.Body.Type {
	case "undefined":
		c.cvtype = unsetCV
	case "undecrypted":
		c.cvtype = undecryptedCV
	case "string":
		c.cvtype = stringCV
		var v string
		err := json.Unmarshal(impl.Body.Value, &v)
		if err != nil {
			return errMistmatchedType
		}
		c.raw = v
		c.value = v
	case "number":
		c.cvtype = stringCV
		var v json.Number
		err := json.Unmarshal(impl.Body.Value, &v)
		if err != nil {
			return errMistmatchedType
		}
		if i, err := v.Int64(); err == nil {
			c.cvtype = intCV
			c.raw = i
		} else if f, err := v.Float64(); err == nil {
			c.cvtype = floatCV
			c.raw = f
		}
		c.value = v.String()
	default:
		return errors.New("Decoding type " + impl.Body.Type + " is not supported")
	}
	return nil
}
func NewUnsetCredentialValue() *CredentialValue {
	return &CredentialValue{cvtype: unsetCV}
}
func NewStringCredentialValue(s string) *CredentialValue {
	return &CredentialValue{
		cvtype: stringCV,
		value:  s,
		raw:    s,
	}
}
func NewIntCredentialValue(i int) *CredentialValue {
	return &CredentialValue{
		cvtype: intCV,
		value:  strconv.Itoa(i),
		raw:    i,
	}
}
func NewFloatCredentialValue(f float64) *CredentialValue {
	return &CredentialValue{
		cvtype: floatCV,
		value:  strconv.FormatFloat(f, 'g', -1, 64),
		raw:    f,
	}
}