Skip to content

Commit

Permalink
swagger container, handler fixes, makefile adds
Browse files Browse the repository at this point in the history
  • Loading branch information
ldelossa committed Nov 29, 2019
1 parent 7979e14 commit 1563107
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local-dev-up:
go mod vendor
$(docker-compose) up -d indexer
$(docker-compose) up -d matcher
$(docker-compose) up -d swagger-ui

# tear down the entire local development environment
.PHONY: local-dev-down
Expand All @@ -44,3 +45,8 @@ local-dev-indexer-restart:
.PHONY: local-dev-matcher-restart
local-dev-matcher-restart:
$(docker-compose) up -d --force-recreate matcher

# restart the local development swagger-ui, any local code changes will take effect
.PHONY: local-dev-swagger-ui-restart
local-dev-swagger-ui-restart:
$(docker-compose) up -d --force-recreate swagger-ui
9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ services:
- "./:/src/clair/"
command:
[ "bash", "-c", "cd /src/clair/cmd/clair; go run -mod vendor . -conf /src/clair/local-dev/matcher/matcher.config.yaml" ]

swagger-ui:
image: swaggerapi/swagger-ui
ports:
- "8082:8080"
volumes:
- "./:/clair"
environment:
SWAGGER_JSON: "/clair/openapi.yaml"
11 changes: 6 additions & 5 deletions indexer/indexreporthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,29 @@ func IndexReportHandler(service Service) http.HandlerFunc {
return
}

parts := strings.Split(r.URL.Path, "/")
if len(parts) != 5 {
manifestHash := strings.TrimPrefix(r.URL.Path, IndexReportAPIPath)
if manifestHash == "" {
resp := &je.Response{
Code: "bad-request",
Message: "malformed path. provide a single manifest hash",
}
je.Error(w, resp, http.StatusBadRequest)
return
}
manifestHash := parts[4]

report, err := service.IndexReport(context.Background(), manifestHash)
if err != nil {
if errors.Is(err, &clairerror.ErrIndexReportNotFound{}) {
var e *clairerror.ErrIndexReportNotFound
if errors.As(err, &e) {
resp := &je.Response{
Code: "not-found",
Message: fmt.Sprintf("index report for manifest %s not found", manifestHash),
}
je.Error(w, resp, http.StatusNotFound)
return
}
if errors.Is(err, &clairerror.ErrIndexReportRetrieval{}) {
var ee *clairerror.ErrIndexReportRetrieval
if errors.As(err, &ee) {
resp := &je.Response{
Code: "retrieval-failure",
Message: fmt.Sprintf("failed to retrieve manifest: %w", err),
Expand Down
5 changes: 2 additions & 3 deletions matcher/matchhander.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ func MatchHandler(service Service) http.HandlerFunc {
return
}

parts := strings.Split(r.URL.Path, "/")
if len(parts) != 5 {
manifestHash := strings.TrimPrefix(r.URL.Path, VulnerabilityReportAPIPath)
if manifestHash == "" {
resp := &je.Response{
Code: "bad-request",
Message: "malformed path. provide a single manifest hash",
}
je.Error(w, resp, http.StatusBadRequest)
return
}
manifestHash := parts[4]

report, err := service.Match(context.Background(), manifestHash)
if err != nil {
Expand Down

0 comments on commit 1563107

Please sign in to comment.