Skip to content

Commit 494ae5d

Browse files
authored
feat(dagger): support non-artifact materials (#512)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 9c207d5 commit 494ae5d

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

extras/dagger/README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,24 @@ dagger call -m github.com/chainloop-dev/chainloop/extras/dagger \
3636

3737
### Add pieces of evidence ([docs](https://docs.chainloop.dev/getting-started/attestation-crafting#adding-materials))
3838

39+
You can attest pieces of evidence by providing its material name and its value, either in the form of a path to a file (`--path`) or a raw value (`--value`).
40+
41+
A path to a file is required for materials derived from artifacts, such as Software Bill Of materials, or any other file-based evidence.
42+
3943
```sh
44+
# Provide a material of kind artifact through its path
45+
dagger call -m github.com/chainloop-dev/chainloop/extras/dagger \
46+
--token env:CHAINLOOP_TOKEN attestation-add \
47+
--attestation-id $ATTESTATION_ID \
48+
--name my-sbom \
49+
--path ./path/to/sbom.json
50+
51+
# Or one with a raw value such as a container image reference
4052
dagger call -m github.com/chainloop-dev/chainloop/extras/dagger \
4153
--token env:CHAINLOOP_TOKEN attestation-add \
4254
--attestation-id $ATTESTATION_ID \
43-
--name [MATERIAL NAME] \
44-
--value [MATERIAL_VALUE]
55+
--name my-container-image \
56+
--value ghcr.io/chainloop-dev/chainloop
4557
```
4658

4759
### Sign and push ([docs](https://docs.chainloop.dev/getting-started/attestation-crafting#encode-sign-and-push-attestation))

extras/dagger/main.go

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,47 @@ func (m *Chainloop) AttestationStatus(ctx context.Context, attestationID string)
4646
"attestation", "status",
4747
"--remote-state",
4848
"--attestation-id", attestationID,
49+
"--full",
4950
}).Stdout(ctx)
5051
}
5152

5253
// Add a piece of evidence/material to the current attestation
53-
func (m *Chainloop) AttestationAdd(ctx context.Context, name string, value *File, attestationID string) (string, error) {
54-
fileName, err := value.Name(ctx)
55-
if err != nil {
56-
return "", fmt.Errorf("getting file name: %w", err)
54+
// The material value can be provided either in the form of a file or as a raw string
55+
// The file type is required for materials of kind ARTIFACT that are uploaded to the CAS
56+
func (m *Chainloop) AttestationAdd(
57+
ctx context.Context,
58+
// material name
59+
name string,
60+
// path to the file to be added
61+
// +optional
62+
path *File,
63+
// raw value to be added
64+
// +optional
65+
value string,
66+
attestationID string) (string, error) {
67+
if value != "" && path != nil {
68+
return "", fmt.Errorf("only one of material path or value can be provided")
5769
}
5870

59-
filePath := fmt.Sprintf("/tmp/%s", fileName)
71+
c := m.cliImage()
72+
// if the value is provided in a file we need to upload it to the container
73+
if path != nil {
74+
fileName, err := path.Name(ctx)
75+
if err != nil {
76+
return "", fmt.Errorf("getting file name: %w", err)
77+
}
6078

61-
return m.cliImage().
62-
WithFile(filePath, value).
63-
WithExec([]string{
64-
"attestation", "add",
65-
"--remote-state",
66-
"--attestation-id", attestationID,
67-
"--name", name,
68-
"--value", filePath,
69-
}).Stderr(ctx)
79+
value = fmt.Sprintf("/tmp/%s", fileName)
80+
c = c.WithFile(value, path)
81+
}
82+
83+
return c.WithExec([]string{
84+
"attestation", "add",
85+
"--remote-state",
86+
"--attestation-id", attestationID,
87+
"--name", name,
88+
"--value", value,
89+
}).Stderr(ctx)
7090
}
7191

7292
// Generate, sign and push the attestation to the control plane

0 commit comments

Comments
 (0)