identity_stub.go

  1package identity
  2
  3import (
  4	"encoding/json"
  5
  6	"github.com/MichaelMure/git-bug/repository"
  7	"github.com/MichaelMure/git-bug/util/lamport"
  8	"github.com/MichaelMure/git-bug/util/timestamp"
  9)
 10
 11var _ Interface = &IdentityStub{}
 12
 13// IdentityStub is an almost empty Identity, holding only the id.
 14// When a normal Identity is serialized into JSON, only the id is serialized.
 15// All the other data are stored in git in a chain of commit + a ref.
 16// When this JSON is deserialized, an IdentityStub is returned instead, to be replaced
 17// later by the proper Identity, loaded from the Repo.
 18type IdentityStub struct {
 19	id string
 20}
 21
 22func (i *IdentityStub) MarshalJSON() ([]byte, error) {
 23	return json.Marshal(struct {
 24		Id string `json:"id"`
 25	}{
 26		Id: i.id,
 27	})
 28}
 29
 30func (i *IdentityStub) UnmarshalJSON(data []byte) error {
 31	aux := struct {
 32		Id string `json:"id"`
 33	}{}
 34
 35	if err := json.Unmarshal(data, &aux); err != nil {
 36		return err
 37	}
 38
 39	i.id = aux.Id
 40
 41	return nil
 42}
 43
 44// Id return the Identity identifier
 45func (i *IdentityStub) Id() string {
 46	return i.id
 47}
 48
 49// HumanId return the Identity identifier truncated for human consumption
 50func (i *IdentityStub) HumanId() string {
 51	return FormatHumanID(i.Id())
 52}
 53
 54func (IdentityStub) Name() string {
 55	panic("identities needs to be properly loaded with identity.ReadLocal()")
 56}
 57
 58func (IdentityStub) Email() string {
 59	panic("identities needs to be properly loaded with identity.ReadLocal()")
 60}
 61
 62func (IdentityStub) Login() string {
 63	panic("identities needs to be properly loaded with identity.ReadLocal()")
 64}
 65
 66func (IdentityStub) AvatarUrl() string {
 67	panic("identities needs to be properly loaded with identity.ReadLocal()")
 68}
 69
 70func (IdentityStub) Keys() []Key {
 71	panic("identities needs to be properly loaded with identity.ReadLocal()")
 72}
 73
 74func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key {
 75	panic("identities needs to be properly loaded with identity.ReadLocal()")
 76}
 77
 78func (IdentityStub) DisplayName() string {
 79	panic("identities needs to be properly loaded with identity.ReadLocal()")
 80}
 81
 82func (IdentityStub) Validate() error {
 83	panic("identities needs to be properly loaded with identity.ReadLocal()")
 84}
 85
 86func (IdentityStub) Commit(repo repository.ClockedRepo) error {
 87	panic("identities needs to be properly loaded with identity.ReadLocal()")
 88}
 89
 90func (i *IdentityStub) CommitAsNeeded(repo repository.ClockedRepo) error {
 91	panic("identities needs to be properly loaded with identity.ReadLocal()")
 92}
 93
 94func (IdentityStub) IsProtected() bool {
 95	panic("identities needs to be properly loaded with identity.ReadLocal()")
 96}
 97
 98func (i *IdentityStub) LastModificationLamport() lamport.Time {
 99	panic("identities needs to be properly loaded with identity.ReadLocal()")
100}
101
102func (i *IdentityStub) LastModification() timestamp.Timestamp {
103	panic("identities needs to be properly loaded with identity.ReadLocal()")
104}