-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added function create_task from autogenerated, trying some stuff for …
…service.rs
- Loading branch information
Showing
24 changed files
with
318 additions
and
35 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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
//! This is the main library file for the `lib` crate. | ||
#![warn(missing_docs)] | ||
#![allow(unused_imports)] | ||
|
||
#[macro_use] | ||
extern crate serde_derive; | ||
|
||
// UNIT TESTING | ||
#[cfg(test)] | ||
mod tests { | ||
// use super::*; | ||
extern crate serde; | ||
extern crate serde_json; | ||
extern crate url; | ||
extern crate reqwest; | ||
|
||
#[test] | ||
fn test() { | ||
// This test currently does nothing, it is just a placeholder. | ||
} | ||
} | ||
|
||
pub mod service; | ||
pub mod tes; |
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,77 @@ | ||
use reqwest::Client; | ||
use serde::Serialize; | ||
use serde_json::Value; | ||
use std::error::Error; | ||
|
||
#[derive(Debug)] | ||
pub struct Service { | ||
base_url: String, | ||
client: Client, | ||
username: Option<String>, | ||
password: Option<String>, | ||
token: Option<String>, | ||
} | ||
|
||
impl Service { | ||
pub fn new(base_url: String, username: Option<String>, password: Option<String>, token: Option<String>) -> Self { | ||
Service { | ||
base_url, | ||
client: Client::new(), | ||
username, | ||
password, | ||
token, | ||
} | ||
} | ||
|
||
pub async fn request( | ||
&self, | ||
method: reqwest::Method, | ||
endpoint: &str, | ||
data: Option<Value>, | ||
params: Option<Value>, | ||
) -> Result<Value, Box<dyn Error>> { | ||
let url = format!("{}/{}", self.base_url, endpoint); | ||
let mut headers = reqwest::header::HeaderMap::new(); | ||
headers.insert("Content-Type", "application/json".parse()?); | ||
|
||
if let Some(token) = &self.token { | ||
headers.insert( | ||
"Authorization", | ||
format!("Bearer {}", token).parse()?, | ||
); | ||
} | ||
|
||
let mut req_builder = self.client.request(method, &url).headers(headers); | ||
|
||
if let Some(data) = data { | ||
req_builder = req_builder.json(&data); | ||
} | ||
|
||
if let Some(params) = params { | ||
req_builder = req_builder.query(¶ms); | ||
} | ||
|
||
let response = req_builder.send().await?; | ||
|
||
if !response.status().is_success() { | ||
let error_message = format!("Error: HTTP {} - {}", response.status(), response.status().canonical_reason().unwrap_or("Unknown error")); | ||
eprintln!("{}", error_message); | ||
return Err(error_message.into()); | ||
} | ||
|
||
let content_type = response | ||
.headers() | ||
.get(reqwest::header::CONTENT_TYPE) | ||
.and_then(|value| value.to_str().ok()) | ||
.unwrap_or(""); | ||
|
||
let response_data = if content_type.contains("application/json") { | ||
response.json::<Value>().await? | ||
} else { | ||
Value::String(response.text().await?) | ||
}; | ||
|
||
Ok(response_data) | ||
} | ||
|
||
} |
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,53 @@ | ||
/* | ||
* Task Execution Service | ||
* | ||
* ## Executive Summary The Task Execution Service (TES) API is a standardized schema and API for describing and executing batch execution tasks. A task defines a set of input files, a set of containers and commands to run, a set of output files and some other logging and metadata. TES servers accept task documents and execute them asynchronously on available compute resources. A TES server could be built on top of a traditional HPC queuing system, such as Grid Engine, Slurm or cloud style compute systems such as AWS Batch or Kubernetes. ## Introduction This document describes the TES API and provides details on the specific endpoints, request formats, and responses. It is intended to provide key information for developers of TES-compatible services as well as clients that will call these TES services. Use cases include: - Deploying existing workflow engines on new infrastructure. Workflow engines such as CWL-Tes and Cromwell have extentions for using TES. This will allow a system engineer to deploy them onto a new infrastructure using a job scheduling system not previously supported by the engine. - Developing a custom workflow management system. This API provides a common interface to asynchronous batch processing capabilities. A developer can write new tools against this interface and expect them to work using a variety of backend solutions that all support the same specification. ## Standards The TES API specification is written in OpenAPI and embodies a RESTful service philosophy. It uses JSON in requests and responses and standard HTTP/HTTPS for information transport. HTTPS should be used rather than plain HTTP except for testing or internal-only purposes. ### Authentication and Authorization Is is envisaged that most TES API instances will require users to authenticate to use the endpoints. However, the decision if authentication is required should be taken by TES API implementers. If authentication is required, we recommend that TES implementations use an OAuth2 bearer token, although they can choose other mechanisms if appropriate. Checking that a user is authorized to submit TES requests is a responsibility of TES implementations. ### CORS If TES API implementation is to be used by another website or domain it must implement Cross Origin Resource Sharing (CORS). Please refer to https://w3id.org/ga4gh/product-approval-support/cors for more information about GA4GH’s recommendations and how to implement CORS. | ||
* | ||
* The version of the OpenAPI document: 1.1.0 | ||
* | ||
* Generated by: https://openapi-generator.tech | ||
*/ | ||
|
||
|
||
|
||
#[derive(Debug, Clone)] | ||
pub struct Configuration { | ||
pub base_path: String, | ||
pub user_agent: Option<String>, | ||
pub client: reqwest::Client, | ||
pub basic_auth: Option<BasicAuth>, | ||
pub oauth_access_token: Option<String>, | ||
pub bearer_access_token: Option<String>, | ||
pub api_key: Option<ApiKey>, | ||
// TODO: take an oauth2 token source, similar to the go one | ||
} | ||
|
||
pub type BasicAuth = (String, Option<String>); | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ApiKey { | ||
pub prefix: Option<String>, | ||
pub key: String, | ||
} | ||
|
||
|
||
impl Configuration { | ||
pub fn new() -> Configuration { | ||
Configuration::default() | ||
} | ||
} | ||
|
||
impl Default for Configuration { | ||
fn default() -> Self { | ||
Configuration { | ||
base_path: "/ga4gh/tes/v1".to_owned(), | ||
user_agent: Some("OpenAPI-Generator/1.1.0/rust".to_owned()), | ||
client: reqwest::Client::new(), | ||
basic_auth: None, | ||
oauth_access_token: None, | ||
bearer_access_token: None, | ||
api_key: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
use std::error; | ||
use std::fmt; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ResponseContent<T> { | ||
pub status: reqwest::StatusCode, | ||
pub content: String, | ||
pub entity: Option<T>, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum Error<T> { | ||
Reqwest(reqwest::Error), | ||
Serde(serde_json::Error), | ||
Io(std::io::Error), | ||
ResponseError(ResponseContent<T>), | ||
} | ||
|
||
impl <T> fmt::Display for Error<T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let (module, e) = match self { | ||
Error::Reqwest(e) => ("reqwest", e.to_string()), | ||
Error::Serde(e) => ("serde", e.to_string()), | ||
Error::Io(e) => ("IO", e.to_string()), | ||
Error::ResponseError(e) => ("response", format!("status code {}", e.status)), | ||
}; | ||
write!(f, "error in {}: {}", module, e) | ||
} | ||
} | ||
|
||
impl <T: fmt::Debug> error::Error for Error<T> { | ||
fn source(&self) -> Option<&(dyn error::Error + 'static)> { | ||
Some(match self { | ||
Error::Reqwest(e) => e, | ||
Error::Serde(e) => e, | ||
Error::Io(e) => e, | ||
Error::ResponseError(_) => return None, | ||
}) | ||
} | ||
} | ||
|
||
impl <T> From<reqwest::Error> for Error<T> { | ||
fn from(e: reqwest::Error) -> Self { | ||
Error::Reqwest(e) | ||
} | ||
} | ||
|
||
impl <T> From<serde_json::Error> for Error<T> { | ||
fn from(e: serde_json::Error) -> Self { | ||
Error::Serde(e) | ||
} | ||
} | ||
|
||
impl <T> From<std::io::Error> for Error<T> { | ||
fn from(e: std::io::Error) -> Self { | ||
Error::Io(e) | ||
} | ||
} | ||
|
||
pub fn urlencode<T: AsRef<str>>(s: T) -> String { | ||
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() | ||
} | ||
|
||
pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { | ||
if let serde_json::Value::Object(object) = value { | ||
let mut params = vec![]; | ||
|
||
for (key, value) in object { | ||
match value { | ||
serde_json::Value::Object(_) => params.append(&mut parse_deep_object( | ||
&format!("{}[{}]", prefix, key), | ||
value, | ||
)), | ||
serde_json::Value::Array(array) => { | ||
for (i, value) in array.iter().enumerate() { | ||
params.append(&mut parse_deep_object( | ||
&format!("{}[{}][{}]", prefix, key, i), | ||
value, | ||
)); | ||
} | ||
}, | ||
serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), | ||
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())), | ||
} | ||
} | ||
|
||
return params; | ||
} | ||
|
||
unimplemented!("Only objects are supported with style=deepObject") | ||
} | ||
|
||
pub mod tes; | ||
pub mod configuration; | ||
pub mod models; |
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
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
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
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
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
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
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
Oops, something went wrong.