add signing key
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/kraken/internal/services/storage"
|
||||
"github.com/ProtonMail/go-crypto/openpgp"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/transport"
|
||||
@@ -118,17 +119,10 @@ func (g *Git) Commit(ctx context.Context, gitRepo *GitRepo) error {
|
||||
}
|
||||
|
||||
_, err = worktree.Commit("some-commit", &git.CommitOptions{
|
||||
All: true,
|
||||
Author: &object.Signature{
|
||||
Name: "kraken",
|
||||
Email: "kraken@kasperhermansen.com",
|
||||
When: time.Now(),
|
||||
},
|
||||
Committer: &object.Signature{
|
||||
Name: "kraken",
|
||||
Email: "kraken@kasperhermansen.com",
|
||||
When: time.Now(),
|
||||
},
|
||||
All: true,
|
||||
Author: &object.Signature{Name: "kraken", Email: "kraken@kasperhermansen.com", When: time.Now()},
|
||||
Committer: &object.Signature{Name: "kraken", Email: "kraken@kasperhermansen.com", When: time.Now()},
|
||||
SignKey: &openpgp.Entity{},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
63
internal/services/signer/openpgp.go
Normal file
63
internal/services/signer/openpgp.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package signer
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"git.front.kjuulh.io/kjuulh/curre"
|
||||
"github.com/ProtonMail/gopenpgp/v2/crypto"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type OpenPGP struct {
|
||||
logger *zap.Logger
|
||||
PrivateKeyRing *crypto.KeyRing
|
||||
config *OpenPgpConfig
|
||||
}
|
||||
|
||||
type OpenPgpConfig struct {
|
||||
PrivateKeyFilePath string
|
||||
PrivateKeyPassword string
|
||||
}
|
||||
|
||||
func NewOpenPGP(logger *zap.Logger, config *OpenPgpConfig) *OpenPGP {
|
||||
return &OpenPGP{
|
||||
logger: logger,
|
||||
config: config,
|
||||
}
|
||||
}
|
||||
|
||||
func NewOpenPGPApp(openPGP *OpenPGP) curre.Component {
|
||||
return curre.NewFunctionalComponent(&curre.FunctionalComponent{
|
||||
InitFunc: func(fc *curre.FunctionalComponent, ctx context.Context) error {
|
||||
|
||||
content, err := os.ReadFile(openPGP.config.PrivateKeyFilePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
privateKeyObj, err := crypto.NewKeyFromArmored(string(content))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
unlockedPrivateKeyRing, err := privateKeyObj.Unlock([]byte(openPGP.config.PrivateKeyPassword))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
privateKeyRing, err := crypto.NewKeyRing(unlockedPrivateKeyRing)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
openPGP.PrivateKeyRing = privateKeyRing
|
||||
|
||||
return nil
|
||||
},
|
||||
StartFunc: func(fc *curre.FunctionalComponent, ctx context.Context) error {
|
||||
return nil
|
||||
},
|
||||
StopFunc: func(fc *curre.FunctionalComponent, ctx context.Context) error {
|
||||
return nil
|
||||
},
|
||||
})
|
||||
|
||||
}
|
Reference in New Issue
Block a user