Compare commits
No commits in common. "master" and "1.0" have entirely different histories.
3 changed files with 6 additions and 45 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "droneconf"
|
||||
version = "1.0.2"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
|
||||
# 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>,
|
||||
Extension(APIConfig(client)): Extension<APIConfig>,
|
||||
) -> Result<impl IntoResponse, Error> {
|
||||
let conf = body.config().ok_or(Error::NoContent)?;
|
||||
let conf = body.config();
|
||||
if conf.starts_with("http://") || conf.starts_with("https://") {
|
||||
let drone_config = client.get(conf).send().await?.text().await?;
|
||||
let response = Response::new(drone_config, body.is_woodpecker());
|
||||
let response = Response { data: drone_config };
|
||||
return Ok(Json(response));
|
||||
}
|
||||
Err(Error::NoContent)
|
||||
|
|
45
src/model.rs
45
src/model.rs
|
@ -4,27 +4,15 @@ use serde::{Deserialize, Serialize};
|
|||
#[derive(Deserialize)]
|
||||
pub struct Request {
|
||||
pub repo: Repository,
|
||||
pub configs: Option<Vec<WoodpeckerConfig>>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Repository {
|
||||
pub config_path: Option<String>,
|
||||
pub config_file: Option<String>,
|
||||
pub config: Option<String>,
|
||||
pub config_path: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
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,
|
||||
}
|
||||
|
||||
|
@ -32,34 +20,7 @@ pub struct WoodpeckerConfig {
|
|||
pub struct APIConfig(pub Client);
|
||||
|
||||
impl Request {
|
||||
pub fn config(&self) -> Option<String> {
|
||||
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,
|
||||
}]),
|
||||
}
|
||||
}
|
||||
pub fn config(&self) -> String {
|
||||
self.repo.config_path.clone()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue