Skip to content

Commit

Permalink
Adopt reconciler logic for orchestrator (openclarity#320)
Browse files Browse the repository at this point in the history
* refactor: adopt reconcile logic

* refactor: Provider interface

* rename Client interface to Provider
* split Provider interface into Discoverer and Scanner
* add FatalError and RetryableError error types to allow the caller
  to distingiush between recoverable/retryable and
  unrecoverable/permanent errors returned by the provider.

* refactor: rm timeouts for ScanResult

* fix: linter errors

* feat(aws): wrap permanent errors

* fix: linter errors

* feat: add helper for unpacking multi-errors

* fix(cli): handling ScanResult in DONE state

* fix: go.mod

* fix(aws): deleting snaphots twice in same region

* fix(cli): interval for polling ScanResult

* refactor(cli): update logging/error messages

* fix: missing /dev mount in scanner container

* fix: rm AWS permission used for debugging authn

* fix(aws): rm unused function

* fix(utils): comments for utils.error package

* feat: add comments to schedule module

* fix(aws): handling Location for Instance

* fix: string representation of reconcile event

* fix: comment not ending with period error.

* refactor: mk Before After aligned with time.Time
  • Loading branch information
chrisgacsal authored Jun 6, 2023
1 parent ea03939 commit 8c87e62
Show file tree
Hide file tree
Showing 79 changed files with 5,961 additions and 3,851 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ ui: ## Build UI
.PHONY: backend
backend: ## Build Backend
@(echo "Building Backend ..." )
@(cd backend && go build -o bin/vmclarity-backend cmd/backend/main.go && ls -l bin/)
@(cd backend && go build -race -o bin/vmclarity-backend cmd/backend/main.go && ls -l bin/)

.PHONY: cli
cli: ## Build CLI
@(echo "Building CLI ..." )
@(cd cli && go build -ldflags="-X 'github.com/openclarity/vmclarity/cli/pkg.GitRevision=${VERSION}'" -o bin/vmclarity-cli main.go && ls -l bin/)
@(cd cli && go build -race -ldflags="-X 'github.com/openclarity/vmclarity/cli/pkg.GitRevision=${VERSION}'" -o bin/vmclarity-cli main.go && ls -l bin/)

.PHONY: docker
docker: docker-backend docker-cli ## Build All Docker images
Expand Down
48 changes: 48 additions & 0 deletions api/models/families.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// 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 models

type FamilyConfigEnabler interface {
IsEnabled() bool
}

func (c *VulnerabilitiesConfig) IsEnabled() bool {
return c != nil && c.Enabled != nil && *c.Enabled
}

func (c *SecretsConfig) IsEnabled() bool {
return c != nil && c.Enabled != nil && *c.Enabled
}

func (c *SBOMConfig) IsEnabled() bool {
return c != nil && c.Enabled != nil && *c.Enabled
}

func (c *RootkitsConfig) IsEnabled() bool {
return c != nil && c.Enabled != nil && *c.Enabled
}

func (c *MisconfigurationsConfig) IsEnabled() bool {
return c != nil && c.Enabled != nil && *c.Enabled
}

func (c *MalwareConfig) IsEnabled() bool {
return c != nil && c.Enabled != nil && *c.Enabled
}

func (c *ExploitsConfig) IsEnabled() bool {
return c != nil && c.Enabled != nil && *c.Enabled
}
33 changes: 20 additions & 13 deletions api/models/models.gen.go

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

49 changes: 49 additions & 0 deletions api/models/scan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// 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 models

func (s *Scan) GetState() (ScanState, bool) {
var state ScanState
var ok bool

if s.State != nil {
state, ok = *s.State, true
}

return state, ok
}

func (s *Scan) GetID() (string, bool) {
var id string
var ok bool

if s.Id != nil {
id, ok = *s.Id, true
}

return id, ok
}

func (s *Scan) GetScanConfigScope() (ScanScopeType, bool) {
var scope ScanScopeType
var ok bool

if s.ScanConfigSnapshot != nil {
scope, ok = s.ScanConfigSnapshot.GetScope()
}

return scope, ok
}
37 changes: 37 additions & 0 deletions api/models/scanconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// 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 models

func (s *ScanConfig) GetID() (string, bool) {
var id string
var ok bool

if s.Id != nil {
id, ok = *s.Id, true
}

return id, ok
}

const DefaultMaxParallelScanners int = 2

func (s *ScanConfig) GetMaxParallelScanners() int {
if s.MaxParallelScanners != nil {
return *s.MaxParallelScanners
}

return DefaultMaxParallelScanners
}
34 changes: 34 additions & 0 deletions api/models/scanconfigsnapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// 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 models

func (d *ScanConfigSnapshot) GetScope() (ScanScopeType, bool) {
var scope ScanScopeType
var ok bool

if d.Scope != nil {
scope, ok = *d.Scope, true
}
return scope, ok
}

func (s *ScanConfigSnapshot) GetMaxParallelScanners() int {
if s.MaxParallelScanners != nil {
return *s.MaxParallelScanners
}

return DefaultMaxParallelScanners
}
92 changes: 92 additions & 0 deletions api/models/scanresult.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// 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 models

func (r *TargetScanResult) GetGeneralState() (TargetScanStateState, bool) {
var state TargetScanStateState
var ok bool

if r.Status != nil {
state, ok = r.Status.GetGeneralState()
}

return state, ok
}

func (r *TargetScanResult) GetGeneralErrors() []string {
var errs []string

if r.Status != nil {
errs = r.Status.GetGeneralErrors()
}

return errs
}

func (r *TargetScanResult) GetID() (string, bool) {
var id string
var ok bool

if r.Id != nil {
id, ok = *r.Id, true
}

return id, ok
}

func (r *TargetScanResult) GetScanID() (string, bool) {
var scanID string
var ok bool

if r.Scan != nil {
scanID, ok = r.Scan.Id, true
}

return scanID, ok
}

func (r *TargetScanResult) GetTargetID() (string, bool) {
var targetID string
var ok bool

if r.Target != nil {
targetID, ok = r.Target.Id, true
}

return targetID, ok
}

func (r *TargetScanResult) IsDone() (bool, bool) {
var done bool
var ok bool
var state TargetScanStateState

if state, ok = r.GetGeneralState(); ok && state == TargetScanStateStateDONE {
done = true
}

return done, ok
}

func (r *TargetScanResult) HasErrors() bool {
var has bool

if errs := r.GetGeneralErrors(); len(errs) > 0 {
has = true
}

return has
}
35 changes: 35 additions & 0 deletions api/models/scanstate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// 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 models

func (s *TargetScanState) GetState() (TargetScanStateState, bool) {
var state TargetScanStateState
var ok bool

if s.State != nil {
state, ok = *s.State, true
}
return state, ok
}

func (s *TargetScanState) GetErrors() []string {
var errs []string

if s.Errors != nil {
errs = *s.Errors
}
return errs
}
Loading

0 comments on commit 8c87e62

Please sign in to comment.