Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Add types for IPv4, IPv6 and variants, including CIDR notation #37

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions types/ip.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://stackoverflow.com/a/190405/1000630, with minor modifications to syntax
type Tea::IP = Variant[Tea::IPv4, Tea::IPv6]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, adding them to stdlib would make sense. I talked a bit with @igalic about this at cfgmgmtcamp and I think we decided to start here, but having it in stdlib would be better. ...but in that case, why not move all types from tea into stdlib?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's entirely valid and this is partially already the case.

2 changes: 2 additions & 0 deletions types/ipcidr.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://stackoverflow.com/a/190405/1000630, with minor modifications to syntax
type Tea::IPCIDR = Variant[Tea::IPv4CIDR, Tea::IPv6CIDR]
2 changes: 2 additions & 0 deletions types/ipv4.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# https://stackoverflow.com/a/190405/1000630, with minor modifications to syntax
type Tea::IPv4 = Pattern[/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}/]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 changes: 2 additions & 0 deletions types/ipv4cidr.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#http://www.regexpal.com/93987
type Tea::IPv4CIDR = Pattern[/^([0-9]{1,3}\.){3}[0-9]{1,3}(\/([0-9]|[1-2][0-9]|3[0-2]))?/]
2 changes: 2 additions & 0 deletions types/ipv6.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Unsure where this came from, thank you Internet!
type Tea::IPv6 = Pattern[/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/] # lint:ignore:140chars
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 changes: 2 additions & 0 deletions types/ipv6cidr.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#source: http://www.regexpal.com/93988
type Tea::IPv6CIDR = Pattern[/s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa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