Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions extras/dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ func (m *Chainloop) Init(
// Path to the source repository to be attested
// +optional
repository *Directory,
// Workflow name to be used for the attestation, default empty
// This option is needed when using an API Token
// +optional
// Workflow name to be used for the attestation
workflowName string,
) (*Attestation, error) {
att := &Attestation{
Expand All @@ -60,7 +58,7 @@ func (m *Chainloop) Init(
}
// Append the contract revision to the args if provided
args := []string{
"attestation", "init", "--remote-state", "-o", "json",
"attestation", "init", "--remote-state", "-o", "json", "--workflow-name", workflowName,
}

if contractRevision != "" {
Expand All @@ -69,12 +67,6 @@ func (m *Chainloop) Init(
)
}

if workflowName != "" {
args = append(args,
"--workflow-name", workflowName,
)
}

info, err := att.
Container(0).
WithExec(args).
Expand Down Expand Up @@ -269,17 +261,31 @@ func (att *Attestation) Container(
}

// Generate, sign and push the attestation to the chainloop control plane
func (att *Attestation) Push(ctx context.Context, key, passphrase *Secret) (string, error) {
return att.
Container(0).
WithMountedSecret("/tmp/key.pem", key).
WithSecretVariable("CHAINLOOP_SIGNING_PASSWORD", passphrase).
WithExec([]string{
"attestation", "push",
"--remote-state",
"--attestation-id", att.AttestationID,
"--key", "/tmp/key.pem",
}).Stdout(ctx)
func (att *Attestation) Push(
ctx context.Context,
// The private key to sign the attestation
// +optional
key *Secret,
// The passphrase to decrypt the private key
// +optional
passphrase *Secret,
) (string, error) {
container := att.Container(0)
args := []string{
"attestation", "push",
"--remote-state",
"--attestation-id", att.AttestationID,
}

if key != nil {
container = container.WithMountedSecret("/tmp/key.pem", key)
args = append(args, "--key", "/tmp/key.pem")
}
if passphrase != nil {
container = container.WithSecretVariable("CHAINLOOP_SIGNING_PASSWORD", passphrase)
}

return container.WithExec(args).Stdout(ctx)
}

// Mark the attestation as failed
Expand Down