Skip to content

Commit

Permalink
Merge pull request blackducksoftware#35 from tandr/common-base
Browse files Browse the repository at this point in the history
Common bases, drop juju, add fields
  • Loading branch information
tandr authored Oct 11, 2019
2 parents 8dc844e + c379ddc commit 1b3e6f8
Show file tree
Hide file tree
Showing 34 changed files with 1,968 additions and 1,926 deletions.
10 changes: 5 additions & 5 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions hubapi/bom-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package hubapi

type BomComponentList struct {
TotalCount uint32 `json:"totalCount"`
Items []BomComponent `json:"items"`
Meta Meta `json:"_meta"`
ItemsListBase
Items []BomComponent `json:"items"`
}

type BomComponent struct {
Expand All @@ -41,9 +40,8 @@ type BomComponent struct {
}

type BomVulnerableComponentList struct {
TotalCount uint32 `json:"totalCount"`
Items []BomVulnerableComponent `json:"items"`
Meta Meta `json:"_meta"`
ItemsListBase
Items []BomVulnerableComponent `json:"items"`
}

type BomVulnerableComponent struct {
Expand All @@ -57,7 +55,7 @@ type BomVulnerableComponent struct {
Meta Meta `json:"_meta"`
}

type VulnerabilityWithRemediation struct {
type VulnerabilityBase struct {
VulnerabilityName string `json:"vulnerabilityName"`
Description string `json:"description"`
VulnerabilityPublishedDate string `json:"vulnerabilityPublishedDate"`
Expand All @@ -67,12 +65,16 @@ type VulnerabilityWithRemediation struct {
ImpactSubscore float32 `json:"impactSubscore"`
Source string `json:"source"`
Severity string `json:"severity"`
RemediationStatus string `json:"remediationStatus"`
RemediationCreatedAt string `json:"remediationCreatedAt"`
RemediationUpdatedAt string `json:"remediationUpdatedAt"`
CweId string `json:"cweId,omitempty"`
}

type VulnerabilityWithRemediation struct {
VulnerabilityBase
RemediationStatus string `json:"remediationStatus"`
RemediationCreatedAt string `json:"remediationCreatedAt"`
RemediationUpdatedAt string `json:"remediationUpdatedAt"`
}

type BomRiskProfile struct {
Counts []BomRiskProfileItem `json:"counts"`
}
Expand Down
10 changes: 4 additions & 6 deletions hubapi/codelocations-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ package hubapi
import "fmt"

type CodeLocationList struct {
TotalCount uint32 `json:"totalCount"`
Items []CodeLocation `json:"items"`
Meta Meta `json:"_meta"`
ItemsListBase
Items []CodeLocation `json:"items"`
}

type CodeLocation struct {
Expand All @@ -33,9 +32,8 @@ type CodeLocation struct {
}

type ScanSummaryList struct {
TotalCount uint32 `json:"totalCount"`
Items []ScanSummary `json:"items"`
Meta Meta `json:"_meta"`
ItemsListBase
Items []ScanSummary `json:"items"`
}

type ScanSummary struct {
Expand Down
6 changes: 6 additions & 0 deletions hubapi/common-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ func (m *Meta) FindLinkByRel(rel string) (*ResourceLink, error) {
return nil, fmt.Errorf("no relation '%s' found", rel)
}

type ItemsListBase struct {
TotalCount int `json:"totalCount"`
AppliedFilters []interface{} `json:"appliedFilters,omitempty"`
Meta Meta `json:"_meta"`
}

// GetListOptions describes the parameter model for the list GET endpoints.
type GetListOptions struct {
Limit *int
Expand Down
68 changes: 63 additions & 5 deletions hubapi/component-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,84 @@

package hubapi

import "time"

type ComponentList struct {
TotalCount uint32 `json:"totalCount"`
Items []Component `json:"items"`
Meta Meta `json:"_meta"`
ItemsListBase
Items []ComponentVariant `json:"items"`
}

type ComponentVariant struct {
ComponentName string `json:"componentName"`
VersionName string `json:"versionName,omitempty"`
OriginID string `json:"originId,omitempty"`
Component string `json:"component"`
Version string `json:"version,omitempty"`
Variant string `json:"variant,omitempty"`
}

type ComponentVersionList struct {
ItemsListBase
Items []ComponentVersion `json:"items"`
}

type ComponentVersion struct {
VersionName string `json:"versionName,omitempty"`
ReleasedOn time.Time `json:"releasedOn,omitempty"`
License ComplexLicense `json:"license"`
Source string `json:"source"`
Type string `json:"type"`
AdditionalHomepages []string `json:"additionalHomepages"`
ApprovalStatus string `json:"approvalStatus"`
Notes string `json:"notes,omitempty"`
Meta Meta `json:"_meta"`
}

type ComponentVersionOriginList struct {
ItemsListBase
Items []ComponentVersionOrigin `json:"items"`
}

type ComponentVersionOrigin struct {
ComponentVersion
Origin string `json:"originName"`
OriginID string `json:"originId"`
}

type ComponentVersionVulnerabilityList struct {
ItemsListBase
Items []ComponentVersionVulnerability `json:"items"`
}

type ComponentVersionVulnerability struct {
VulnerabilityBase
AccessVector string `json:"accessVector"`
AccessComplexity string `json:"accessComplexity"`
Authentication string `json:"authentication"`
ConfidentialityImpact string `json:"confidentialityImpact"`
IntegrityImpact string `json:"integrityImpact"`
AvailabilityImpact string `json:"availabilityImpact"`
Meta Meta `json:"_meta"`
}

type Component struct {
Name string `json:"name"`
Description string `json:"description"`
Description string `json:"description,omitempty"`
ApprovalStatus string `json:"approvalStatus"`
Homepage string `json:"url,omitempty"`
AdditionalHomepages []string `json:"additionalHomepages"`
PrimaryLanguage string `json:"primaryLanguage,omitempty"`
Source string `json:"source"`
Type string `json:"type"`
Notes string `json:"notes,omitempty"`
Meta Meta `json:"_meta"`
}

type ComponentRequest struct {
Name string `json:"name"`
Description string `json:"description"`
ApprovalStatus string `json:"approvalStatus"`
Homepage string `json:"url,omitempty"`
AdditionalHomepages []string `json:"additionalHomepages"`
ApprovalStatus string `json:"approvalStatus"`
Type string `json:"type"`
}
78 changes: 78 additions & 0 deletions hubapi/component-api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package hubapi_test

import (
"encoding/json"
"io/ioutil"
"testing"

"github.com/blackducksoftware/hub-client-go/hubapi"
"github.com/stretchr/testify/assert"
)

func TestReadList(t *testing.T) {

content, err := ioutil.ReadFile("testdata/componentList.json")
assert.NoError(t, err)
assert.NotEmpty(t, content)

var items hubapi.ComponentList

err = json.Unmarshal([]byte(content), &items)
assert.NoError(t, err)
assert.True(t, items.TotalCount > 0)
assert.Len(t, items.Items, 1)

component := items.Items[0]

assert.NotEmpty(t, component.ComponentName)
assert.NotEmpty(t, component.Component)
assert.NotEmpty(t, component.Version)
}

func TestReadComponentVersionList(t *testing.T) {

content, err := ioutil.ReadFile("testdata/componentVersionList.json")
assert.NoError(t, err)
assert.NotEmpty(t, content)

var items hubapi.ComponentVersionList

err = json.Unmarshal([]byte(content), &items)
assert.NoError(t, err)
assert.True(t, items.TotalCount > 0)
assert.Len(t, items.Items, 10)

component := items.Items[0]

assert.NotEmpty(t, component.VersionName)
assert.NotEmpty(t, component.Source)
assert.NotEmpty(t, component.Type)
}

func TestReadComponentVersionOriginList(t *testing.T) {
content, err := ioutil.ReadFile("testdata/componentVersionOriginList.json")
assert.NoError(t, err)
assert.NotEmpty(t, content)

var items hubapi.ComponentVersionOriginList

err = json.Unmarshal([]byte(content), &items)
assert.NoError(t, err)
assert.Len(t, items.Items, 10)
assert.True(t, items.TotalCount > 0)

item := items.Items[1]

assert.NotEmpty(t, item.VersionName)
assert.NotEmpty(t, item.Origin)
assert.NotEmpty(t, item.OriginID)

assert.True(t, len(item.Meta.Links) > 5)
resLink, err := item.Meta.FindLinkByRel("version")
assert.NoError(t, err)
assert.NotNil(t, resLink)

resLink, err = item.Meta.FindLinkByRel("vulnerabilities")
assert.NoError(t, err)
assert.NotNil(t, resLink)
}
5 changes: 2 additions & 3 deletions hubapi/current-user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type CreateApiTokenResponse struct {
}

type ApiTokenList struct {
TotalCount uint32 `json:"totalCount"`
Items []ApiTokenWithMeta `json:"items"`
Meta Meta `json:"_meta"`
ItemsListBase
Items []ApiTokenWithMeta `json:"items"`
}
5 changes: 2 additions & 3 deletions hubapi/policyrules-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
)

type PolicyRuleList struct {
TotalCount uint32 `json:"totalCount"`
Items []PolicyRule `json:"items"`
Meta Meta `json:"_meta"`
ItemsListBase
Items []PolicyRule `json:"items"`
}

type PolicyRule struct {
Expand Down
8 changes: 4 additions & 4 deletions hubapi/projects-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const (
)

type ProjectList struct {
TotalCount uint32 `json:"totalCount"`
Items []Project `json:"items"`
ItemsListBase
Items []Project `json:"items"`
}

type Project struct {
Expand All @@ -54,8 +54,8 @@ type ProjectRequest struct {
}

type ProjectVersionList struct {
TotalCount uint32 `json:"totalCount"`
Items []ProjectVersion `json:"items"`
ItemsListBase
Items []ProjectVersion `json:"items"`
}

type ProjectVersion struct {
Expand Down
22 changes: 22 additions & 0 deletions hubapi/testdata/componentList.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"totalCount": 1,
"items": [
{
"componentName": "Apache Commons Collections",
"versionName": "4.0",
"originId": "org.apache.commons:commons-collections4:4.0",
"component": "https://SERVER/api/components/87ac8642-f639-46fe-ab2b-66e89cca0130",
"version": "https://SERVER/api/components/87ac8642-f639-46fe-ab2b-66e89cca0130/versions/7b17b1ca-9ff3-4709-9336-6999d6f38923",
"variant": "https://SERVER/api/components/87ac8642-f639-46fe-ab2b-66e89cca0130/versions/7b17b1ca-9ff3-4709-9336-6999d6f38923/origins/967c343d-31d1-4aeb-905b-75192bb8a114"
}
],
"appliedFilters": [],
"_meta": {
"allow": [
"POST",
"GET"
],
"href": "https://SERVER/api/components?q=maven:org.apache.commons:commons-collections4:4.0&offset=0&limit=10",
"links": []
}
}
Loading

0 comments on commit 1b3e6f8

Please sign in to comment.