Skip to content
Open
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 src/Puppet/Interpreter/Resolve.hs
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ resolveDataType ud
UDTScalar -> pure DTScalar
UDTData -> pure DTData
UDTOptional dt -> DTOptional <$> resolveDataType dt
UDTSensitive dt -> DTSensitive <$> resolveDataType dt
UNotUndef -> pure NotUndef
UDTVariant vrs -> DTVariant <$> traverse resolveDataType vrs
UDTPattern a -> pure (DTPattern a)
Expand Down Expand Up @@ -785,6 +786,7 @@ datatypeMatch dt v =
DTScalar -> datatypeMatch (DTVariant (DTInteger Nothing Nothing :| [DTString Nothing Nothing, DTBoolean])) v
DTData -> datatypeMatch (DTVariant (DTScalar :| [DTArray DTData 0 Nothing, DTHash DTScalar DTData 0 Nothing])) v
DTOptional sdt -> datatypeMatch (DTVariant (DTUndef :| [sdt])) v
DTSensitive sdt -> datatypeMatch (DTVariant (DTUndef :| [sdt])) v
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@bartavelle Is this alright ?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I do not think this is alright. If you want it to work "right", you should create a new datatype for the interpreter, and it should only match that.

It seems impossible to validate it properly without adding special logic. Indeed, it says:

The Sensitive type is parameterized, but the parameterized type (the type of the value it contains) only retains the basic type, but sensitive information about the length or details about the contained data value can be leaked.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

You can write a ruby to haskell binding so that it can call unwrap.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Where do I write such binding ?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

probably in the Puppet.Runner.Erb module. Look at how the varlookup function is exported to the ruby runtime

DTVariant sdts -> any (`datatypeMatch` v) sdts
DTEnum lst -> maybe False (`elem` lst) (v ^? _PString)
DTAny -> True
Expand Down
2 changes: 2 additions & 0 deletions src/Puppet/Language/Value.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ data DataType
| DTScalar
| DTData
| DTOptional DataType
| DTSensitive DataType
| NotUndef
| DTVariant (NonEmpty DataType)
| DTPattern (NonEmpty CompRegex)
Expand All @@ -45,6 +46,7 @@ instance Pretty DataType where
DTScalar -> "Scalar"
DTData -> "Data"
DTOptional o -> "Optional" <> brackets (pretty o)
DTSensitive o -> "Sensitive" <> brackets (pretty o)
NotUndef -> "NotUndef"
DTVariant vs -> "Variant" <> list (foldMap (pure . pretty) vs)
DTPattern vs -> "Pattern" <> list (foldMap (pure . pretty) vs)
Expand Down
1 change: 1 addition & 0 deletions src/Puppet/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ datatype = dtString
<|> dtHash
<|> (UDTUndef <$ reserved "Undef")
<|> (reserved "Optional" *> (UDTOptional <$> brackets datatype))
<|> (reserved "Sensitive" *> (UDTSensitive <$> brackets datatype))
<|> (UNotUndef <$ reserved "NotUndef")
<|> (reserved "Variant" *> (UDTVariant . NE.fromList <$> brackets (datatype `sepBy1` symbolic ',')))
-- while all the other cases are straightforward, it seems that the
Expand Down
1 change: 1 addition & 0 deletions src/Puppet/Parser/PrettyPrinter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ instance Pretty UDataType where
UDTScalar -> "Scalar"
UDTData -> "Data"
UDTOptional o -> "Optional" <> brackets (pretty o)
UDTSensitive o -> "Sensitive" <> brackets (pretty o)
UNotUndef -> "NotUndef"
UDTVariant vs -> "Variant" <> list (foldMap (pure . pretty) vs)
UDTPattern vs -> "Pattern" <> list (foldMap (pure . pretty) vs)
Expand Down
1 change: 1 addition & 0 deletions src/Puppet/Parser/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ data UDataType
| UDTScalar
| UDTData
| UDTOptional UDataType
| UDTSensitive UDataType
| UNotUndef
| UDTVariant (NonEmpty UDataType)
| UDTPattern (NonEmpty CompRegex)
Expand Down
2 changes: 2 additions & 0 deletions tests/DT/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ spec = do
it "accepts variables" $ pendingWith "to be fixed" *> parse datatype "?" "String[$var]" `shouldParse` UDTString (Just 5) Nothing
describe "Stdlib::" $ do
"Stdlib::HTTPUrl" `parsed` UDTData
describe "Sensitive" $ do
"Sensitive[String]" `parsed` UDTSensitive (UDTString Nothing Nothing)