-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::OpenIdClient; | ||
use actix_web::{web, HttpRequest}; | ||
use anyhow::Context; | ||
use drogue_cloud_service_api::endpoints::Endpoints; | ||
use serde_json::{json, Value}; | ||
use std::borrow::Cow; | ||
|
||
const SPEC: &str = include_str!("../api/index.yaml"); | ||
|
||
pub fn spec( | ||
req: HttpRequest, | ||
endpoints: &Endpoints, | ||
client: web::Data<OpenIdClient>, | ||
) -> anyhow::Result<Value> { | ||
let mut api: Value = serde_yaml::from_str(SPEC).context("Failed to parse OpenAPI YAML")?; | ||
|
||
let url = endpoints.api.as_ref().map(Cow::from).unwrap_or_else(|| { | ||
let ci = req.connection_info(); | ||
Cow::from(format!("{}://{}", ci.scheme(), ci.host())) | ||
}); | ||
|
||
// server | ||
|
||
api["servers"] = json!([{ "url": url, "description": "Drogue Cloud API" }]); | ||
|
||
// SSO | ||
|
||
let url = client.client.config().authorization_endpoint.clone(); | ||
|
||
api["security"] = json!([{"Drogue Cloud SSO": []}]); | ||
api["components"]["securitySchemes"] = json!({ | ||
"Drogue Cloud SSO": { | ||
"type": "oauth2", | ||
"description": "SSO", | ||
"flows": { | ||
"implicit": { | ||
"authorizationUrl": url, | ||
"scopes": { | ||
"openid": "OpenID Connect", | ||
} | ||
} | ||
} | ||
}, | ||
}); | ||
|
||
// render | ||
|
||
Ok(api) | ||
} |
Submodule helm
updated
9 files