portauthority icon indicating copy to clipboard operation
portauthority copied to clipboard

Error upserting policy with AllowedRiskSeverity as list

Open caipre opened this issue 7 years ago • 1 comments

A policy with AllowedRiskSeverity as a list fails to create:

$ curl -XPOST -H'content-type: application/json' -d '{"Policy":{"Name":"High","AllowedRiskSeverity":"[\"Negligible\",\"Low\",\"Medium\"]"}}' localhost:31700/v1/policies
{"Error":{"Message":"error upserting policy: pq: malformed array literal: \"{[\"Negligible\",\"Low\",\"Medium\"]}\""}}

The value is treated as a list when listing an image's vulnerabilities: https://github.com/target/portauthority/blob/f2513f0b45301c054188f90d45de229efd96aaa4/api/v1/routes.go#L962

Maybe there's some marshaling required here: https://github.com/target/portauthority/blob/master/pkg/datastore/pgsql/policy.go#L60 ? My golang isn't too strong. Will try to look more into this tomorrow.

caipre avatar May 10 '18 21:05 caipre

@caipre try it like this. AllowedRiskSeverity is a string on the input currently.

curl -XPOST -H'content-type: application/json' -d '{"Policy":{"Name":"High","AllowedRiskSeverity":"Negligible,Low,Medium"}}' http://localhost:31700/v1/policies

ErikThoreson avatar May 11 '18 13:05 ErikThoreson