This repository has been archived by the owner on Aug 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
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
7 changed files
with
180 additions
and
31 deletions.
There are no files selected for viewing
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
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,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
# This script is a dumb example of a script that can be run by the backend. | ||
# It is not meant to be run by the user, but rather by the backend. | ||
set -e | ||
|
||
echo "This is a superrrrr powerful script!!!! It does nothing but print this message." | ||
|
||
echo "The arguments passed to this script are: $@" | ||
|
||
echo "The environment variables set for this script are:" | ||
env | ||
|
||
echo "The current working directory is: $(pwd)" | ||
|
||
exit 1 |
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,17 @@ | ||
#!/usr/bin/env bash | ||
|
||
|
||
# This script is a dumb example of a script that can be run by the backend. | ||
# It is not meant to be run by the user, but rather by the backend. | ||
set -e | ||
|
||
echo "This is a superrrrr powerful script!!!! It does nothing but print this message." | ||
|
||
echo "The arguments passed to this script are: $@" | ||
|
||
echo "The environment variables set for this script are:" | ||
env | ||
|
||
echo "The current working directory is: $(pwd)" | ||
|
||
exit 0 |
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,9 @@ | ||
import json | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
arg_json = sys.argv[1] | ||
|
||
json.loads(arg_json) | ||
|
||
print('OK') |
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 |
---|---|---|
@@ -1,20 +1,112 @@ | ||
use std::sync::Arc; | ||
|
||
use axum::{debug_handler, Extension, Json}; | ||
use axum::extract::Path; | ||
use axum::http::StatusCode; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::yaml_config::{CatalogYamlConfig, YamlConfig}; | ||
use crate::yaml_config::{CatalogServiceYamlConfig, CatalogYamlConfig, YamlConfig}; | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct Response<T> { | ||
pub struct ResultsResponse<T> { | ||
results: Vec<T>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
pub struct SimpleResponse { | ||
message: Option<String>, | ||
} | ||
|
||
fn find_catalog_by_slug<'a>(catalogs: &'a Vec<CatalogYamlConfig>, catalog_slug: &str) -> Option<&'a CatalogYamlConfig> { | ||
catalogs.iter().find(|catalog| catalog.slug == catalog_slug) | ||
} | ||
|
||
fn find_catalog_service_by_slug<'a>(catalog: &'a CatalogYamlConfig, service_slug: &str) -> Option<&'a CatalogServiceYamlConfig> { | ||
catalog.services.as_ref().unwrap().iter().find(|service| service.slug == service_slug) | ||
} | ||
|
||
#[debug_handler] | ||
pub async fn list_catalog_services( | ||
Path(catalog_slug): Path<String>, | ||
Extension(yaml_config): Extension<Arc<YamlConfig>>, | ||
) -> (StatusCode, Json<ResultsResponse<CatalogServiceYamlConfig>>) { | ||
let catalog = match find_catalog_by_slug(&yaml_config.catalogs, catalog_slug.as_str()) { | ||
Some(catalog) => catalog, | ||
None => return (StatusCode::NOT_FOUND, Json(ResultsResponse { results: vec![] })) | ||
}; | ||
|
||
(StatusCode::OK, Json(ResultsResponse { results: catalog.services.clone().unwrap_or(vec![]) })) | ||
} | ||
|
||
#[debug_handler] | ||
pub async fn list_catalogs( | ||
Extension(yaml_config): Extension<Arc<YamlConfig>> | ||
) -> (StatusCode, Json<Response<CatalogYamlConfig>>) { | ||
(StatusCode::OK, Json(Response { results: yaml_config.catalog.clone() })) | ||
pub async fn exec_catalog_service_validate_scripts( | ||
Path((catalog_slug, service_slug)): Path<(String, String)>, | ||
Extension(yaml_config): Extension<Arc<YamlConfig>>, | ||
) -> (StatusCode, Json<SimpleResponse>) { | ||
let catalog = match find_catalog_by_slug(&yaml_config.catalogs, catalog_slug.as_str()) { | ||
Some(catalog) => catalog, | ||
None => return (StatusCode::NOT_FOUND, Json(SimpleResponse { message: Some("Service not found".to_string()) })) | ||
}; | ||
|
||
let service = match find_catalog_service_by_slug(catalog, service_slug.as_str()) { | ||
Some(service) => service, | ||
None => return (StatusCode::NOT_FOUND, Json(SimpleResponse { message: Some("Service not found".to_string()) })) | ||
}; | ||
|
||
(StatusCode::OK, Json(SimpleResponse { message: None })) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::catalog::{find_catalog_by_slug, find_catalog_service_by_slug}; | ||
use crate::yaml_config::{CatalogServiceYamlConfig, CatalogYamlConfig}; | ||
|
||
#[test] | ||
fn test_find_catalog_by_slug() { | ||
let catalogs = vec![ | ||
CatalogYamlConfig { | ||
name: "Catalog 1".to_string(), | ||
slug: "catalog-1".to_string(), | ||
description: None, | ||
services: None, | ||
}, | ||
CatalogYamlConfig { | ||
name: "Catalog 2".to_string(), | ||
slug: "catalog-2".to_string(), | ||
description: None, | ||
services: None, | ||
}, | ||
]; | ||
|
||
assert_eq!(find_catalog_by_slug(&catalogs, "catalog-1"), Some(&catalogs[0])); | ||
assert_eq!(find_catalog_by_slug(&catalogs, "catalog-2"), Some(&catalogs[1])); | ||
assert_eq!(find_catalog_by_slug(&catalogs, "catalog-3"), None); | ||
} | ||
|
||
#[test] | ||
fn test_find_catalog_service_by_slug() { | ||
let catalog = CatalogYamlConfig { | ||
name: "Catalog 1".to_string(), | ||
slug: "catalog-1".to_string(), | ||
description: None, | ||
services: Some(vec![ | ||
CatalogServiceYamlConfig { | ||
name: "Service 1".to_string(), | ||
slug: "service-1".to_string(), | ||
description: None, | ||
fields: None, | ||
}, | ||
CatalogServiceYamlConfig { | ||
name: "Service 2".to_string(), | ||
slug: "service-2".to_string(), | ||
description: None, | ||
fields: None, | ||
}, | ||
]), | ||
}; | ||
|
||
assert_eq!(find_catalog_service_by_slug(&catalog, "service-1"), Some(&catalog.services.unwrap()[0])); | ||
assert_eq!(find_catalog_service_by_slug(&catalog, "service-2"), Some(&catalog.services.unwrap()[1])); | ||
assert_eq!(find_catalog_service_by_slug(&catalog, "service-3"), None); | ||
} | ||
} |
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
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