1package identity
2
3import (
4 "encoding/json"
5
6 bootstrap "github.com/MichaelMure/git-bug/entity/boostrap"
7 "github.com/MichaelMure/git-bug/repository"
8 "github.com/MichaelMure/git-bug/util/lamport"
9 "github.com/MichaelMure/git-bug/util/timestamp"
10)
11
12var _ bootstrap.Identity = &IdentityStub{}
13
14// IdentityStub is an almost empty Identity, holding only the id.
15// When a normal Identity is serialized into JSON, only the id is serialized.
16// All the other data are stored in git in a chain of commit + a ref.
17// When this JSON is deserialized, an IdentityStub is returned instead, to be replaced
18// later by the proper Identity, loaded from the Repo.
19type IdentityStub struct {
20 id bootstrap.Id
21}
22
23func (i *IdentityStub) MarshalJSON() ([]byte, error) {
24 // TODO: add a type marker
25 return json.Marshal(struct {
26 Id bootstrap.Id `json:"id"`
27 }{
28 Id: i.id,
29 })
30}
31
32func (i *IdentityStub) UnmarshalJSON(data []byte) error {
33 aux := struct {
34 Id bootstrap.Id `json:"id"`
35 }{}
36
37 if err := json.Unmarshal(data, &aux); err != nil {
38 return err
39 }
40
41 i.id = aux.Id
42
43 return nil
44}
45
46// Id return the Identity identifier
47func (i *IdentityStub) Id() bootstrap.Id {
48 return i.id
49}
50
51func (IdentityStub) Name() string {
52 panic("identities needs to be properly loaded with identity.ReadLocal()")
53}
54
55func (IdentityStub) DisplayName() 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() []bootstrap.Key {
72 panic("identities needs to be properly loaded with identity.ReadLocal()")
73}
74
75func (i *IdentityStub) SigningKey(repo repository.RepoKeyring) (bootstrap.Key, error) {
76 panic("identities needs to be properly loaded with identity.ReadLocal()")
77}
78
79func (IdentityStub) ValidKeysAtTime(_ string, _ lamport.Time) []bootstrap.Key {
80 panic("identities needs to be properly loaded with identity.ReadLocal()")
81}
82
83func (i *IdentityStub) LastModification() timestamp.Timestamp {
84 panic("identities needs to be properly loaded with identity.ReadLocal()")
85}
86
87func (i *IdentityStub) LastModificationLamports() map[string]lamport.Time {
88 panic("identities needs to be properly loaded with identity.ReadLocal()")
89}
90
91func (IdentityStub) IsProtected() bool {
92 panic("identities needs to be properly loaded with identity.ReadLocal()")
93}
94
95func (IdentityStub) Validate() error {
96 panic("identities needs to be properly loaded with identity.ReadLocal()")
97}
98
99func (i *IdentityStub) NeedCommit() bool {
100 return false
101}