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