-
-
Notifications
You must be signed in to change notification settings - Fork 19
feat: Add Key::shortened_to_valid_length helper function
#1260
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
0d683e3
b7f0f0b
fb2914b
eca4b00
9c5b35d
f0a76b3
b2d9da3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,11 @@ impl ResourceNames { | |
| /// `max_length < 1 /* character */ + 1 /* dash */ + hash_length`. | ||
| /// | ||
| /// Kubernetes object names cannot contain non-ASCII characters. | ||
| fn ensure_max_length(resource_name: String, max_length: usize, hash_length: usize) -> String { | ||
| pub fn ensure_max_length( | ||
| resource_name: String, | ||
| max_length: usize, | ||
| hash_length: usize, | ||
| ) -> String { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function was written for resource names, where the assertions always hold. If it's now used to shorten arbitrary strings (which could also come from the user) then you can That said, I do see the usefulness. I'd suggest making it safe for arbitrary strings (which isn't trivial) and moving it to a string utility module.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved it into
However, I'm pretty sure I missed something, will test non-asci strings now
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed a commit that adds UTF-8 support: f0a76b3 |
||
| assert!(resource_name.is_ascii()); | ||
| assert!(max_length >= 1 /* character */ + 1 /* dash */ + hash_length); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
This constant belongs in
kvp::keyand should be namedMAX_KEY_NAME_LENGTH.Rather than exposing the value publicly, it might be cleaner to offer a
sanitizefunction that takes a key prefix and name and returns a validkvp::key::Key.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 removed the constant and added the requested function. However, I didn't call it
sanitize, as to me that gives off security vibes, but happy to discuss the name :)