From d90bf4892aadcae34133114fe9083f7e3b49dfb3 Mon Sep 17 00:00:00 2001 From: Christian Prando Date: Thu, 8 Apr 2021 14:49:17 -0600 Subject: [PATCH] UD-7238: Adds files to support the hub rapid scans. Implements the first method to kick-off a rapid scan. --- hubapi/rapid-scans-api.go | 19 +++++++++++++++++ hubclient/rapid-scans-client.go | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 hubapi/rapid-scans-api.go create mode 100644 hubclient/rapid-scans-client.go diff --git a/hubapi/rapid-scans-api.go b/hubapi/rapid-scans-api.go new file mode 100644 index 0000000..d7993b2 --- /dev/null +++ b/hubapi/rapid-scans-api.go @@ -0,0 +1,19 @@ +// Copyright 2021 Synopsys, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package hubapi + +const ( + ContentTypeRapidScan = "application/vnd.blackducksoftware.developer-scan-1-ld-2+json" +) diff --git a/hubclient/rapid-scans-client.go b/hubclient/rapid-scans-client.go new file mode 100644 index 0000000..181b7bc --- /dev/null +++ b/hubclient/rapid-scans-client.go @@ -0,0 +1,36 @@ +// Copyright 2021 Synopsys, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package hubclient + +import ( + "github.com/blackducksoftware/hub-client-go/hubapi" + log "github.com/sirupsen/logrus" +) + +const ( + apiDeveloperScans = "/api/developer-scans" +) + +func (c *Client) StartRapidScan(bdioHeaderContent string) (error, string) { + rapidScansURL := c.baseURL + apiDeveloperScans + result, err := c.HttpPostJSON(rapidScansURL, bdioHeaderContent, hubapi.ContentTypeRapidScan, 200) + + if err != nil { + log.Errorf("Error kicking off a rapid scan.", err) + return err, "" + } + + return nil, result +}