aboutsummaryrefslogtreecommitdiffstats
path: root/identity
diff options
context:
space:
mode:
Diffstat (limited to 'identity')
-rw-r--r--identity/bare.go37
-rw-r--r--identity/bare_test.go1
-rw-r--r--identity/common.go2
-rw-r--r--identity/identity.go22
-rw-r--r--identity/interface.go12
-rw-r--r--identity/version.go18
6 files changed, 80 insertions, 12 deletions
diff --git a/identity/bare.go b/identity/bare.go
index 58c278be..3e6ca32f 100644
--- a/identity/bare.go
+++ b/identity/bare.go
@@ -27,6 +27,7 @@ type Bare struct {
id entity.Id
name string
email string
+ login string
avatarUrl string
}
@@ -34,8 +35,8 @@ func NewBare(name string, email string) *Bare {
return &Bare{id: entity.UnsetId, name: name, email: email}
}
-func NewBareFull(name string, email string, avatarUrl string) *Bare {
- return &Bare{id: entity.UnsetId, name: name, email: email, avatarUrl: avatarUrl}
+func NewBareFull(name string, email string, login string, avatarUrl string) *Bare {
+ return &Bare{id: entity.UnsetId, name: name, email: email, login: login, avatarUrl: avatarUrl}
}
func deriveId(data []byte) entity.Id {
@@ -46,7 +47,7 @@ func deriveId(data []byte) entity.Id {
type bareIdentityJSON struct {
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
- Login string `json:"login,omitempty"` // Deprecated, only kept to have the same ID when reading an old value
+ Login string `json:"login,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
}
@@ -54,6 +55,7 @@ func (i *Bare) MarshalJSON() ([]byte, error) {
return json.Marshal(bareIdentityJSON{
Name: i.name,
Email: i.email,
+ Login: i.login,
AvatarUrl: i.avatarUrl,
})
}
@@ -70,6 +72,7 @@ func (i *Bare) UnmarshalJSON(data []byte) error {
i.name = aux.Name
i.email = aux.Email
+ i.login = aux.Login
i.avatarUrl = aux.AvatarUrl
return nil
@@ -108,6 +111,11 @@ func (i *Bare) Email() string {
return i.email
}
+// Login return the last version of the login
+func (i *Bare) Login() string {
+ return i.login
+}
+
// AvatarUrl return the last version of the Avatar URL
func (i *Bare) AvatarUrl() string {
return i.avatarUrl
@@ -126,13 +134,22 @@ func (i *Bare) ValidKeysAtTime(_ lamport.Time) []*Key {
// DisplayName return a non-empty string to display, representing the
// identity, based on the non-empty values.
func (i *Bare) DisplayName() string {
- return i.name
+ switch {
+ case i.name == "" && i.login != "":
+ return i.login
+ case i.name != "" && i.login == "":
+ return i.name
+ case i.name != "" && i.login != "":
+ return fmt.Sprintf("%s (%s)", i.name, i.login)
+ }
+
+ panic("invalid person data")
}
// Validate check if the Identity data is valid
func (i *Bare) Validate() error {
- if text.Empty(i.name) {
- return fmt.Errorf("name is not set")
+ if text.Empty(i.name) && text.Empty(i.login) {
+ return fmt.Errorf("either name or login should be set")
}
if strings.Contains(i.name, "\n") {
@@ -143,6 +160,14 @@ func (i *Bare) Validate() error {
return fmt.Errorf("name is not fully printable")
}
+ if strings.Contains(i.login, "\n") {
+ return fmt.Errorf("login should be a single line")
+ }
+
+ if !text.Safe(i.login) {
+ return fmt.Errorf("login is not fully printable")
+ }
+
if strings.Contains(i.email, "\n") {
return fmt.Errorf("email should be a single line")
}
diff --git a/identity/bare_test.go b/identity/bare_test.go
index 5aa50e40..335c8d37 100644
--- a/identity/bare_test.go
+++ b/identity/bare_test.go
@@ -18,6 +18,7 @@ func TestBare_Id(t *testing.T) {
func TestBareSerialize(t *testing.T) {
before := &Bare{
+ login: "login",
email: "email",
name: "name",
avatarUrl: "avatar",
diff --git a/identity/common.go b/identity/common.go
index 0fd2b274..007e10d6 100644
--- a/identity/common.go
+++ b/identity/common.go
@@ -37,7 +37,7 @@ func UnmarshalJSON(raw json.RawMessage) (Interface, error) {
b := &Bare{}
err = json.Unmarshal(raw, b)
- if err == nil && b.name != "" {
+ if err == nil && (b.name != "" || b.login != "") {
return b, nil
}
diff --git a/identity/identity.go b/identity/identity.go
index b5222a3e..6b71fa35 100644
--- a/identity/identity.go
+++ b/identity/identity.go
@@ -56,13 +56,14 @@ func NewIdentity(name string, email string) *Identity {
}
}
-func NewIdentityFull(name string, email string, avatarUrl string) *Identity {
+func NewIdentityFull(name string, email string, login string, avatarUrl string) *Identity {
return &Identity{
id: entity.UnsetId,
versions: []*Version{
{
name: name,
email: email,
+ login: login,
avatarURL: avatarUrl,
nonce: makeNonce(20),
},
@@ -282,6 +283,7 @@ func IsUserIdentitySet(repo repository.Repo) (bool, error) {
type Mutator struct {
Name string
+ Login string
Email string
AvatarUrl string
Keys []*Key
@@ -292,6 +294,7 @@ func (i *Identity) Mutate(f func(orig Mutator) Mutator) {
orig := Mutator{
Name: i.Name(),
Email: i.Email(),
+ Login: i.Login(),
AvatarUrl: i.AvatarUrl(),
Keys: i.Keys(),
}
@@ -302,6 +305,7 @@ func (i *Identity) Mutate(f func(orig Mutator) Mutator) {
i.versions = append(i.versions, &Version{
name: mutated.Name,
email: mutated.Email,
+ login: mutated.Login,
avatarURL: mutated.AvatarUrl,
keys: mutated.Keys,
})
@@ -510,6 +514,11 @@ func (i *Identity) Email() string {
return i.lastVersion().email
}
+// Login return the last version of the login
+func (i *Identity) Login() string {
+ return i.lastVersion().login
+}
+
// AvatarUrl return the last version of the Avatar URL
func (i *Identity) AvatarUrl() string {
return i.lastVersion().avatarURL
@@ -538,7 +547,16 @@ func (i *Identity) ValidKeysAtTime(time lamport.Time) []*Key {
// DisplayName return a non-empty string to display, representing the
// identity, based on the non-empty values.
func (i *Identity) DisplayName() string {
- return i.Name()
+ switch {
+ case i.Name() == "" && i.Login() != "":
+ return i.Login()
+ case i.Name() != "" && i.Login() == "":
+ return i.Name()
+ case i.Name() != "" && i.Login() != "":
+ return fmt.Sprintf("%s (%s)", i.Name(), i.Login())
+ }
+
+ panic("invalid person data")
}
// IsProtected return true if the chain of git commits started to be signed.
diff --git a/identity/interface.go b/identity/interface.go
index d138362d..bbb94be7 100644
--- a/identity/interface.go
+++ b/identity/interface.go
@@ -12,18 +12,30 @@ type Interface interface {
Id() entity.Id
// Name return the last version of the name
+ // Can be empty.
Name() string
// Email return the last version of the email
+ // Can be empty.
Email() string
+ // Login return the last version of the login
+ // Can be empty.
+ // Warning: this login can be defined when importing from a bridge but should *not* be
+ // used to identify an identity as multiple bridge with different login can map to the same
+ // identity. Use the metadata system for that usage instead.
+ Login() string
+
// AvatarUrl return the last version of the Avatar URL
+ // Can be empty.
AvatarUrl() string
// Keys return the last version of the valid keys
+ // Can be empty.
Keys() []*Key
// ValidKeysAtTime return the set of keys valid at a given lamport time
+ // Can be empty.
ValidKeysAtTime(time lamport.Time) []*Key
// DisplayName return a non-empty string to display, representing the
diff --git a/identity/version.go b/identity/version.go
index f9c7b262..757b029f 100644
--- a/identity/version.go
+++ b/identity/version.go
@@ -24,7 +24,8 @@ type Version struct {
unixTime int64
name string
- email string // as defined in git, not for bridges
+ email string // as defined in git or from a bridge when importing the identity
+ login string // from a bridge when importing the identity
avatarURL string
// The set of keys valid at that time, from this version onward, until they get removed
@@ -52,6 +53,7 @@ type VersionJSON struct {
UnixTime int64 `json:"unix_time"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty"`
+ Login string `json:"login,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
Keys []*Key `json:"pub_keys,omitempty"`
Nonce []byte `json:"nonce,omitempty"`
@@ -81,6 +83,7 @@ func (v *Version) MarshalJSON() ([]byte, error) {
UnixTime: v.unixTime,
Name: v.name,
Email: v.email,
+ Login: v.login,
AvatarUrl: v.avatarURL,
Keys: v.keys,
Nonce: v.nonce,
@@ -103,6 +106,7 @@ func (v *Version) UnmarshalJSON(data []byte) error {
v.unixTime = aux.UnixTime
v.name = aux.Name
v.email = aux.Email
+ v.login = aux.Login
v.avatarURL = aux.AvatarUrl
v.keys = aux.Keys
v.nonce = aux.Nonce
@@ -120,8 +124,8 @@ func (v *Version) Validate() error {
return fmt.Errorf("lamport time not set")
}
- if text.Empty(v.name) {
- return fmt.Errorf("name not set")
+ if text.Empty(v.name) && text.Empty(v.login) {
+ return fmt.Errorf("either name or login should be set")
}
if strings.Contains(v.name, "\n") {
@@ -132,6 +136,14 @@ func (v *Version) Validate() error {
return fmt.Errorf("name is not fully printable")
}
+ if strings.Contains(v.login, "\n") {
+ return fmt.Errorf("login should be a single line")
+ }
+
+ if !text.Safe(v.login) {
+ return fmt.Errorf("login is not fully printable")
+ }
+
if strings.Contains(v.email, "\n") {
return fmt.Errorf("email should be a single line")
}