From 0f8a294efcdaa0f4802910cd988e72f32c71d05b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 14 Sep 2015 21:54:57 -0400 Subject: improved privdata --- ...ent_4_38e533c398521a2f1e02fde939f753e1._comment | 35 ++++++++++++++++++++++ ...ent_7_d6c4c2645696eac448e906d812c2de62._comment | 25 ++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 doc/forum/Could_not_load_host_key:___47__etc__47__ssh__47__ssh__95__host__95__ed25519__95__key/comment_4_38e533c398521a2f1e02fde939f753e1._comment create mode 100644 doc/todo/bytes_in_privData__63__/comment_7_d6c4c2645696eac448e906d812c2de62._comment diff --git a/doc/forum/Could_not_load_host_key:___47__etc__47__ssh__47__ssh__95__host__95__ed25519__95__key/comment_4_38e533c398521a2f1e02fde939f753e1._comment b/doc/forum/Could_not_load_host_key:___47__etc__47__ssh__47__ssh__95__host__95__ed25519__95__key/comment_4_38e533c398521a2f1e02fde939f753e1._comment new file mode 100644 index 00000000..e51c5147 --- /dev/null +++ b/doc/forum/Could_not_load_host_key:___47__etc__47__ssh__47__ssh__95__host__95__ed25519__95__key/comment_4_38e533c398521a2f1e02fde939f753e1._comment @@ -0,0 +1,35 @@ +[[!comment format=mdwn + username="joey" + subject="""comment 4""" + date="2015-09-15T00:29:47Z" + content=""" +I've fixed this bug. I thought about adding a type based +validation when privdata is being set, but in the end decided against it +for a couple reasons: + +* Doesn't fix existing privdata files. +* The privdata file could be edited by the user, etc and the validation + wouldn't be run. +* A user could just as well paste in a file and omit pasting the trailing + newline, so the validation would need to check if there was a trailing + newline when it's significant. +* If the validation is by what the type of privdata is used for, this + disconnects the validation from the property that consumes the privdata. + Seems better to centralize all handling of a particular peice of privdata + in once place. +* I was having some difficulty implementing it.. + +Instead, I settled on making PrivData a newtype, +and adding some accessor functions for it: + + privDataLines :: PrivData -> [String] + privDataVal :: PrivDara -> String -- returned string never contains newlines + +This helps document the issue, and like `lines "a"` is the same as `lines +"a\n"`, using privDataLines will give the same result whether the trailing +newline was chomped or not. So, propellor no longer removes trailing newlines +when the user is inputting privdata. + +The ssh property is adjusted to use privDataLines and add a trailing +newline when writing files, and problem solved. +"""]] diff --git a/doc/todo/bytes_in_privData__63__/comment_7_d6c4c2645696eac448e906d812c2de62._comment b/doc/todo/bytes_in_privData__63__/comment_7_d6c4c2645696eac448e906d812c2de62._comment new file mode 100644 index 00000000..07bc8145 --- /dev/null +++ b/doc/todo/bytes_in_privData__63__/comment_7_d6c4c2645696eac448e906d812c2de62._comment @@ -0,0 +1,25 @@ +[[!comment format=mdwn + username="joey" + subject="""mostly done""" + date="2015-09-15T00:26:10Z" + content=""" +A recent change converted PrivData to a newtype. +There are no longer any things that directly use PrivData; all use +should be via accessor functions like privDataLines and privDataVal. +Which helps with this. + +So, I've instead implemented a `privDataByteString :: PrivData -> ByteString`, +and I've adjusted the privdata serialization so it shouldn't crash +on arbitrarily encoded data when eg, a binary file is fed into `propellor --set`. + +(Note that I was wrong earlier when I said it'd be safe to change the +serialization to use ByteString; it must use String. While `"foo"` +can be Read as a ByteString same as a string, `"foo\1000"`, +when Read as a ByteString, truncates the big unicode character to +a single byte. So, PrivData is still stored as Strings internally.) + +The final step would be to make `hasPrivContent` use `privDataByteString` +instead of `privDataLines`. Which needs some more work to add Properties to +ensure a file contains a ByteString. This should be pretty easy to do, +but I lost steam.. +"""]] -- cgit v1.2.3