identity

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package identity contains the identity data model and low-level related functions

Index

Constants

This section is empty.

Variables

View Source
var ErrIdentityNotExist = errors.New("identity doesn't exist")
View Source
var ErrMultipleIdentitiesSet = errors.New("multiple user identities set")
View Source
var ErrNoIdentitySet = errors.New("No identity is set.\n" +
	"To interact with bugs, an identity first needs to be created using " +
	"\"git bug user create\" or adopted with \"git bug user adopt\"")
View Source
var ErrNonFastForwardMerge = errors.New("non fast-forward identity merge")

Functions

func Fetch

func Fetch(repo repository.Repo, remote string) (string, error)

Fetch retrieve updates from a remote This does not change the local identities state

func GetUserIdentityId

func GetUserIdentityId(repo repository.Repo) (entity.Id, error)

func IsUserIdentitySet

func IsUserIdentitySet(repo repository.Repo) (bool, error)

IsUserIdentitySet say if the user has set his identity

func ListLocalIds

func ListLocalIds(repo repository.Repo) ([]entity.Id, error)

ListLocalIds list all the available local identity ids

func MergeAll

func MergeAll(repo repository.ClockedRepo, remote string) <-chan entity.MergeResult

MergeAll will merge all the available remote identity

func NewErrMultipleMatch

func NewErrMultipleMatch(matching []entity.Id) *entity.ErrMultipleMatch

func NewErrMultipleMatchIdentity

func NewErrMultipleMatchIdentity(matching []entity.Id) *entity.ErrMultipleMatch

func Pull

func Pull(repo repository.ClockedRepo, remote string) error

Pull will do a Fetch + MergeAll This function will return an error if a merge fail

func Push

func Push(repo repository.Repo, remote string) (string, error)

Push update a remote with the local changes

func ReadAllLocal

func ReadAllLocal(repo repository.ClockedRepo) <-chan StreamedIdentity

ReadAllLocal read and parse all local Identity

func ReadAllRemote

func ReadAllRemote(repo repository.ClockedRepo, remote string) <-chan StreamedIdentity

ReadAllRemote read and parse all remote Identity for a given remote

func RemoveIdentity

func RemoveIdentity(repo repository.ClockedRepo, id entity.Id) error

RemoveIdentity will remove a local identity from its entity.Id

func SetUserIdentity

func SetUserIdentity(repo repository.RepoConfig, identity *Identity) error

SetUserIdentity store the user identity's id in the git config

Types

type Identity

type Identity struct {
	// contains filtered or unexported fields
}

func GetUserIdentity

func GetUserIdentity(repo repository.Repo) (*Identity, error)

GetUserIdentity read the current user identity, set with a git config entry

func NewFromGitUser

func NewFromGitUser(repo repository.ClockedRepo) (*Identity, error)

NewFromGitUser will query the repository for user detail and build the corresponding Identity

func NewIdentity

func NewIdentity(repo repository.RepoClock, name string, email string) (*Identity, error)

func NewIdentityFull

func NewIdentityFull(repo repository.RepoClock, name string, email string, login string, avatarUrl string, keys []*Key) (*Identity, error)

func ReadLocal

func ReadLocal(repo repository.Repo, id entity.Id) (*Identity, error)

ReadLocal load a local Identity from the identities data available in git

func ReadRemote

func ReadRemote(repo repository.Repo, remote string, id string) (*Identity, error)

ReadRemote load a remote Identity from the identities data available in git

func (*Identity) AvatarUrl

func (i *Identity) AvatarUrl() string

AvatarUrl return the last version of the Avatar URL

func (*Identity) Commit

func (i *Identity) Commit(repo repository.ClockedRepo) error

Write the identity into the Repository. In particular, this ensure that the Id is properly set.

func (*Identity) CommitAsNeeded

func (i *Identity) CommitAsNeeded(repo repository.ClockedRepo) error

func (*Identity) DisplayName

func (i *Identity) DisplayName() string

DisplayName return a non-empty string to display, representing the identity, based on the non-empty values.

func (*Identity) Email

func (i *Identity) Email() string

Email return the last version of the email

func (*Identity) Id

func (i *Identity) Id() entity.Id

Id return the Identity identifier

func (*Identity) ImmutableMetadata

func (i *Identity) ImmutableMetadata() map[string]string

ImmutableMetadata return all metadata for this Identity, accumulated from each version. If multiple value are found, the first defined takes precedence.

func (*Identity) IsProtected

func (i *Identity) IsProtected() bool

IsProtected return true if the chain of git commits started to be signed. If that's the case, only signed commit with a valid key for this identity can be added.

func (*Identity) Keys

func (i *Identity) Keys() []*Key

Keys return the last version of the valid keys

func (*Identity) LastModification

func (i *Identity) LastModification() timestamp.Timestamp

LastModification return the timestamp at which the last version of the identity became valid.

func (*Identity) LastModificationLamports

func (i *Identity) LastModificationLamports() map[string]lamport.Time

LastModificationLamports return the lamport times at which the last version of the identity became valid.

func (*Identity) Login

func (i *Identity) Login() string

Login return the last version of the login

func (*Identity) MarshalJSON

func (i *Identity) MarshalJSON() ([]byte, error)

MarshalJSON will only serialize the id

func (*Identity) Merge

func (i *Identity) Merge(repo repository.Repo, other *Identity) (bool, error)

Merge will merge a different version of the same Identity

To make sure that an Identity history can't be altered, a strict fast-forward only policy is applied here. As an Identity should be tied to a single user, this should work in practice, but it does leave a possibility that a user would edit his Identity from two different repo concurrently and push the changes in a non-centralized network of repositories. In this case, it would result in some repo accepting one version and some other accepting another, preventing the network in general to converge to the same result. This would create a sort of partition of the network, and manual cleaning would be required.

An alternative approach would be to have a determinist rebase:

  • any commits present in both local and remote version would be kept, never changed.
  • newer commits would be merged in a linear chain of commits, ordered based on the Lamport time

However, this approach leave the possibility, in the case of a compromised crypto keys, of forging a new version with a bogus Lamport time to be inserted before a legit version, invalidating the correct version and hijacking the Identity. There would only be a short period of time when this would be possible (before the network converge) but I'm not confident enough to implement that. I choose the strict fast-forward only approach, despite its potential problem with two different version as mentioned above.

func (*Identity) MutableMetadata

func (i *Identity) MutableMetadata() map[string]string

MutableMetadata return all metadata for this Identity, accumulated from each version. If multiple value are found, the last defined takes precedence.

func (*Identity) Mutate

func (i *Identity) Mutate(repo repository.RepoClock, f func(orig *Mutator)) error

Mutate allow to create a new version of the Identity in one go

func (*Identity) Name

func (i *Identity) Name() string

Name return the last version of the name

func (*Identity) NeedCommit

func (i *Identity) NeedCommit() bool

func (*Identity) SetMetadata

func (i *Identity) SetMetadata(key string, value string)

SetMetadata store arbitrary metadata along the last not-commit version. If the version has been commit to git already, a new identical version is added and will need to be commit.

func (*Identity) SigningKey

func (i *Identity) SigningKey(repo repository.RepoKeyring) (*Key, error)

SigningKey return the key that should be used to sign new messages. If no key is available, return nil.

func (*Identity) UnmarshalJSON

func (i *Identity) UnmarshalJSON(data []byte) error

UnmarshalJSON will only read the id Users of this package are expected to run Load() to load the remaining data from the identities data in git.

func (*Identity) ValidKeysAtTime

func (i *Identity) ValidKeysAtTime(clockName string, time lamport.Time) []*Key

ValidKeysAtTime return the set of keys valid at a given lamport time

func (*Identity) Validate

func (i *Identity) Validate() error

Validate check if the Identity data is valid

type IdentityStub

type IdentityStub struct {
	// contains filtered or unexported fields
}

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.

func (IdentityStub) AvatarUrl

func (IdentityStub) AvatarUrl() string

func (IdentityStub) DisplayName

func (IdentityStub) DisplayName() string

func (IdentityStub) Email

func (IdentityStub) Email() string

func (*IdentityStub) Id

func (i *IdentityStub) Id() entity.Id

Id return the Identity identifier

func (IdentityStub) IsProtected

func (IdentityStub) IsProtected() bool

func (IdentityStub) Keys

func (IdentityStub) Keys() []*Key

func (*IdentityStub) LastModification

func (i *IdentityStub) LastModification() timestamp.Timestamp

func (*IdentityStub) LastModificationLamports

func (i *IdentityStub) LastModificationLamports() map[string]lamport.Time

func (IdentityStub) Login

func (IdentityStub) Login() string

func (*IdentityStub) MarshalJSON

func (i *IdentityStub) MarshalJSON() ([]byte, error)

func (IdentityStub) Name

func (IdentityStub) Name() string

func (*IdentityStub) NeedCommit

func (i *IdentityStub) NeedCommit() bool

func (*IdentityStub) SigningKey

func (i *IdentityStub) SigningKey(repo repository.RepoKeyring) (*Key, error)

func (*IdentityStub) UnmarshalJSON

func (i *IdentityStub) UnmarshalJSON(data []byte) error

func (IdentityStub) ValidKeysAtTime

func (IdentityStub) ValidKeysAtTime(_ string, _ lamport.Time) []*Key

func (IdentityStub) Validate

func (IdentityStub) Validate() error

type Interface

type Interface interface {
	entity.Interface

	// Name return the last version of the name
	// Can be empty.
	Name() string

	// DisplayName return a non-empty string to display, representing the
	// identity, based on the non-empty values.
	DisplayName() 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

	// SigningKey return the key that should be used to sign new messages. If no key is available, return nil.
	SigningKey(repo repository.RepoKeyring) (*Key, error)

	// ValidKeysAtTime return the set of keys valid at a given lamport time for a given clock of another entity
	// Can be empty.
	ValidKeysAtTime(clockName string, time lamport.Time) []*Key

	// LastModification return the timestamp at which the last version of the identity became valid.
	LastModification() timestamp.Timestamp

	// LastModificationLamports return the lamport times at which the last version of the identity became valid.
	LastModificationLamports() map[string]lamport.Time

	// IsProtected return true if the chain of git commits started to be signed.
	// If that's the case, only signed commit with a valid key for this identity can be added.
	IsProtected() bool

	// Validate check if the Identity data is valid
	Validate() error

	// NeedCommit indicate that the in-memory state changed and need to be committed in the repository
	NeedCommit() bool
}

func UnmarshalJSON

func UnmarshalJSON(raw json.RawMessage) (Interface, error)

Custom unmarshaling function to allow package user to delegate the decoding of an Identity and distinguish between an Identity and a Bare.

If the given message has a "id" field, it's considered being a proper Identity.

type Key

type Key struct {
	// contains filtered or unexported fields
}

func GenerateKey

func GenerateKey() *Key

GenerateKey generate a keypair (public+private) The type and configuration of the key is determined by the default value in go's OpenPGP.

func (*Key) Clone

func (k *Key) Clone() *Key

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() ([]byte, error)

func (*Key) PGPEntity

func (k *Key) PGPEntity() *openpgp.Entity

func (*Key) Private

func (k *Key) Private() *packet.PrivateKey

func (*Key) Public

func (k *Key) Public() *packet.PublicKey

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(data []byte) error

func (*Key) Validate

func (k *Key) Validate() error

type Mutator

type Mutator struct {
	Name      string
	Login     string
	Email     string
	AvatarUrl string
	Keys      []*Key
}

type SimpleResolver

type SimpleResolver struct {
	// contains filtered or unexported fields
}

SimpleResolver is a Resolver loading Identities directly from a Repo

func NewSimpleResolver

func NewSimpleResolver(repo repository.Repo) *SimpleResolver

func (*SimpleResolver) Resolve

func (r *SimpleResolver) Resolve(id entity.Id) (entity.Interface, error)

type StreamedIdentity

type StreamedIdentity struct {
	Identity *Identity
	Err      error
}

type StubResolver

type StubResolver struct{}

StubResolver is a Resolver that doesn't load anything, only returning IdentityStub instances

func NewStubResolver

func NewStubResolver() *StubResolver

func (*StubResolver) Resolve

func (s *StubResolver) Resolve(id entity.Id) (entity.Interface, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL