Skip to content

Commit

Permalink
Fix config
Browse files Browse the repository at this point in the history
  • Loading branch information
Threated committed Nov 7, 2023
1 parent ea564c2 commit 8faa99e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.local
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ COPY --from=proxy /usr/local/bin/beam /usr/local/bin/proxy
COPY --from=builder /app/target/release/local /usr/local/bin/

ENV APP_secret-sync_KEY=NotSecret
ENV RUST_LOG=warn
ENTRYPOINT ["sh", "-c", "/usr/local/bin/proxy & /usr/local/bin/local $@", "_"]
# ENTRYPOINT [ "tail", "-f", "/dev/null" ]
10 changes: 3 additions & 7 deletions central/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ use crate::keycloak::{KeyCloakConfig, self};
#[derive(Debug, Parser)]
pub struct Config {
/// Address the server should bind to
#[clap(env, default_value = "0.0.0.0:8080")]
#[clap(env, long, default_value = "0.0.0.0:8080")]
pub bind_addr: SocketAddr,

/// Url of the local beam proxy which is required to have sockets enabled
#[clap(env, default_value = "http://beam-proxy:8081")]
#[clap(env, long, default_value = "http://beam-proxy:8081")]
pub beam_url: Url,

/// Url of the local Keycloak
#[clap(env, default_value = "http://keycloak:8080")] // TODO: Find the right default url
pub keycloak_url: Url,

/// Beam api key
#[clap(env)]
#[clap(env, long)]
pub beam_secret: String,

/// The app id of this application
Expand Down
48 changes: 35 additions & 13 deletions central/src/keycloak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ async fn get_access_token(conf: &KeyCloakConfig) -> Result<String> {
struct Token {
access_token: String,
}
dbg!(CLIENT
.post(&format!(
"{}/realms/{}/protocol/openid-connect/token",
conf.keycloak_url, conf.keycloak_realm
))
.form(&json!({
"client_id": conf.keycloak_id,
"client_secret": conf.keycloak_secret,
"grant_type": "client_credentials"
}))
.send()
.await?)
CLIENT
.post(&format!(
"{}/realms/{}/protocol/openid-connect/token",
conf.keycloak_url, conf.keycloak_realm
))
.form(&json!({
"client_id": conf.keycloak_id,
"client_secret": conf.keycloak_secret,
"grant_type": "client_credentials"
}))
.send()
.await?
.json::<Token>()
.await
.map(|t| t.access_token)
Expand Down Expand Up @@ -66,6 +66,20 @@ async fn get_access_token_via_admin_login(conf: &KeyCloakConfig) -> Result<Strin
.map(|t| t.access_token)
}

#[cfg(test)]
async fn get_client(id: &str, token: &str, conf: &KeyCloakConfig) -> Result<serde_json::Value> {
dbg!(CLIENT
.get(&format!(
"{}/admin/realms/{}/clients/{id}",
conf.keycloak_url, conf.keycloak_realm
))
.bearer_auth(token)
.send()
.await?)
.json()
.await
}

#[tokio::test]
async fn test_create_client() -> Result<()> {
let conf = KeyCloakConfig {
Expand All @@ -76,6 +90,7 @@ async fn test_create_client() -> Result<()> {
};
let token = get_access_token_via_admin_login(&conf).await?;
dbg!(post_client(&token, "test", vec!["http://test.bk".into()], &conf).await?);
dbg!(get_client("test", &token, &conf).await.unwrap());
Ok(())
}

Expand Down Expand Up @@ -125,7 +140,7 @@ async fn post_client(
match res.status() {
StatusCode::CREATED => Ok(SecretResult::Created(secret)),
StatusCode::CONFLICT => Ok(SecretResult::AlreadyValid),
s => unreachable!("Unexpected statuscode {s} while creating keycloak client")
s => unreachable!("Unexpected statuscode {s} while creating keycloak client"),
}
}

Expand All @@ -152,3 +167,10 @@ pub async fn create_client(
) -> Result<SecretResult> {
post_client(&get_access_token(conf).await?, name, redirect_urls, conf).await
}

///
/// pw set? validate?
/// pw create but what if it already exists?
///
///
mod asdf {}
3 changes: 0 additions & 3 deletions local/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ impl FromStr for SecretArg {
// Add new `SecretRequest` variants here
let request = match secret_type {
"OIDC" => {
// if CONFIG.oidc_provieder.is_none() {
// return Err("Can not create OIDC client without the 'OIDC_PROVIDER' config option!".into());
// }
let redirect_urls = args.split(',').map(ToString::to_string).collect();
Ok(SecretRequest::OpenIdConnect { redirect_urls })
},
Expand Down

0 comments on commit 8faa99e

Please sign in to comment.