1package identity
2
3import (
4 "encoding/json"
5
6 "github.com/MichaelMure/git-bug/entity"
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 entity.Id
20}
21
22func (i *IdentityStub) MarshalJSON() ([]byte, error) {
23 // TODO: add a type marker
24 return json.Marshal(struct {
25 Id entity.Id `json:"id"`
26 }{
27 Id: i.id,
28 })
29}
30
31func (i *IdentityStub) UnmarshalJSON(data []byte) error {
32 aux := struct {
33 Id entity.Id `json:"id"`
34 }{}
35
36 if err := json.Unmarshal(data, &aux); err != nil {
37 return err
38 }
39
40 i.id = aux.Id
41
42 return nil
43}
44
45// Id return the Identity identifier
46func (i *IdentityStub) Id() entity.Id {
47 return i.id
48}
49
50func (IdentityStub) Name() string {
51 panic("identities needs to be properly loaded with identity.ReadLocal()")
52}
53
54func (IdentityStub) DisplayName() 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 (i *IdentityStub) SigningKey() *Key {
75 panic("identities needs to be properly loaded with identity.ReadLocal()")
76}
77
78func (IdentityStub) ValidKeysAtTime(_ string, _ lamport.Time) []*Key {
79 panic("identities needs to be properly loaded with identity.ReadLocal()")
80}
81
82func (i *IdentityStub) LastModification() timestamp.Timestamp {
83 panic("identities needs to be properly loaded with identity.ReadLocal()")
84}
85
86func (i *IdentityStub) LastModificationLamports() map[string]lamport.Time {
87 panic("identities needs to be properly loaded with identity.ReadLocal()")
88}
89
90func (IdentityStub) IsProtected() bool {
91 panic("identities needs to be properly loaded with identity.ReadLocal()")
92}
93
94func (IdentityStub) Validate() error {
95 panic("identities needs to be properly loaded with identity.ReadLocal()")
96}
97
98func (i *IdentityStub) NeedCommit() bool {
99 return false
100}