Skip to content

Commit

Permalink
Revert "Cleanup of gpg variables and improved error handling (#128)"
Browse files Browse the repository at this point in the history
This reverts commit 9f95a0c.
  • Loading branch information
guicaulada committed Aug 24, 2023
1 parent 9f95a0c commit 8e8232d
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions containers/base_rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package containers
import (
"encoding/base64"
"log"
"time"

"dagger.io/dagger"
)
Expand All @@ -27,38 +26,29 @@ func RPMContainer(d *dagger.Client, opts *GPGOpts) *dagger.Container {
if !opts.Sign {
return container
}
var gpgPublicKeySecret, gpgPrivateKeySecret, gpgPassphraseSecret *dagger.Secret

if sec, err := base64.StdEncoding.DecodeString(opts.GPGPublicKeyBase64); err == nil {
gpgPublicKeySecret = d.SetSecret("gpg-public-key", string(sec))
} else {
log.Printf("gpg-public-key-base64 cannot be decoded %s", err.Error())
}

if sec, err := base64.StdEncoding.DecodeString(opts.GPGPrivateKeyBase64); err == nil {
gpgPrivateKeySecret = d.SetSecret("gpg-private-key", string(sec))
var gpgPublicKeyBase64Secret, gpgPrivateKeyBase64Secret *dagger.Secret
if decodedGPGPublicKeyBase64Secret, err := base64.StdEncoding.DecodeString(opts.GPGPublicKeyBase64); err == nil {
gpgPublicKeyBase64Secret = d.SetSecret("gpg-public-key-base64", string(decodedGPGPublicKeyBase64Secret))
} else {
log.Printf("gpg-private-key-base64 cannot be decoded %s", err.Error())
log.Println("gpg-public-key-base64 cannot be decoded %w", err)
}

if sec, err := base64.StdEncoding.DecodeString(opts.GPGPassphraseBase64); err == nil {
gpgPassphraseSecret = d.SetSecret("gpg-passphrase-base64", string(sec))
if decodedGPGPrivateKeyBase64Secret, err := base64.StdEncoding.DecodeString(opts.GPGPrivateKeyBase64); err == nil {
gpgPrivateKeyBase64Secret = d.SetSecret("gpg-private-key-base64", string(decodedGPGPrivateKeyBase64Secret))
} else {
log.Printf("gpg-private-key-base64 cannot be decoded %s", err.Error())
log.Println("gpg-private-key-base64 cannot be decoded %w", err)
}

gpgPassphraseBase64Secret := d.SetSecret("gpg-passphrase-base64", opts.GPGPassphraseBase64)
return container.
WithSecretVariable("GPG_PUBLIC_KEY_BASE64", gpgPublicKeyBase64Secret).
WithSecretVariable("GPG_PRIVATE_KEY_BASE64", gpgPrivateKeyBase64Secret).
WithSecretVariable("GPG_PASSPHRASE_BASE64", gpgPassphraseBase64Secret).
WithExec([]string{"apt-get", "install", "-yq", "gnupg2"}).
WithExec([]string{"mkdir", "-p", "/root/.rpmdb/privkeys"}).
WithExec([]string{"mkdir", "-p", "/root/.rpmdb/passkeys"}).
WithExec([]string{"mkdir", "-p", "/root/.rpmdb/pubkeys"}).
WithEnvVariable("now", time.Now().String()).
WithSecretVariable("GPG_PUBLIC_KEY", gpgPublicKeySecret).
WithSecretVariable("GPG_PRIVATE_KEY", gpgPrivateKeySecret).
WithSecretVariable("GPG_PASSPHRASE", gpgPassphraseSecret).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PRIVATE_KEY\" > /root/.rpmdb/privkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PASSPHRASE\" > /root/.rpmdb/passkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PUBLIC_KEY\" > /root/.rpmdb/pubkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PRIVATE_KEY_BASE64\" > /root/.rpmdb/privkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PASSPHRASE_BASE64\" > /root/.rpmdb/passkeys/grafana.key"}).
WithExec([]string{"/bin/sh", "-c", "echo \"$GPG_PUBLIC_KEY_BASE64\" > /root/.rpmdb/pubkeys/grafana.key"}).
WithNewFile("/root/.rpmmacros", dagger.ContainerWithNewFileOpts{
Permissions: 0400,
Contents: RPMMacros,
Expand Down

0 comments on commit 8e8232d

Please sign in to comment.