-
Notifications
You must be signed in to change notification settings - Fork 17
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
Spike for constraints #27
base: main
Are you sure you want to change the base?
Changes from all commits
441e588
e9cb99a
696ae5a
b30bc34
344d8fe
0c2f502
787da2f
5454a8e
83d7913
53c1d79
0209713
55d0a6a
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
//! <https://docs.getunleash.io/user_guide/unleash_context> | ||
use std::{collections::HashMap, net::IpAddr}; | ||
|
||
use chrono::Utc; | ||
use serde::{de, Deserialize}; | ||
|
||
// Custom IP Address newtype that can be deserialised from strings e.g. 127.0.0.1 for use with tests. | ||
|
@@ -40,4 +41,10 @@ pub struct Context { | |
pub app_name: String, | ||
#[serde(default)] | ||
pub environment: String, | ||
#[serde(default = "current_time", rename = "currentTime")] | ||
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. We should test #[serde(rename_all = "camelCase")] at some point, might be sufficient. |
||
pub current_time: String, | ||
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 shouldn't be a string. IIRC correctly chrono doesn't have a sensible default, so I suggest: 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. In fact, I'm not sure whether we should be capturing the current time at all. For the proxy use case, clients should not be permitted to time-travel; for the non-proxy use case access to the current time is probably cheap enough, since time access is such a well known thing. We could compile rules that relate to get compiled into a unix time expression for even faster evaluation, if scaling the proxy is required - though I suspect only unleash themselves would hit that scale. |
||
} | ||
|
||
fn current_time() -> String { | ||
Utc::now().to_rfc3339() | ||
} |
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.
It is a shame this needs to change: the enums are much less ergonomic now :( - single attribute structs :(.
I wonder if struct flattening + an internally tagged representation could work: a family of related enums: