Skip to content

Commit

Permalink
Merge pull request #83 from OneLiteFeatherNET/feat/expose-more-options
Browse files Browse the repository at this point in the history
Feat/expose more options
  • Loading branch information
Randoooom committed Jul 11, 2024
2 parents dfb1444 + a5fff28 commit c946ee9
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 81 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "feedback-fusion"
version = "0.1.4"
version = "0.2.0"
edition = "2021"
license = "MIT"

Expand Down Expand Up @@ -50,7 +50,7 @@ tonic-health = "0.11.0"
tonic-reflection = "0.11.0"
tonic-web = "0.11.0"
tokio = { version = "1.37.0", features = ["full"] }
tower = "0.4.13"
tower = { version = "0.4.13", feature = ["limit"] }
tokio-retry = "0.3"
tower-http = { version = "=0.4.4", features = ["trace", "validate-request"] }
tracing = "0.1.39"
Expand Down
4 changes: 2 additions & 2 deletions charts/feedback-fusion/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.7
version: 0.2.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.4"
appVersion: "0.2.0"
1 change: 0 additions & 1 deletion charts/feedback-fusion/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ feedbackFusion:
config:
secret: feedback-fusion-config
# RUST_LOG: INFO
# GLOBAL_RATE_LIMIT: 10
# OIDC_AUDIENCE: ""
# OIDC_PROVIDER: ""
#
Expand Down
16 changes: 15 additions & 1 deletion docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ You can set the following environment variables:

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

## Scope Configuration

| Environment Variable | Description |
|-----------------------------------|------------------------------------|
| `OIDC_SCOPE_API` | Scope for API access |
| `OIDC_SCOPE_WRITE` | Scope for write access |
| `OIDC_SCOPE_READ` | Scope for read access |
| `OIDC_SCOPE_WRITE_TARGET` | Scope for writing targets |
| `OIDC_SCOPE_READ_TARGET` | Scope for reading targets |
| `OIDC_SCOPE_WRITE_PROMPT` | Scope for writing prompts |
| `OIDC_SCOPE_READ_PROMPT` | Scope for reading prompts |
| `OIDC_SCOPE_WRITE_FIELD` | Scope for writing fields |
| `OIDC_SCOPE_READ_FIELD` | Scope for reading fields |
| `OIDC_SCOPE_READ_RESPONSE` | Scope for reading responses |

## Database Configuration

The Backend supports mutliple database backends. The backend will choose the database based on your provided configuration values.
Expand Down
76 changes: 51 additions & 25 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,61 @@ lazy_static! {
DatabaseConfiguration::extract().unwrap();
}

#[derive(Deserialize, Debug, Clone, Getters)]
#[get = "pub"]
pub struct Config {
#[serde(default = "default_global_rate_limit")]
global_rate_limit: u64,
oidc_provider: String,
#[serde(default = "default_oidc_audience")]
oidc_audience: String,
oidc_issuer: Option<String>,
config_path: Option<String>,
otlp_endpoint: Option<String>,
#[serde(default = "default_service_name")]
service_name: String
}
macro_rules! config {
(($($ident:ident: $type:ty $(,)? )*), ($($dident:ident: $dtype:ty = $default:expr $(,)?)*)) => {
paste! {
#[derive(Deserialize, Debug, Clone, Getters)]
#[get = "pub"]
pub struct Config {
$(
$ident: $type,
)*

$(
#[serde(default = "default_" $dident)]
$dident: $dtype,
)*
}

#[inline]
fn default_global_rate_limit() -> u64 {
10
}

#[inline]
fn default_oidc_audience() -> String {
"feedback-fusion".to_owned()
$(
#[inline]
fn [<default_ $dident>]() -> $dtype {
$default.to_owned()
}
)*
}
};
}

#[inline]
fn default_service_name() -> String {
"feedback-fusion".to_owned()
}
config!(
(
oidc_provider: String,
oidc_issuer: Option<String>,
config_path: Option<String>,
otlp_endpoint: Option<String>,
),

(
service_name: String = "feedback-fusion"
oidc_audience: String = "feedback-fusion",

oidc_scope_api: String = "api:feedback-fusion",
oidc_scope_write: String = "feedback-fusion:write",
oidc_scope_read: String = "feedback-fusion:read",

oidc_scope_write_target: String = "feedback-fusion:writeTarget",
oidc_scope_read_target: String = "feedback-fusion:readTarget"

oidc_scope_write_prompt: String = "feedback-fusion:writePrompt",
oidc_scope_read_prompt: String = "feedback-fusion:readPrompt"

oidc_scope_write_field: String = "feedback-fusion:writeField",
oidc_scope_read_field: String = "feedback-fusion:readField"

oidc_scope_read_response: String = "feedback-fusion:readResponse"
)
);

#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
pub struct InstanceConfig {
Expand Down
5 changes: 3 additions & 2 deletions src/services/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,16 @@ pub async fn authority() -> Result<Authority> {
#[derive(Debug, Clone, Deserialize)]
pub struct OIDCClaims {
iss: jwt::Issuer,
iat: UnixTime,
aud: jwt::Audiences,
nbf: UnixTime,
nbf: Option<UnixTime>,
exp: UnixTime,
scope: Scope,
}

impl jwt::CoreClaims for OIDCClaims {
fn nbf(&self) -> Option<UnixTime> {
Some(self.nbf)
Some(self.nbf.unwrap_or(self.iat))
}
fn exp(&self) -> Option<UnixTime> {
Some(self.exp)
Expand Down
Loading

0 comments on commit c946ee9

Please sign in to comment.