-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cscli refact: package clialert, clidecision (#3203)
* cscli refact: package clialert, clidecision * refact: function SanitizeScope() * lint
- Loading branch information
Showing
11 changed files
with
98 additions
and
89 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 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,26 @@ | ||
package clialert | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"github.com/crowdsecurity/crowdsec/pkg/types" | ||
) | ||
|
||
// SanitizeScope validates ip and range and sets the scope accordingly to our case convention. | ||
func SanitizeScope(scope, ip, ipRange string) (string, error) { | ||
if ipRange != "" { | ||
_, _, err := net.ParseCIDR(ipRange) | ||
if err != nil { | ||
return "", fmt.Errorf("%s is not a valid range", ipRange) | ||
} | ||
} | ||
|
||
if ip != "" { | ||
if net.ParseIP(ip) == nil { | ||
return "", fmt.Errorf("%s is not a valid ip", ip) | ||
} | ||
} | ||
|
||
return types.NormalizeScope(scope), nil | ||
} |
2 changes: 1 addition & 1 deletion
2
cmd/crowdsec-cli/alerts_table.go → cmd/crowdsec-cli/clialert/table.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package clialert | ||
|
||
import ( | ||
"fmt" | ||
|
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
2 changes: 1 addition & 1 deletion
2
cmd/crowdsec-cli/decisions_table.go → ...owdsec-cli/clidecision/decisions_table.go
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package main | ||
package clidecision | ||
|
||
import ( | ||
"fmt" | ||
|
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
Oops, something went wrong.