Implement credential commit object, but don't use it anywhere yet

---
type: change
message: Implement credential commit object, but don't use it anywhere yet
change_hash: AIJRxhlQQuDhoByl1nApcFrRhlS9bK+4w/6JYl8SHl9o
credentials:
- type: pgp_signature
  pub_key_id: 95C46FA6A41148AC
  body: iQIzBAABAgAdFiEEJ6tQKp6olvZKJ0lwlcRvpqQRSKwFAl5hjqYACgkQlcRvpqQRSKyD5Q/+MTE6eiKXA0dicHXzv7DR48BMmXwD9wgekF5s49hUOh70+zmPvSypTI3hbnN4lfRnubTvrCZDBwxwhb5q6DRNosNGoBdUj5ofzpsyOJwoy7+htPJrZci6aAzy2uTcVMdqyaqbrDx9RAXGpqui1pZlS+kyUWlhMy4WT6ilJEHVDwqzVw6YcemflcdE6tc+ufqbkmVSy9uAMHLd6a5iegsbX0g/qwME7Qx07yWsuqwfD6FMCeEwtwk9FIkIkPAASZz0u4BlNy6g2KtGrWRraO9i2sQJyLoXh1/vhxCEX9oq0HrzutECgodaDBIFCnZd4NrDSeRPRHKxYF1/rWCUIkPzTMtQR5tGY2CYMCfTC1gBzb5UuJlkAi/D6TTaZO1JWwl2J7R9701D0aEds8w3FFVxOmggwtXonX5mjkYMLyEGVzinPjgtQBgZJQDZ4mIXhUaG8U0vhmo5pQFLAokKXWTo/Jbwm8MZ6SaiLmtGzGm+VoU4sGyUmVURC9X3bv8UjxFJrDibOnmEkfodNzkBsMow0y2gw78XaAME5h4TlBqjCof5iFc9gIBZWskOJYXcEenjChYADwt6Yvfm9UHhXeP8DSb0UtXz3se/PkUrjsC8bCqESncDYyB8QvIcNQY3eiZvRnSTU+m67ME5fuh6ANK5yvwcUIficG9hAVroUwu5eU4=
  account: mediocregopher
This commit is contained in:
mediocregopher 2020-03-05 16:43:40 -07:00
parent 51af20fbc0
commit c87baa5192
3 changed files with 53 additions and 6 deletions

10
SPEC.md
View File

@ -193,10 +193,10 @@ credentials:
## Credential Commits
Commits of type `credential` contain one or more credentials for some set of
changes, and the change hash to which those credentials apply. The commit
message head is not spec'd, but should be a human-readable description of "who
is crediting what, and how".
Commits of type `credential` contain one or more credentials for some hash
(presumably a change hash, but in the future there may be other types). The
commit message head is not spec'd, but should be a human-readable description of
"who is crediting what, and how".
Example credential commit message:
@ -204,7 +204,7 @@ Example credential commit message:
some_user_id pgp sig of commits AAA..BBB with key CCC
---
change_hash: XXX
credentialed_hash: XXX
credentials:
- type: pgp_signature
account_id: some_user_id

View File

@ -40,6 +40,7 @@ type CommitInterface interface {
// field should be set on a Commit, unless otherwise noted.
type Commit struct {
Change *CommitChange `type:"change,default"`
Credential *CommitCredential `type:"credential"`
// Credentials represent all created Credentials for this commit, and can be
// set on all Commit objects regardless of other fields being set.

46
commit_signature.go Normal file
View File

@ -0,0 +1,46 @@
package dehub
import (
"dehub/yamlutil"
"encoding/base64"
"fmt"
"gopkg.in/src-d/go-git.v4/plumbing/object"
)
// CommitCredential describes the structure of a credential commit message.
type CommitCredential struct {
CredentialedHash yamlutil.Blob `yaml:"credentialed_hash"`
}
var _ CommitInterface = CommitCredential{}
// NewCommitCredential constructs and returns a Commit populated with a
// CommitCredential encompassing the given hash. The Credentials of the returned
// Commit will _not_ be filled in.
func (r *Repo) NewCommitCredential(hash []byte) (Commit, error) {
return Commit{
Credential: &CommitCredential{
CredentialedHash: hash,
},
}, nil
}
// MessageHead implements the method for the CommitInterface interface.
func (cc CommitCredential) MessageHead() (string, error) {
hash64 := base64.StdEncoding.EncodeToString(cc.CredentialedHash)
if len(hash64) > 6 {
hash64 = hash64[:6] + "..."
}
return fmt.Sprintf("Credential of hash %s", hash64), nil
}
// Hash implements the method for the CommitInterface.
func (cc CommitCredential) Hash(_, _ *object.Tree) ([]byte, error) {
return cc.CredentialedHash, nil
}
// GetHash implements the method for the CommitInterface.
func (cc CommitCredential) GetHash() []byte {
return cc.CredentialedHash
}