@@ -20,6 +20,7 @@ import (
20
20
"time"
21
21
22
22
v1 "github.com/chainloop-dev/chainloop/app/cli/api/attestation/v1"
23
+ pbc "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
23
24
"github.com/chainloop-dev/chainloop/internal/attestation/crafter"
24
25
)
25
26
@@ -37,11 +38,11 @@ type AttestationStatusResult struct {
37
38
WorkflowMeta * AttestationStatusWorkflowMeta
38
39
Materials []AttestationStatusResultMaterial
39
40
EnvVars map [string ]string
40
- RunnerContext * AttestaionResultRunnerContext
41
+ RunnerContext * AttestationResultRunnerContext
41
42
DryRun bool
42
43
}
43
44
44
- type AttestaionResultRunnerContext struct {
45
+ type AttestationResultRunnerContext struct {
45
46
EnvVars map [string ]string
46
47
JobURL , RunnerType string
47
48
}
@@ -51,7 +52,7 @@ type AttestationStatusWorkflowMeta struct {
51
52
}
52
53
53
54
type AttestationStatusResultMaterial struct {
54
- Name , Type , Value string
55
+ * Material
55
56
Set , IsOutput , Required bool
56
57
}
57
58
@@ -93,12 +94,19 @@ func (action *AttestationStatus) Run() (*AttestationStatusResult, error) {
93
94
// Materials
94
95
for _ , m := range c .CraftingState .InputSchema .Materials {
95
96
materialResult := & AttestationStatusResultMaterial {
96
- Name : m .Name , Type : m .Type .String (), IsOutput : m .Output , Required : ! m .Optional ,
97
+ Material : & Material {
98
+ Name : m .Name , Type : m .Type .String (),
99
+ Annotations : pbAnnotationsToAction (m .Annotations ),
100
+ },
101
+ IsOutput : m .Output , Required : ! m .Optional ,
97
102
}
98
103
104
+ // If it has been added already we load the value
99
105
if cm , found := c .CraftingState .Attestation .Materials [m .Name ]; found {
106
+ if err := setMaterialValue (cm , materialResult .Material ); err != nil {
107
+ return nil , err
108
+ }
100
109
materialResult .Set = true
101
- materialResult .Value = getMaterialSetValue (cm )
102
110
}
103
111
104
112
res .Materials = append (res .Materials , * materialResult )
@@ -114,7 +122,7 @@ func (action *AttestationStatus) Run() (*AttestationStatusResult, error) {
114
122
}
115
123
116
124
res .EnvVars = envVars
117
- res .RunnerContext = & AttestaionResultRunnerContext {
125
+ res .RunnerContext = & AttestationResultRunnerContext {
118
126
EnvVars : c .Runner .ResolveEnvVars (),
119
127
RunnerType : att .RunnerType .String (),
120
128
JobURL : att .RunnerUrl ,
@@ -123,15 +131,32 @@ func (action *AttestationStatus) Run() (*AttestationStatusResult, error) {
123
131
return res , nil
124
132
}
125
133
126
- func getMaterialSetValue (w * v1.Attestation_Material ) string {
134
+ func pbAnnotationsToAction (in []* pbc.Annotation ) []* Annotation {
135
+ res := make ([]* Annotation , 0 , len (in ))
136
+
137
+ for _ , a := range in {
138
+ res = append (res , & Annotation {
139
+ Name : a .GetName (),
140
+ Value : a .GetValue (),
141
+ })
142
+ }
143
+
144
+ return res
145
+ }
146
+
147
+ func setMaterialValue (w * v1.Attestation_Material , o * Material ) error {
127
148
switch m := w .GetM ().(type ) {
128
149
case * v1.Attestation_Material_String_ :
129
- return m .String_ .GetValue ()
150
+ o . Value = m .String_ .GetValue ()
130
151
case * v1.Attestation_Material_ContainerImage_ :
131
- return fmt .Sprintf ("%s@%s" , m .ContainerImage .GetName (), m .ContainerImage .GetDigest ())
152
+ o .Value = m .ContainerImage .GetName ()
153
+ o .Hash = m .ContainerImage .GetDigest ()
132
154
case * v1.Attestation_Material_Artifact_ :
133
- return fmt .Sprintf ("%s@%s" , m .Artifact .GetName (), m .Artifact .GetDigest ())
155
+ o .Value = m .Artifact .GetName ()
156
+ o .Hash = m .Artifact .GetDigest ()
157
+ default :
158
+ return fmt .Errorf ("unknown material type: %T" , m )
134
159
}
135
160
136
- return ""
161
+ return nil
137
162
}
0 commit comments