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 }