Skip to content
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

[fix] Adding "/" and "-" chars for the new condition format #193

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 6 additions & 6 deletions limitador/src/limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ mod conditions {

fn valid_id_char(&mut self) -> bool {
let char = self.input[self.pos];
char.is_alphanumeric() || char == '.' || char == '_'
char.is_alphanumeric() || char == '.' || char == '_' || char == '-' || char == '/'
Copy link
Member

@alexsnaps alexsnaps Jul 26, 2023

Choose a reason for hiding this comment

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

So the trouble I have with this change is that it muddies the waters... What if it's to be an expression now? Like http.response_code - 12 ? The white spaces matter now?
That being said I don't think we'd ever support that (very example if only 🤣 ). That being said I already hated having the . in there... tho I thought you could have argued it remained an identifier for "something" to resolve...

So anyways, I won't necessarily block this from happening, but I wonder if sanitizing the variable names/identifiers wouldn't be slightly more desirable.

Copy link
Contributor

@guicassolato guicassolato Jul 27, 2023

Choose a reason for hiding this comment

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

We don’t necessarily need - nor /. Intuitively, we went with these characters because the Limitador identifiers that the RateLimitPolicy controller generates come straight from qualified limit definitions stated in Kubernetes resources, where the / char is used as the namespace-resource separator and the - char is often used in the names of the resources. We first thought that by keeping such format we'd favour readability (even though we’re here talking about internal values of internal resources that hardly will be inspected by humans).

In the end, all we need are unique limit identifiers. Readability and easy referencing of those bits of configuration across resources are a plus. In fact, while we are using the namespaced name of the RateLimitPolicy resource in the namespace field of the rate limit definition, only the name of the limit for this particular identifier suffices. Replacing the unsupported characters there won't be a problem.

All that to say that we don't need this PR. We can fix some other way in the RateLimitPolicy controller, in https://github.com/kuadrant/kuadrant-operator.

Thanks @didierofrivia and @alexsnaps! I think we can close this.

}

fn scan_string(&mut self, until: char) -> Result<Token, SyntaxError> {
Expand Down Expand Up @@ -777,14 +777,14 @@ mod conditions {

#[test]
fn test_charset() {
let tokens =
Scanner::scan(" 変数 == ' 💖 '".to_owned()).expect("Should parse alright!");
let tokens = Scanner::scan(" love.en-US/愛.jp == ' 💖 '".to_owned())
.expect("Should parse alright!");
assert_eq!(tokens.len(), 3);
assert_eq!(
tokens[0],
Token {
token_type: TokenType::Identifier,
literal: Some(Identifier("変数".to_owned())),
literal: Some(Identifier("love.en-US/愛.jp".to_owned())),
pos: 2,
}
);
Expand All @@ -793,15 +793,15 @@ mod conditions {
Token {
token_type: TokenType::EqualEqual,
literal: None,
pos: 5,
pos: 18,
}
);
assert_eq!(
tokens[2],
Token {
token_type: TokenType::String,
literal: Some(Literal::String(" 💖 ".to_owned())),
pos: 8,
pos: 21,
}
);
}
Expand Down
Loading