-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate components are not granted access to undefined k/v stores #1486
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be somewhat confusing to users what it means to "define" a key value store. Perhaps we should more directly point to that fact that they are not creating a runtime config that configures a non-default store?
.unwrap_or_default() | ||
{ | ||
if !store_manager.is_defined(&allowed) { | ||
let err = format!("Component {} is granted access to key-value store '{allowed}', which is not defined", component.id()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that we need to frame key_value_stores
in terms of access control. Maybe something like:
let err = format!("Component {} is granted access to key-value store '{allowed}', which is not defined", component.id()); | |
let err = format!("Component {} uses the key-value store '{allowed}', which is not defined", component.id()); |
@rylev I tried adding more pointers and I like it but it really magnifies the effect of the doubling printing:
I'll see if I can find what's doing this; if it's not an easy and obviously-safe fix, then maybe we just accept it and record a separate issue - again, not something people should run into too often! |
Okay I am not sure how to fix the double printing.
If I remove the |
0e5ad85
to
3a6e720
Compare
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
3a6e720
to
a772ca4
Compare
Or we could create a new |
Now looks like:
|
store.delete("bar")?; | ||
|
||
ensure!(!store.exists("bar")?); | ||
|
||
ensure!(matches!(store.get("bar"), Err(Error::NoSuchKey))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally find it easier to read long tests like this if assertions are grouped with the side-effect-inducing call they are testing, e.g.:
store.delete("bar")?; | |
ensure!(!store.exists("bar")?); | |
ensure!(matches!(store.get("bar"), Err(Error::NoSuchKey))); | |
store.delete("bar")?; | |
ensure!(!store.exists("bar")?); | |
ensure!(matches!(store.get("bar"), Err(Error::NoSuchKey))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually none of this test body is needed because spin up
will barf during validation and never actually run it so I just deleted it all. Wake the heck up, Ivan
|
||
ensure!(store.exists("bar")?); | ||
|
||
ensure!(b"baz" as &[_] == &store.get("bar")?); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_eq!
gives more useful errors, e.g.
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `4`,
right: `3`', src/main.rs:5:1
I think it would also remove the need to cast as &[_]
in this case, but my confidence in understanding Rust's coercion rules is NOT HIGH.
Aaaand I was wrong, but you can simplify it thusly (with or without the change to assert_eq
:
assert_eq!(b"bas", &*store.get("bar")?);
Ok(()) | ||
} else { | ||
let prologue = vec![ | ||
"One or more components use key-value stores which are not defined.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to explicitly call out that only the "default" store is implicitly defined. However, this is explained in the docs that are linked so i think this works and if there is confusion we can always iterate on user feedback
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, users should never see an error about the default
store so hopefully they won't think they need to define it!.
… components Signed-off-by: itowlson <ivan.towlson@fermyon.com>
003cdef
to
c01e703
Compare
(I'm not mad keen on the "host component error" string or the duplicated text, but this is a "should rarely happen" error so I'm wary of changing things that might break existing error paths.)