-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1579 from snyk/fea/alert_into_diag
fea: transform alert from enum lib into diagnostic
- Loading branch information
Showing
15 changed files
with
163 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package diagnostic | ||
|
||
import ( | ||
"github.com/snyk/driftctl/enumeration/alerter" | ||
"github.com/snyk/driftctl/enumeration/remote/alerts" | ||
"github.com/snyk/driftctl/enumeration/resource" | ||
) | ||
|
||
type Diagnostic interface { | ||
Code() string | ||
Message() string | ||
ResourceType() string | ||
Resource() *resource.Resource | ||
} | ||
|
||
type diagnosticImpl struct { | ||
alert alerter.Alert | ||
} | ||
|
||
func (d *diagnosticImpl) Code() string { | ||
if _, ok := d.alert.(*alerts.RemoteAccessDeniedAlert); ok { | ||
return "ACCESS_DENIED" | ||
} | ||
return "UNKNOWN_ERROR" | ||
} | ||
|
||
func (d *diagnosticImpl) Message() string { | ||
return d.alert.Message() | ||
} | ||
|
||
func (d *diagnosticImpl) ResourceType() string { | ||
ty := "" | ||
if d.Resource() != nil { | ||
ty = d.Resource().ResourceType() | ||
} | ||
return ty | ||
} | ||
|
||
func (d *diagnosticImpl) Resource() *resource.Resource { | ||
return d.alert.Resource() | ||
} | ||
|
||
type Diagnostics []Diagnostic | ||
|
||
func FromAlerts(alertMap alerter.Alerts) Diagnostics { | ||
var results Diagnostics | ||
for _, v := range alertMap { | ||
for _, alert := range v { | ||
diag := &diagnosticImpl{alert} | ||
results = append(results, diag) | ||
} | ||
} | ||
return results | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.