Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
|
a4665ddb06 | ||
|
242b950c13 | ||
|
15dc36f337 |
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "droneconf"
|
name = "droneconf"
|
||||||
version = "0.1.0"
|
version = "1.0.2"
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
|
@ -59,10 +59,10 @@ async fn on_request(
|
||||||
Json(body): Json<Request>,
|
Json(body): Json<Request>,
|
||||||
Extension(APIConfig(client)): Extension<APIConfig>,
|
Extension(APIConfig(client)): Extension<APIConfig>,
|
||||||
) -> Result<impl IntoResponse, Error> {
|
) -> Result<impl IntoResponse, Error> {
|
||||||
let conf = body.config();
|
let conf = body.config().ok_or(Error::NoContent)?;
|
||||||
if conf.starts_with("http://") || conf.starts_with("https://") {
|
if conf.starts_with("http://") || conf.starts_with("https://") {
|
||||||
let drone_config = client.get(conf).send().await?.text().await?;
|
let drone_config = client.get(conf).send().await?.text().await?;
|
||||||
let response = Response { data: drone_config };
|
let response = Response::new(drone_config, body.is_woodpecker());
|
||||||
return Ok(Json(response));
|
return Ok(Json(response));
|
||||||
}
|
}
|
||||||
Err(Error::NoContent)
|
Err(Error::NoContent)
|
||||||
|
|
45
src/model.rs
45
src/model.rs
|
@ -4,15 +4,27 @@ use serde::{Deserialize, Serialize};
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Request {
|
pub struct Request {
|
||||||
pub repo: Repository,
|
pub repo: Repository,
|
||||||
|
pub configs: Option<Vec<WoodpeckerConfig>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Repository {
|
pub struct Repository {
|
||||||
pub config_path: String,
|
pub config_path: Option<String>,
|
||||||
|
pub config_file: Option<String>,
|
||||||
|
pub config: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub data: Option<String>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub configs: Option<Vec<WoodpeckerConfig>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct WoodpeckerConfig {
|
||||||
|
pub name: String,
|
||||||
pub data: String,
|
pub data: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +32,34 @@ pub struct Response {
|
||||||
pub struct APIConfig(pub Client);
|
pub struct APIConfig(pub Client);
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
pub fn config(&self) -> String {
|
pub fn config(&self) -> Option<String> {
|
||||||
self.repo.config_path.clone()
|
self.repo
|
||||||
|
.config_path
|
||||||
|
.clone()
|
||||||
|
.or(self.repo.config_file.clone())
|
||||||
|
.or(self.repo.config.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn is_woodpecker(&self) -> bool {
|
||||||
|
self.configs.is_some()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Response {
|
||||||
|
pub fn new(data: String, is_woodpecker: bool) -> Self {
|
||||||
|
if !is_woodpecker {
|
||||||
|
Self {
|
||||||
|
data: Some(data),
|
||||||
|
configs: None,
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Self {
|
||||||
|
data: None,
|
||||||
|
configs: Some(vec![WoodpeckerConfig {
|
||||||
|
name: "central-override".to_string(),
|
||||||
|
data,
|
||||||
|
}]),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue