Skip to content

Commit

Permalink
feat: basic rest api + refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasyl Portey committed Sep 7, 2020
1 parent 6416946 commit 34e88d2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
GOLINT := golangci-lint

.PHONY: dep
dep: # Download required dependencies
go mod tidy
go mod download

.PHONY: lint
lint: dep # Lint the files
$(GOLINT) run -c .golangci.yml

.PHONY: test
test: dep # Run unit tests
go test -race -count=1 -short ./...
4 changes: 4 additions & 0 deletions internal/storage/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ func (m *MemoryStorage) SaveVulnerabilities(_ context.Context, vulnerabilities [
return nil
}

func (m *MemoryStorage) GetResults(ctx context.Context, _ string) ([]model.ResultItem, error) {
return nil, nil
}

func NewMemoryStorage() *MemoryStorage {
return &MemoryStorage{
files: make(map[int]*model.FileMetadata),
Expand Down
5 changes: 5 additions & 0 deletions pkg/ice/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SourceProvider interface {

type Storage interface {
SaveFile(ctx context.Context, metadata *model.FileMetadata) error
GetResults(ctx context.Context, scanID string) ([]model.ResultItem, error)
}

type Service struct {
Expand Down Expand Up @@ -60,6 +61,10 @@ func (s *Service) StartScan(ctx context.Context, scanID string) error {
return errors.Wrap(err, "failed to read sources")
}

func (s *Service) GetResults(ctx context.Context, scanID string) ([]model.ResultItem, error) {
return s.Storage.GetResults(ctx, scanID)
}

func hash(s string) uint32 {
h := fnv.New32a()
if _, err := h.Write([]byte(s)); err != nil {
Expand Down
22 changes: 15 additions & 7 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,21 @@ type QueryMetadata struct {
}

type Vulnerability struct {
ID int
ScanID string `db:"scan_id"`
FileID int `db:"file_id"`
QueryName string `db:"query_name"`
Severity string
Line *int
Output string
ID int `json:"id"`
ScanID string `db:"scan_id" json:"-"`
FileID int `db:"file_id" json:"file_id"`
QueryName string `db:"query_name" json:"query_name"`
Severity string `json:"severity"`
Line *int `json:"line"`
Output string `json:"-"`
}

type ResultItem struct {
ID int `json:"id"`
FileName int `db:"file_id" json:"file_name"`
Line *int `json:"line"`
QueryName string `db:"query_name" json:"query_name"`
Severity string `json:"severity"`
}

type FileMetadatas []FileMetadata
Expand Down

0 comments on commit 34e88d2

Please sign in to comment.