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
43func (i *IdentityStub) Id() string {
44 return i.id
45}
46
47func (IdentityStub) Name() string {
48 panic("identities needs to be properly loaded with identity.Read()")
49}
50
51func (IdentityStub) Email() string {
52 panic("identities needs to be properly loaded with identity.Read()")
53}
54
55func (IdentityStub) Login() string {
56 panic("identities needs to be properly loaded with identity.Read()")
57}
58
59func (IdentityStub) AvatarUrl() string {
60 panic("identities needs to be properly loaded with identity.Read()")
61}
62
63func (IdentityStub) Keys() []Key {
64 panic("identities needs to be properly loaded with identity.Read()")
65}
66
67func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key {
68 panic("identities needs to be properly loaded with identity.Read()")
69}
70
71func (IdentityStub) DisplayName() string {
72 panic("identities needs to be properly loaded with identity.Read()")
73}
74
75func (IdentityStub) Validate() error {
76 panic("identities needs to be properly loaded with identity.Read()")
77}
78
79func (IdentityStub) Commit(repo repository.Repo) error {
80 panic("identities needs to be properly loaded with identity.Read()")
81}
82
83func (IdentityStub) IsProtected() bool {
84 panic("identities needs to be properly loaded with identity.Read()")
85}