mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-08 22:30:41 +00:00
Add new flags for specifying GPG keyring manually when signing.
This commit is contained in:
+4
-5
@@ -16,11 +16,8 @@ func getSigner(cmd *commander.Command) (utils.Signer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
signer := &utils.GpgSigner{}
|
signer := &utils.GpgSigner{}
|
||||||
|
signer.SetKey(cmd.Flag.Lookup("gpg-key").Value.String())
|
||||||
key := cmd.Flag.Lookup("gpg-key").Value.String()
|
signer.SetKeyRing(cmd.Flag.Lookup("keyring").Value.String(), cmd.Flag.Lookup("secret-keyring").Value.String())
|
||||||
if key != "" {
|
|
||||||
signer.SetKey(key)
|
|
||||||
}
|
|
||||||
|
|
||||||
err := signer.Init()
|
err := signer.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -213,6 +210,8 @@ ex.
|
|||||||
cmd.Flag.String("distribution", "", "distribution name to publish")
|
cmd.Flag.String("distribution", "", "distribution name to publish")
|
||||||
cmd.Flag.String("component", "", "component name to publish")
|
cmd.Flag.String("component", "", "component name to publish")
|
||||||
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
cmd.Flag.String("gpg-key", "", "GPG key ID to use when signing the release")
|
||||||
|
cmd.Flag.String("keyring", "", "GPG keyring to use (instead of default)")
|
||||||
|
cmd.Flag.String("secret-keyring", "", "GPG secret keyring to use (instead of default)")
|
||||||
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
cmd.Flag.Bool("skip-signing", false, "don't sign Release files with GPG")
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
Vendored
+2
@@ -28,7 +28,9 @@ func (n *NullSigner) Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *NullSigner) SetKey(keyRef string) {
|
func (n *NullSigner) SetKey(keyRef string) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *NullSigner) SetKeyRing(keyring, secretKeyring string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NullSigner) DetachedSign(source string, destination string) error {
|
func (n *NullSigner) DetachedSign(source string, destination string) error {
|
||||||
|
|||||||
+26
-7
@@ -15,6 +15,7 @@ import (
|
|||||||
type Signer interface {
|
type Signer interface {
|
||||||
Init() error
|
Init() error
|
||||||
SetKey(keyRef string)
|
SetKey(keyRef string)
|
||||||
|
SetKeyRing(keyring, secretKeyring string)
|
||||||
DetachedSign(source string, destination string) error
|
DetachedSign(source string, destination string) error
|
||||||
ClearSign(source string, destination string) error
|
ClearSign(source string, destination string) error
|
||||||
}
|
}
|
||||||
@@ -35,7 +36,8 @@ var (
|
|||||||
|
|
||||||
// GpgSigner is implementation of Signer interface using gpg
|
// GpgSigner is implementation of Signer interface using gpg
|
||||||
type GpgSigner struct {
|
type GpgSigner struct {
|
||||||
keyRef string
|
keyRef string
|
||||||
|
keyring, secretKeyring string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetKey sets key ID to use when signing files
|
// SetKey sets key ID to use when signing files
|
||||||
@@ -43,6 +45,27 @@ func (g *GpgSigner) SetKey(keyRef string) {
|
|||||||
g.keyRef = keyRef
|
g.keyRef = keyRef
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetKeyring allows to set custom keyring and secretkeyring
|
||||||
|
func (g *GpgSigner) SetKeyRing(keyring, secretKeyring string) {
|
||||||
|
g.keyring, g.secretKeyring = keyring, secretKeyring
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GpgSigner) gpgArgs() []string {
|
||||||
|
args := []string{}
|
||||||
|
if g.keyring != "" {
|
||||||
|
args = append(args, "--no-default-keyring", "--keyring", g.keyring)
|
||||||
|
}
|
||||||
|
if g.secretKeyring != "" {
|
||||||
|
args = append(args, "--secret-keyring", g.secretKeyring)
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.keyRef != "" {
|
||||||
|
args = append(args, "-u", g.keyRef)
|
||||||
|
}
|
||||||
|
|
||||||
|
return args
|
||||||
|
}
|
||||||
|
|
||||||
// Init verifies availability of gpg & presence of keys
|
// Init verifies availability of gpg & presence of keys
|
||||||
func (g *GpgSigner) Init() error {
|
func (g *GpgSigner) Init() error {
|
||||||
output, err := exec.Command("gpg", "--list-keys").Output()
|
output, err := exec.Command("gpg", "--list-keys").Output()
|
||||||
@@ -62,9 +85,7 @@ func (g *GpgSigner) DetachedSign(source string, destination string) error {
|
|||||||
fmt.Printf("Signing file '%s' with gpg, please enter your passphrase when prompted:\n", source)
|
fmt.Printf("Signing file '%s' with gpg, please enter your passphrase when prompted:\n", source)
|
||||||
|
|
||||||
args := []string{"-o", destination, "--armor", "--yes"}
|
args := []string{"-o", destination, "--armor", "--yes"}
|
||||||
if g.keyRef != "" {
|
args = append(args, g.gpgArgs()...)
|
||||||
args = append(args, "-u", g.keyRef)
|
|
||||||
}
|
|
||||||
args = append(args, "--detach-sign", source)
|
args = append(args, "--detach-sign", source)
|
||||||
cmd := exec.Command("gpg", args...)
|
cmd := exec.Command("gpg", args...)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
@@ -74,9 +95,7 @@ func (g *GpgSigner) DetachedSign(source string, destination string) error {
|
|||||||
func (g *GpgSigner) ClearSign(source string, destination string) error {
|
func (g *GpgSigner) ClearSign(source string, destination string) error {
|
||||||
fmt.Printf("Clearsigning file '%s' with gpg, please enter your passphrase when prompted:\n", source)
|
fmt.Printf("Clearsigning file '%s' with gpg, please enter your passphrase when prompted:\n", source)
|
||||||
args := []string{"-o", destination, "--yes"}
|
args := []string{"-o", destination, "--yes"}
|
||||||
if g.keyRef != "" {
|
args = append(args, g.gpgArgs()...)
|
||||||
args = append(args, "-u", g.keyRef)
|
|
||||||
}
|
|
||||||
args = append(args, "--clearsign", source)
|
args = append(args, "--clearsign", source)
|
||||||
cmd := exec.Command("gpg", args...)
|
cmd := exec.Command("gpg", args...)
|
||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
|
|||||||
Reference in New Issue
Block a user