git-bug/identity/identity_stub.go

106 lines
2.8 KiB
Go
Raw Normal View History

2019-02-01 14:22:00 +03:00
package identity
import (
"encoding/json"
"github.com/MichaelMure/git-bug/repository"
"github.com/MichaelMure/git-bug/util/lamport"
"github.com/MichaelMure/git-bug/util/timestamp"
2019-02-01 14:22:00 +03:00
)
var _ Interface = &IdentityStub{}
// IdentityStub is an almost empty Identity, holding only the id.
// When a normal Identity is serialized into JSON, only the id is serialized.
// All the other data are stored in git in a chain of commit + a ref.
// When this JSON is deserialized, an IdentityStub is returned instead, to be replaced
// later by the proper Identity, loaded from the Repo.
type IdentityStub struct {
id string
}
func (i *IdentityStub) MarshalJSON() ([]byte, error) {
// TODO: add a type marker
2019-02-01 14:22:00 +03:00
return json.Marshal(struct {
Id string `json:"id"`
}{
Id: i.id,
})
}
func (i *IdentityStub) UnmarshalJSON(data []byte) error {
aux := struct {
Id string `json:"id"`
}{}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
i.id = aux.Id
return nil
}
2019-02-24 20:49:12 +03:00
// Id return the Identity identifier
2019-02-01 14:22:00 +03:00
func (i *IdentityStub) Id() string {
return i.id
}
2019-02-24 20:49:12 +03:00
// HumanId return the Identity identifier truncated for human consumption
func (i *IdentityStub) HumanId() string {
return FormatHumanID(i.Id())
}
2019-02-01 14:22:00 +03:00
func (IdentityStub) Name() string {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (IdentityStub) Email() string {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (IdentityStub) Login() string {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (IdentityStub) AvatarUrl() string {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (IdentityStub) Keys() []Key {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (IdentityStub) DisplayName() string {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (IdentityStub) Validate() error {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
2019-02-19 02:19:27 +03:00
func (IdentityStub) Commit(repo repository.ClockedRepo) error {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
2019-02-19 02:19:27 +03:00
func (i *IdentityStub) CommitAsNeeded(repo repository.ClockedRepo) error {
2019-02-16 19:32:30 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
}
2019-02-01 14:22:00 +03:00
func (IdentityStub) IsProtected() bool {
2019-02-03 21:55:35 +03:00
panic("identities needs to be properly loaded with identity.ReadLocal()")
2019-02-01 14:22:00 +03:00
}
func (i *IdentityStub) LastModificationLamport() lamport.Time {
panic("identities needs to be properly loaded with identity.ReadLocal()")
}
func (i *IdentityStub) LastModification() timestamp.Timestamp {
panic("identities needs to be properly loaded with identity.ReadLocal()")
}