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

Derive some more traits for the public api #106

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ heck = "0.5"
clap = { version = "4", features = ["derive", "std"], default-features = false }
toml = "0.8"
serde = { version = "1", features = ["derive", "rc"] }
indexmap = { version = "2", features = ["serde"] }
indexmap = { version = "2", features = ["serde"] }
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ use keycloak::{

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = std::env::var("KEYCLOAK_ADDR").unwrap_or_else(|_| "http://localhost:9080".into());
let url = std::env::var("KEYCLOAK_ADDR").unwrap_or_else(|_| "http://localhost:8080".into());
let user = std::env::var("KEYCLOAK_USER").unwrap_or_else(|_| "admin".into());
let password = std::env::var("KEYCLOAK_PASSWORD").unwrap_or_else(|_| "password".into());

let client = reqwest::Client::new();
let admin_token = KeycloakAdminToken::acquire(&url, &user, &password, &client).await?;

Expand Down
2 changes: 0 additions & 2 deletions examples/adduser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let user = std::env::var("KEYCLOAK_USER").unwrap_or_else(|_| "admin".into());
let password = std::env::var("KEYCLOAK_PASSWORD").unwrap_or_else(|_| "password".into());

eprintln!("Acquire token for {user}:{password}");

let client = reqwest::Client::new();
let admin_token = KeycloakAdminToken::acquire(&url, &user, &password, &client).await?;

Expand Down
4 changes: 2 additions & 2 deletions examples/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ mod openapi {
};
format!(
r##"#[skip_serializing_none]
#[derive(Clone, Debug, Default, PartialEq, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]{}
pub struct {name} {{
{}
Expand Down Expand Up @@ -867,7 +867,7 @@ pub struct {name} {{
.iter()
.all(|variant| variant.chars().all(|c| c.is_uppercase()));
format!(
r##"#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
r##"#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
#[cfg_attr(feature = "schemars", derive(JsonSchema))]{}
pub enum {name} {{
{}
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub enum KeycloakError {
},
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct KeycloakHttpError {
pub error: Option<String>,
#[serde(rename = "errorMessage")]
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ use keycloak::{

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let url = std::env::var("KEYCLOAK_ADDR").unwrap_or_else(|_| "http://localhost:9080".into());
let url = std::env::var("KEYCLOAK_ADDR").unwrap_or_else(|_| "http://localhost:8080".into());
let user = std::env::var("KEYCLOAK_USER").unwrap_or_else(|_| "admin".into());
let password = std::env::var("KEYCLOAK_PASSWORD").unwrap_or_else(|_| "password".into());

let client = reqwest::Client::new();
let admin_token = KeycloakAdminToken::acquire(&url, &user, &password, &client).await?;

Expand Down
3 changes: 2 additions & 1 deletion src/rest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub trait KeycloakTokenSupplier {
async fn get(&self, url: &str) -> Result<String, KeycloakError>;
}

#[derive(Clone)]
pub struct KeycloakServiceAccountAdminTokenRetriever {
client_id: String,
client_secret: String,
Expand Down Expand Up @@ -81,7 +82,7 @@ impl KeycloakServiceAccountAdminTokenRetriever {
}
}

#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
pub struct KeycloakAdminToken {
access_token: String,
expires_in: usize,
Expand Down
Loading