Skip to content

Commit

Permalink
Cleanup of gpg variables and improved error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
zerok committed Aug 24, 2023
1 parent 59a698b commit 874ecb4
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions containers/base_rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ func RPMContainer(d *dagger.Client, opts *GPGOpts) *dagger.Container {
}
var gpgPublicKeyBase64Secret, gpgPrivateKeyBase64Secret *dagger.Secret
if decodedGPGPublicKeyBase64Secret, err := base64.StdEncoding.DecodeString(opts.GPGPublicKeyBase64); err == nil {
gpgPublicKeyBase64Secret = d.SetSecret("gpg-public-key-base64", string(decodedGPGPublicKeyBase64Secret))
gpgPublicKeyBase64Secret = d.SetSecret("gpg-public-key", string(decodedGPGPublicKeyBase64Secret))
} else {
log.Println("gpg-public-key-base64 cannot be decoded %w", err)
log.Printf("gpg-public-key-base64 cannot be decoded %s", err.Error())
}
if decodedGPGPrivateKeyBase64Secret, err := base64.StdEncoding.DecodeString(opts.GPGPrivateKeyBase64); err == nil {
gpgPrivateKeyBase64Secret = d.SetSecret("gpg-private-key-base64", string(decodedGPGPrivateKeyBase64Secret))
gpgPrivateKeyBase64Secret = d.SetSecret("gpg-private-key", string(decodedGPGPrivateKeyBase64Secret))
} else {
log.Println("gpg-private-key-base64 cannot be decoded %w", err)
log.Printf("gpg-private-key-base64 cannot be decoded %s", err.Error())
}
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"}).
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"}).
WithSecretVariable("GPG_PUBLIC_KEY", gpgPublicKeyBase64Secret).
WithSecretVariable("GPG_PRIVATE_KEY", gpgPrivateKeyBase64Secret).
WithSecretVariable("GPG_PASSPHRASE", gpgPassphraseBase64Secret).
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"}).
WithNewFile("/root/.rpmmacros", dagger.ContainerWithNewFileOpts{
Permissions: 0400,
Contents: RPMMacros,
Expand Down

0 comments on commit 874ecb4

Please sign in to comment.