Skip to content

Commit

Permalink
Support multiple hubs (#235)
Browse files Browse the repository at this point in the history
Added support for multiple hub values
  • Loading branch information
msenmurugan authored and Rob Rati committed Mar 11, 2019
1 parent 5018172 commit 910d18d
Show file tree
Hide file tree
Showing 20 changed files with 456 additions and 289 deletions.
48 changes: 37 additions & 11 deletions api/swagger-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,14 @@
"Repository",
"Tag",
"Sha",
"HubProjectName",
"HubProjectVersionName",
"HubScanName",
"Scheme",
"Domain",
"Port",
"User",
"Password",
"BlackDuckProjectName",
"BlackDuckProjectVersionName",
"BlackDuckScanName",
"Priority"
],
"properties": {
Expand All @@ -411,16 +416,37 @@
"description": "The SHA of the image",
"type": "string"
},
"HubProjectName": {
"description": "The Hub project name",
"Scheme": {
"description": "The Scheme of the Black Duck instance. Currently only https is supported",
"type": "string"
},
"HubProjectVersionName": {
"description": "The Hub project version name",
"Domain": {
"description": "The Domain name of the Black Duck instance",
"type": "string"
},
"HubScanName": {
"description": "The Hub scan name",
"Port": {
"description": "The Port of the Black Duck instance",
"type": "integer",
"format": "int"
},
"User": {
"description": "The name of the user that can access the Black Duck instance",
"type": "string"
},
"Password": {
"description": "The password for the user that can access the Blackduck instance",
"type": "string"
},
"BlackDuckProjectName": {
"description": "The name of the project to use in the Black Duck instance",
"type": "string"
},
"BlackDuckProjectVersionName": {
"description": "The name of the project version to use in the Black Duck instance",
"type": "string"
},
"BlackDuckScanName": {
"description": "The name of the scan to use in the Black Duck instance",
"type": "string"
},
"Priority": {
Expand Down Expand Up @@ -580,8 +606,8 @@
"description": "The number of scans that may be run at the same time",
"type": "integer"
},
"HubClientTimeoutMilliseconds": {
"description": "The timeout for HTTP requests issued to the Hub",
"ClientTimeoutMilliseconds": {
"description": "The timeout for HTTP requests issued to the Black Duck instance",
"type": "integer"
},
"LogLevel": {
Expand Down
24 changes: 14 additions & 10 deletions cmd/mockperceptor/mockperceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func main() {
type MockPerceptorResponder struct{}

// GetModel .....
func (mr *MockPerceptorResponder) GetModel() api.Model {
return api.Model{}
func (mr *MockPerceptorResponder) GetModel() (*api.Model, error) {
return &api.Model{}, nil
}

// AddPod .....
Expand Down Expand Up @@ -119,14 +119,18 @@ func (mr *MockPerceptorResponder) GetNextImage() api.NextImage {
log.Info("GetNextImage")
start := time.Now().String()
imageSpec := api.ImageSpec{
Repository: "docker.io/alpine",
Tag: "latest",
Sha: "621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528",
HubURL: "",
HubProjectName: "string",
HubProjectVersionName: "string",
HubScanName: start,
Priority: 1,
Repository: "docker.io/alpine",
Tag: "latest",
Sha: "621c2f39f8133acb8e64023a94dbdf0d5ca81896102b9e57c0dc184cadaf5528",
Scheme: "https",
Domain: "",
Port: 8443,
User: "mock-username",
Password: "mock-password",
BlackDuckProjectName: "string",
BlackDuckProjectVersionName: "string",
BlackDuckScanName: start,
Priority: 1,
}
return api.NextImage{ImageSpec: &imageSpec}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/finishedscanclientjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ under the License.

package api

// FinishedScanClientJob .....
// FinishedScanClientJob stores the scan client job finished status
type FinishedScanClientJob struct {
ImageSpec ImageSpec
ImageSpec *ImageSpec
Err string
}
22 changes: 13 additions & 9 deletions pkg/api/imagespec.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ under the License.

package api

// ImageSpec .....
// ImageSpec stores the Image specification
type ImageSpec struct {
Repository string
Tag string
Sha string
HubURL string
HubProjectName string
HubProjectVersionName string
HubScanName string
Priority int
Repository string
Tag string
Sha string
Scheme string
Domain string
Port int
User string
Password string
BlackDuckProjectName string
BlackDuckProjectVersionName string
BlackDuckScanName string
Priority int
}
16 changes: 8 additions & 8 deletions pkg/api/mockresponder.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type ImageInfo struct {
}

// GetModel .....
func (mr *MockResponder) GetModel() Model {
func (mr *MockResponder) GetModel() (*Model, error) {
// images := map[string]*ModelImageInfo{}
// for key, image := range mr.Images {
// scanResults := map[string]interface{}{
Expand All @@ -81,7 +81,7 @@ func (mr *MockResponder) GetModel() Model {
// Images: images,
// Pods: mr.Pods,
// }
return Model{}
return &Model{}, nil
}

// perceiver
Expand Down Expand Up @@ -199,12 +199,12 @@ func (mr *MockResponder) UpdateAllImages(allImages AllImages) error {
func (mr *MockResponder) GetNextImage() NextImage {
mr.NextImageCounter++
imageSpec := ImageSpec{
HubProjectName: fmt.Sprintf("mock-perceptor-%d", mr.NextImageCounter),
HubProjectVersionName: fmt.Sprintf("mock-perceptor-project-version-%d", mr.NextImageCounter),
HubScanName: fmt.Sprintf("mock-perceptor-scan-name-%d", mr.NextImageCounter),
Repository: "abc/def/ghi",
Tag: "latest",
Sha: "123abc456def"}
BlackDuckProjectName: fmt.Sprintf("mock-perceptor-%d", mr.NextImageCounter),
BlackDuckProjectVersionName: fmt.Sprintf("mock-perceptor-project-version-%d", mr.NextImageCounter),
BlackDuckScanName: fmt.Sprintf("mock-perceptor-scan-name-%d", mr.NextImageCounter),
Repository: "abc/def/ghi",
Tag: "latest",
Sha: "123abc456def"}
return NextImage{ImageSpec: &imageSpec}
}

Expand Down
46 changes: 25 additions & 21 deletions pkg/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ import (
"time"
)

// Model ...
// Model stores the perceptor model
type Model struct {
Hubs map[string]*ModelHub
CoreModel *CoreModel
Config *ModelConfig
Scheduler *ModelScanScheduler
BlackDucks map[string]*ModelBlackDuck
CoreModel *CoreModel
Config *ModelConfig
Scheduler *ModelScanScheduler
}

// ModelScanScheduler ...
type ModelScanScheduler struct {
ConcurrentScanLimit int
TotalScanLimit int
}

// CoreModel .....
Expand All @@ -56,22 +54,28 @@ type ModelImageTransition struct {
Time string
}

// ModelHubConfig ...
type ModelHubConfig struct {
User string
PasswordEnvVar string
ClientTimeout ModelTime
// ModelHost ...
type ModelHost struct {
Scheme string
Domain string // it can be domain name or ip address
Port int
User string
ConcurrentScanLimit int
TotalScanLimit int
}

// ModelBlackDuckConfig ...
type ModelBlackDuckConfig struct {
Hosts []*ModelHost
ClientTimeout ModelTime
TLSVerification bool
}

// ModelConfig .....
type ModelConfig struct {
Timings *ModelTimings
Hub *ModelHubConfig
Port int
LogLevel string
Timings *ModelTimings
BlackDuck *ModelBlackDuckConfig
Port int
LogLevel string
}

// ModelTime ...
Expand Down Expand Up @@ -125,13 +129,13 @@ type ModelCircuitBreaker struct {
ConsecutiveFailures int
}

// ModelHub describes a hub client model
type ModelHub struct {
// can we log in to the hub?
// ModelBlackDuck describes a Black Duck client model
type ModelBlackDuck struct {
// can we log in to the Black Duck?
// IsLoggedIn bool
// have all the projects been sucked in?
HasLoadedAllCodeLocations bool
// map of project name to ... ? hub URL?
// map of project name to ... ? Black Duck URL?
// Projects map[string]string
// map of code location name to mapped project version url
CodeLocations map[string]*ModelCodeLocation
Expand Down
4 changes: 2 additions & 2 deletions pkg/api/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import (
"net/http"
)

// Responder .....
// Responder interface stores all the methods corresponding to Perceptor api
type Responder interface {
GetModel() Model
GetModel() (*Model, error)

// perceiver
AddPod(pod Pod) error
Expand Down
9 changes: 7 additions & 2 deletions pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ import (
log "github.com/sirupsen/logrus"
)

// SetupHTTPServer .....
// SetupHTTPServer will setup all api's to be served
func SetupHTTPServer(responder Responder) {
// state of the program
http.HandleFunc("/model", func(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
jsonBytes, err := json.MarshalIndent(responder.GetModel(), "", " ")
model, err := responder.GetModel()
if err != nil {
responder.Error(w, r, err, 500)
return
}
jsonBytes, err := json.MarshalIndent(model, "", " ")
if err != nil {
responder.Error(w, r, err, 500)
return
Expand Down
Loading

0 comments on commit 910d18d

Please sign in to comment.