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 // TODO: add a type marker
24 return json.Marshal(struct {
25 Id string `json:"id"`
26 }{
27 Id: i.id,
28 })
29}
30
31func (i *IdentityStub) UnmarshalJSON(data []byte) error {
32 aux := struct {
33 Id string `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() string {
47 return i.id
48}
49
50// HumanId return the Identity identifier truncated for human consumption
51func (i *IdentityStub) HumanId() string {
52 return FormatHumanID(i.Id())
53}
54
55func (IdentityStub) Name() string {
56 panic("identities needs to be properly loaded with identity.ReadLocal()")
57}
58
59func (IdentityStub) Email() string {
60 panic("identities needs to be properly loaded with identity.ReadLocal()")
61}
62
63func (IdentityStub) Login() string {
64 panic("identities needs to be properly loaded with identity.ReadLocal()")
65}
66
67func (IdentityStub) AvatarUrl() string {
68 panic("identities needs to be properly loaded with identity.ReadLocal()")
69}
70
71func (IdentityStub) Keys() []Key {
72 panic("identities needs to be properly loaded with identity.ReadLocal()")
73}
74
75func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key {
76 panic("identities needs to be properly loaded with identity.ReadLocal()")
77}
78
79func (IdentityStub) DisplayName() string {
80 panic("identities needs to be properly loaded with identity.ReadLocal()")
81}
82
83func (IdentityStub) Validate() error {
84 panic("identities needs to be properly loaded with identity.ReadLocal()")
85}
86
87func (IdentityStub) Commit(repo repository.ClockedRepo) error {
88 panic("identities needs to be properly loaded with identity.ReadLocal()")
89}
90
91func (i *IdentityStub) CommitAsNeeded(repo repository.ClockedRepo) error {
92 panic("identities needs to be properly loaded with identity.ReadLocal()")
93}
94
95func (IdentityStub) IsProtected() bool {
96 panic("identities needs to be properly loaded with identity.ReadLocal()")
97}
98
99func (i *IdentityStub) LastModificationLamport() lamport.Time {
100 panic("identities needs to be properly loaded with identity.ReadLocal()")
101}
102
103func (i *IdentityStub) LastModification() timestamp.Timestamp {
104 panic("identities needs to be properly loaded with identity.ReadLocal()")
105}