Skip to content

Commit

Permalink
fix(rpc): scanResponse rpc conversion for custom resources (#2692)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankk13 authored Aug 10, 2022
1 parent 517d2e0 commit babfb17
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pkg/rpc/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ func ConvertToRPCPkgs(pkgs []ftypes.Package) []*common.Package {
return rpcPkgs
}

func ConvertToRPCCustomResources(resources []ftypes.CustomResource) []*common.CustomResource {
var rpcResources []*common.CustomResource
for _, r := range resources {
data, err := structpb.NewValue(r.Data)
if err != nil {
log.Logger.Warn(err)
}
rpcResources = append(rpcResources, &common.CustomResource{
Type: r.Type,
FilePath: r.FilePath,
Layer: &common.Layer{
Digest: r.Layer.Digest,
DiffId: r.Layer.DiffID,
},
Data: data,
})
}
return rpcResources
}

// ConvertFromRPCPkgs returns list of Fanal package objects
func ConvertFromRPCPkgs(rpcPkgs []*common.Package) []ftypes.Package {
var pkgs []ftypes.Package
Expand Down Expand Up @@ -575,6 +595,7 @@ func ConvertToRPCScanResponse(results types.Results, fos *ftypes.OS) *scanner.Sc
Vulnerabilities: ConvertToRPCVulns(result.Vulnerabilities),
Misconfigurations: ConvertToRPCMisconfs(result.Misconfigurations),
Packages: ConvertToRPCPkgs(result.Packages),
CustomResources: ConvertToRPCCustomResources(result.CustomResources),
})
}

Expand Down

0 comments on commit babfb17

Please sign in to comment.