Skip to content

Commit 8259cab

Browse files
authored
Put compliance check in run function (#576)
1 parent ee8a9e5 commit 8259cab

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

cmd/kosli/assertArtifact.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,26 @@ func (o *assertArtifactOptions) run(out io.Writer, args []string) error {
149149
return err
150150
}
151151

152-
return output.FormattedPrint(response.Body, o.output, out, 0,
152+
err = output.FormattedPrint(response.Body, o.output, out, 0,
153153
map[string]output.FormatOutputFunc{
154154
"table": printAssertAsTable,
155155
"json": output.PrintJson,
156156
})
157+
if err != nil {
158+
return err
159+
}
160+
161+
var evaluationResult map[string]interface{}
162+
err = json.Unmarshal([]byte(response.Body), &evaluationResult)
163+
if err != nil {
164+
return err
165+
}
166+
167+
isCompliant := evaluationResult["compliant"].(bool)
168+
if !isCompliant {
169+
return fmt.Errorf("Artifact is not compliant")
170+
}
171+
return nil
157172
}
158173

159174
func printAssertAsTable(raw string, out io.Writer, page int) error {
@@ -247,8 +262,5 @@ func printAssertAsTable(raw string, out io.Writer, page int) error {
247262
logger.Info(" See more details at %s", evaluationResult["html_url"].(string))
248263
}
249264

250-
if !isCompliant {
251-
return fmt.Errorf("Artifact is not compliant")
252-
}
253265
return nil
254266
}

0 commit comments

Comments
 (0)