This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bcf0b2
commit e2b437c
Showing
7 changed files
with
158 additions
and
14 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
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 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,43 @@ | ||
package orbiter | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
type Orb struct { | ||
URL string | ||
Repokey string | ||
Masterkey string | ||
} | ||
|
||
var ( | ||
ipPartRegex = `([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])` | ||
ipRegex = fmt.Sprintf(`%s\.%s\.%s\.%s`, ipPartRegex, ipPartRegex, ipPartRegex, ipPartRegex) | ||
cidrRegex = fmt.Sprintf(`%s/([1-2][0-9]|3[0-2]|[0-9])`, ipRegex) | ||
|
||
compiledIP = regexp.MustCompile(fmt.Sprintf(`^(%s)$`, ipRegex)) | ||
compiledCIDR = regexp.MustCompile(fmt.Sprintf(`^(%s)$`, cidrRegex)) | ||
) | ||
|
||
type cidr string | ||
|
||
type IPAddress string | ||
|
||
type CIDR string | ||
|
||
func (c CIDR) Validate() error { | ||
if !compiledCIDR.MatchString(string(c)) { | ||
return errors.Errorf("Value %s is not in valid CIDR notation. It does not match the regular expression %s", c, compiledCIDR.String()) | ||
} | ||
return nil | ||
} | ||
|
||
func (i IPAddress) Validate() error { | ||
if !compiledIP.MatchString(string(i)) { | ||
return errors.Errorf("Value %s is not a valid IP address. It does not match the regular expression %s", i, compiledIP.String()) | ||
} | ||
return nil | ||
} |