Skip to content

Commit

Permalink
Derive some more traits for the public api (#106)
Browse files Browse the repository at this point in the history
* Derive some more traits for the public api

* Update the generator script also

* removed sensitive data leaks, ns changes

* removed additional requirements for KeycloakTokenSupplier implementors

* reorder derives like std,3dparty

---------

Co-authored-by: Alexander Korolev <[email protected]>
  • Loading branch information
omid and kilork authored Apr 21, 2024
1 parent 6a50606 commit 0a19aff
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 107 deletions.
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

0 comments on commit 0a19aff

Please sign in to comment.