@@ -20,6 +20,7 @@ import (
2020 "time"
2121
2222 v1 "github.com/chainloop-dev/chainloop/app/cli/api/attestation/v1"
23+ pbc "github.com/chainloop-dev/chainloop/app/controlplane/api/workflowcontract/v1"
2324 "github.com/chainloop-dev/chainloop/internal/attestation/crafter"
2425)
2526
@@ -37,11 +38,11 @@ type AttestationStatusResult struct {
3738 WorkflowMeta * AttestationStatusWorkflowMeta
3839 Materials []AttestationStatusResultMaterial
3940 EnvVars map [string ]string
40- RunnerContext * AttestaionResultRunnerContext
41+ RunnerContext * AttestationResultRunnerContext
4142 DryRun bool
4243}
4344
44- type AttestaionResultRunnerContext struct {
45+ type AttestationResultRunnerContext struct {
4546 EnvVars map [string ]string
4647 JobURL , RunnerType string
4748}
@@ -51,7 +52,7 @@ type AttestationStatusWorkflowMeta struct {
5152}
5253
5354type AttestationStatusResultMaterial struct {
54- Name , Type , Value string
55+ * Material
5556 Set , IsOutput , Required bool
5657}
5758
@@ -93,12 +94,19 @@ func (action *AttestationStatus) Run() (*AttestationStatusResult, error) {
9394 // Materials
9495 for _ , m := range c .CraftingState .InputSchema .Materials {
9596 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 ,
97102 }
98103
104+ // If it has been added already we load the value
99105 if cm , found := c .CraftingState .Attestation .Materials [m .Name ]; found {
106+ if err := setMaterialValue (cm , materialResult .Material ); err != nil {
107+ return nil , err
108+ }
100109 materialResult .Set = true
101- materialResult .Value = getMaterialSetValue (cm )
102110 }
103111
104112 res .Materials = append (res .Materials , * materialResult )
@@ -114,7 +122,7 @@ func (action *AttestationStatus) Run() (*AttestationStatusResult, error) {
114122 }
115123
116124 res .EnvVars = envVars
117- res .RunnerContext = & AttestaionResultRunnerContext {
125+ res .RunnerContext = & AttestationResultRunnerContext {
118126 EnvVars : c .Runner .ResolveEnvVars (),
119127 RunnerType : att .RunnerType .String (),
120128 JobURL : att .RunnerUrl ,
@@ -123,15 +131,32 @@ func (action *AttestationStatus) Run() (*AttestationStatusResult, error) {
123131 return res , nil
124132}
125133
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 {
127148 switch m := w .GetM ().(type ) {
128149 case * v1.Attestation_Material_String_ :
129- return m .String_ .GetValue ()
150+ o . Value = m .String_ .GetValue ()
130151 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 ()
132154 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 )
134159 }
135160
136- return ""
161+ return nil
137162}
0 commit comments