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

Conversation

runejuhl
Copy link

Fixes #2

(I'm not opposed to adding tests, but I'd like a pointer to how to get there fast. I can see that stdlib uses the modulesync stuff, should this do the same?)

Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

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

Would it make sense to add these CIDR types to stdlib instead?

For tests you can have a look at theforeman/puppet-dhcp@7d31525 but maybe rspec-puppet needs infrastructure to verify data types as well.

@@ -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.

@@ -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.

@@ -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.

@runejuhl
Copy link
Author

runejuhl commented Jun 6, 2018

I can see that stdlib has added IP validation types (puppetlabs/puppetlabs-stdlib@6dad21e), so I'll close this one.

@runejuhl runejuhl closed this Jun 6, 2018
@igalic
Copy link
Contributor

igalic commented Jun 7, 2018

\o/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants