Skip to content

Commit c946ee9

Browse files
authored
Merge pull request #83 from OneLiteFeatherNET/feat/expose-more-options
Feat/expose more options
2 parents dfb1444 + a5fff28 commit c946ee9

File tree

8 files changed

+122
-81
lines changed

8 files changed

+122
-81
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "feedback-fusion"
3-
version = "0.1.4"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "MIT"
66

@@ -50,7 +50,7 @@ tonic-health = "0.11.0"
5050
tonic-reflection = "0.11.0"
5151
tonic-web = "0.11.0"
5252
tokio = { version = "1.37.0", features = ["full"] }
53-
tower = "0.4.13"
53+
tower = { version = "0.4.13", feature = ["limit"] }
5454
tokio-retry = "0.3"
5555
tower-http = { version = "=0.4.4", features = ["trace", "validate-request"] }
5656
tracing = "0.1.39"

charts/feedback-fusion/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.1.7
18+
version: 0.2.0
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.1.4"
24+
appVersion: "0.2.0"

charts/feedback-fusion/values.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ feedbackFusion:
120120
config:
121121
secret: feedback-fusion-config
122122
# RUST_LOG: INFO
123-
# GLOBAL_RATE_LIMIT: 10
124123
# OIDC_AUDIENCE: ""
125124
# OIDC_PROVIDER: ""
126125
#

docs/docs/configuration.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ You can set the following environment variables:
66

77
| Environment Variable | Type | Default Value | Description |
88
|-------------------------|-------------------|----------------------------|-----------------------------------------------------------------------------|
9-
| `GLOBAL_RATE_LIMIT` | `u64` | `10` | The global rate limit for requests. |
109
| `OIDC_PROVIDER` | `String` | N/A | The OIDC provider URL. |
1110
| `OIDC_AUDIENCE` | `String` | `"feedback-fusion"` | The audience for the OIDC tokens. |
1211
| `OIDC_ISSUER` | `Option<String>` | `None` | The optional issuer URL for the OIDC tokens. |
@@ -15,6 +14,21 @@ You can set the following environment variables:
1514
| `OTLP_ENDPOINT` | `Option<String>` | `None` | The gRPC OTLP endpoint to send the trace spans to |
1615
| `SERVICE_NAME` | `String` | `"feedback-fusion"` | Service name used in tracing context |
1716

17+
## Scope Configuration
18+
19+
| Environment Variable | Description |
20+
|-----------------------------------|------------------------------------|
21+
| `OIDC_SCOPE_API` | Scope for API access |
22+
| `OIDC_SCOPE_WRITE` | Scope for write access |
23+
| `OIDC_SCOPE_READ` | Scope for read access |
24+
| `OIDC_SCOPE_WRITE_TARGET` | Scope for writing targets |
25+
| `OIDC_SCOPE_READ_TARGET` | Scope for reading targets |
26+
| `OIDC_SCOPE_WRITE_PROMPT` | Scope for writing prompts |
27+
| `OIDC_SCOPE_READ_PROMPT` | Scope for reading prompts |
28+
| `OIDC_SCOPE_WRITE_FIELD` | Scope for writing fields |
29+
| `OIDC_SCOPE_READ_FIELD` | Scope for reading fields |
30+
| `OIDC_SCOPE_READ_RESPONSE` | Scope for reading responses |
31+
1832
## Database Configuration
1933

2034
The Backend supports mutliple database backends. The backend will choose the database based on your provided configuration values.

src/config.rs

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -34,35 +34,61 @@ lazy_static! {
3434
DatabaseConfiguration::extract().unwrap();
3535
}
3636

37-
#[derive(Deserialize, Debug, Clone, Getters)]
38-
#[get = "pub"]
39-
pub struct Config {
40-
#[serde(default = "default_global_rate_limit")]
41-
global_rate_limit: u64,
42-
oidc_provider: String,
43-
#[serde(default = "default_oidc_audience")]
44-
oidc_audience: String,
45-
oidc_issuer: Option<String>,
46-
config_path: Option<String>,
47-
otlp_endpoint: Option<String>,
48-
#[serde(default = "default_service_name")]
49-
service_name: String
50-
}
37+
macro_rules! config {
38+
(($($ident:ident: $type:ty $(,)? )*), ($($dident:ident: $dtype:ty = $default:expr $(,)?)*)) => {
39+
paste! {
40+
#[derive(Deserialize, Debug, Clone, Getters)]
41+
#[get = "pub"]
42+
pub struct Config {
43+
$(
44+
$ident: $type,
45+
)*
46+
47+
$(
48+
#[serde(default = "default_" $dident)]
49+
$dident: $dtype,
50+
)*
51+
}
5152

52-
#[inline]
53-
fn default_global_rate_limit() -> u64 {
54-
10
55-
}
5653

57-
#[inline]
58-
fn default_oidc_audience() -> String {
59-
"feedback-fusion".to_owned()
54+
$(
55+
#[inline]
56+
fn [<default_ $dident>]() -> $dtype {
57+
$default.to_owned()
58+
}
59+
)*
60+
}
61+
};
6062
}
6163

62-
#[inline]
63-
fn default_service_name() -> String {
64-
"feedback-fusion".to_owned()
65-
}
64+
config!(
65+
(
66+
oidc_provider: String,
67+
oidc_issuer: Option<String>,
68+
config_path: Option<String>,
69+
otlp_endpoint: Option<String>,
70+
),
71+
72+
(
73+
service_name: String = "feedback-fusion"
74+
oidc_audience: String = "feedback-fusion",
75+
76+
oidc_scope_api: String = "api:feedback-fusion",
77+
oidc_scope_write: String = "feedback-fusion:write",
78+
oidc_scope_read: String = "feedback-fusion:read",
79+
80+
oidc_scope_write_target: String = "feedback-fusion:writeTarget",
81+
oidc_scope_read_target: String = "feedback-fusion:readTarget"
82+
83+
oidc_scope_write_prompt: String = "feedback-fusion:writePrompt",
84+
oidc_scope_read_prompt: String = "feedback-fusion:readPrompt"
85+
86+
oidc_scope_write_field: String = "feedback-fusion:writeField",
87+
oidc_scope_read_field: String = "feedback-fusion:readField"
88+
89+
oidc_scope_read_response: String = "feedback-fusion:readResponse"
90+
)
91+
);
6692

6793
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
6894
pub struct InstanceConfig {

src/services/oidc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,16 @@ pub async fn authority() -> Result<Authority> {
9797
#[derive(Debug, Clone, Deserialize)]
9898
pub struct OIDCClaims {
9999
iss: jwt::Issuer,
100+
iat: UnixTime,
100101
aud: jwt::Audiences,
101-
nbf: UnixTime,
102+
nbf: Option<UnixTime>,
102103
exp: UnixTime,
103104
scope: Scope,
104105
}
105106

106107
impl jwt::CoreClaims for OIDCClaims {
107108
fn nbf(&self) -> Option<UnixTime> {
108-
Some(self.nbf)
109+
Some(self.nbf.unwrap_or(self.iat))
109110
}
110111
fn exp(&self) -> Option<UnixTime> {
111112
Some(self.exp)

0 commit comments

Comments
 (0)