Skip to content

Commit

Permalink
Merge pull request #3 from Sideko-Inc/0.4.0
Browse files Browse the repository at this point in the history
0.4.0
  • Loading branch information
eliasposen authored Apr 2, 2024
2 parents f870008 + 1699dd1 commit a5b48f8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 77 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sideko"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = [
"Elias Posen <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion core/src/cmds/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn handle_login(output: PathBuf) -> Result<()> {

// open browser for login
let login_url = url::Url::parse_with_params(
&format!("{}/api/auth/login_url", config::get_base_url()),
&format!("{}/v1/auth/login_url", config::get_base_url()),
&[
("cli_output", output.to_str().unwrap_or(".")),
("cli_port", &port.to_string()),
Expand Down
56 changes: 26 additions & 30 deletions sideko-api/src/blocking.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/// Generatedby Sideko (sideko.dev)
use crate::auth;
use crate::error_enums;
use crate::request_types::*;
use crate::result;
use crate::error_enums;
use crate::schemas::*;
use reqwest::blocking::Client as ReqwestClient;
use reqwest::blocking::RequestBuilder as ReqwestRequestBuilder;
#[allow(unused)]
use reqwest::blocking::multipart as reqwest_multipart;
use reqwest::blocking::Client as ReqwestClient;
use reqwest::blocking::RequestBuilder as ReqwestRequestBuilder;
use std::collections::BTreeMap;
#[derive(Clone, Debug)]
pub struct Client {
Expand All @@ -17,7 +17,7 @@ pub struct Client {
impl Default for Client {
fn default() -> Self {
Self {
base_url: "http://server-not-specified".to_string(),
base_url: "https://api.sideko.dev".to_string(),
auth: BTreeMap::new(),
}
}
Expand All @@ -30,14 +30,10 @@ impl Client {
}
/// Authentication builder function to store api-key credentials in the client
pub fn with_api_key_auth(mut self, val: &str) -> Self {
self.auth
.insert(
"ApiKeyAuth".to_string(),
auth::AuthProvider::KeyHeader(
"x-sideko-key".to_string(),
val.to_string(),
),
);
self.auth.insert(
"ApiKeyAuth".to_string(),
auth::AuthProvider::KeyHeader("x-sideko-key".to_string(), val.to_string()),
);
self
}
fn builder_with_auth(
Expand All @@ -56,30 +52,31 @@ impl Client {
&self,
request: ExchangeCodeForKeyRequest,
) -> result::Result<ApiKey, error_enums::ExchangeCodeForKeyErrors> {
let endpoint = "/api/auth/exchange_key";
let endpoint = "/v1/auth/exchange_key";
let url = format!("{}{}", self.base_url, endpoint);
let mut query_params: Vec<(&str, String)> = vec![];
query_params.push(("code", format!("{}", & request.code)));
query_params.push(("code", format!("{}", &request.code)));
let unauthed_builder = ReqwestClient::default().get(&url).query(&query_params);
let authed_builder = self.builder_with_auth(unauthed_builder, &["ApiKeyAuth"]);
let response = authed_builder.send().map_err(result::Error::Dispatch)?;
let status_code = response.status().as_u16();
match status_code {
200 => {
let response_text = response.text().unwrap_or_default();
let data = serde_json::from_str::<ApiKey>(&response_text)
.map_err(|serde_err| result::Error::UnexpectedResponseBody {
let data = serde_json::from_str::<ApiKey>(&response_text).map_err(|serde_err| {
result::Error::UnexpectedResponseBody {
status_code,
method: "GET".to_string(),
url: url.to_string(),
response_text,
expected_signature: "ApiKey".to_string(),
serde_err,
})?;
}
})?;
Ok(data)
}
_ => {
let expected_status_codes: Vec<String> = vec!["200".to_string(),];
let expected_status_codes: Vec<String> = vec!["200".to_string()];
Err(result::Error::BlockingUnexpectedStatus {
status_code,
method: "".to_string(),
Expand All @@ -94,7 +91,7 @@ impl Client {
&self,
request: CliCheckUpdatesRequest,
) -> result::Result<Vec<CliUpdate>, error_enums::CliCheckUpdatesErrors> {
let endpoint = format!("/api/cli/updates/{}", request.cli_version);
let endpoint = format!("/v1/cli/updates/{}", request.cli_version);
let url = format!("{}{}", self.base_url, endpoint);
let query_params: Vec<(&str, String)> = vec![];
let unauthed_builder = ReqwestClient::default().get(&url).query(&query_params);
Expand All @@ -104,19 +101,20 @@ impl Client {
match status_code {
200 => {
let response_text = response.text().unwrap_or_default();
let data = serde_json::from_str::<Vec<CliUpdate>>(&response_text)
.map_err(|serde_err| result::Error::UnexpectedResponseBody {
let data = serde_json::from_str::<Vec<CliUpdate>>(&response_text).map_err(
|serde_err| result::Error::UnexpectedResponseBody {
status_code,
method: "GET".to_string(),
url: url.to_string(),
response_text,
expected_signature: "Vec<CliUpdate>".to_string(),
serde_err,
})?;
},
)?;
Ok(data)
}
_ => {
let expected_status_codes: Vec<String> = vec!["200".to_string(),];
let expected_status_codes: Vec<String> = vec!["200".to_string()];
Err(result::Error::BlockingUnexpectedStatus {
status_code,
method: "".to_string(),
Expand All @@ -131,13 +129,13 @@ impl Client {
&self,
request: StatelessGenerateSdkRequest,
) -> result::Result<BinaryResponse, error_enums::StatelessGenerateSdkErrors> {
let endpoint = "/api/stateless/generate_sdk";
let endpoint = "/v1/stateless/generate_sdk";
let url = format!("{}{}", self.base_url, endpoint);
let query_params: Vec<(&str, String)> = vec![];
let unauthed_builder = ReqwestClient::default().post(&url).query(&query_params);
let authed_builder = self.builder_with_auth(unauthed_builder, &["ApiKeyAuth"]);
let request_body: serde_json::Value = serde_json::to_value(request.data)
.map_err(result::Error::Serialize)?;
let request_body: serde_json::Value =
serde_json::to_value(request.data).map_err(result::Error::Serialize)?;
let response = authed_builder
.json(&request_body)
.send()
Expand All @@ -146,13 +144,11 @@ impl Client {
match status_code {
201 => {
let res_bytes = response.bytes().map_err(result::Error::ResponseBytes)?;
let data = BinaryResponse {
content: res_bytes,
};
let data = BinaryResponse { content: res_bytes };
Ok(data)
}
_ => {
let expected_status_codes: Vec<String> = vec!["201".to_string(),];
let expected_status_codes: Vec<String> = vec!["201".to_string()];
Err(result::Error::BlockingUnexpectedStatus {
status_code,
method: "".to_string(),
Expand Down
74 changes: 35 additions & 39 deletions sideko-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ pub mod request_types;
pub mod result;
pub mod schemas;
use request_types::*;
use schemas::*;
use reqwest::multipart as reqwest_multipart;
use reqwest::Client as ReqwestClient;
use reqwest::RequestBuilder as ReqwestRequestBuilder;
use reqwest::multipart as reqwest_multipart;
use schemas::*;
use std::collections::BTreeMap;
#[derive(Clone, Debug)]
pub struct Client {
Expand All @@ -20,7 +20,7 @@ pub struct Client {
impl Default for Client {
fn default() -> Self {
Self {
base_url: "http://server-not-specified".to_string(),
base_url: "https://api.sideko.dev".to_string(),
auth: BTreeMap::new(),
}
}
Expand All @@ -33,14 +33,10 @@ impl Client {
}
/// Authentication builder function to store api-key credentials in the client
pub fn with_api_key_auth(mut self, val: &str) -> Self {
self.auth
.insert(
"ApiKeyAuth".to_string(),
auth::AuthProvider::KeyHeader(
"x-sideko-key".to_string(),
val.to_string(),
),
);
self.auth.insert(
"ApiKeyAuth".to_string(),
auth::AuthProvider::KeyHeader("x-sideko-key".to_string(), val.to_string()),
);
self
}
fn builder_with_auth(
Expand All @@ -56,48 +52,46 @@ impl Client {
req_builder
}
#[allow(unused)]
fn async_multipart_file(
&self,
path: &str,
) -> std::io::Result<reqwest_multipart::Part> {
fn async_multipart_file(&self, path: &str) -> std::io::Result<reqwest_multipart::Part> {
let path: &std::path::Path = path.as_ref();
let file_name = path
.file_name()
.map(|filename| filename.to_string_lossy().into_owned());
let file_bytes = std::fs::read(path)?;
Ok(
reqwest_multipart::Part::bytes(file_bytes)
.file_name(file_name.unwrap_or_default()),
)
Ok(reqwest_multipart::Part::bytes(file_bytes).file_name(file_name.unwrap_or_default()))
}
pub async fn exchange_code_for_key(
&self,
request: ExchangeCodeForKeyRequest,
) -> result::Result<ApiKey, error_enums::ExchangeCodeForKeyErrors> {
let endpoint = "/api/auth/exchange_key";
let endpoint = "/v1/auth/exchange_key";
let url = format!("{}{}", self.base_url, endpoint);
let mut query_params: Vec<(&str, String)> = vec![];
query_params.push(("code", format!("{}", & request.code)));
query_params.push(("code", format!("{}", &request.code)));
let unauthed_builder = ReqwestClient::default().get(&url).query(&query_params);
let authed_builder = self.builder_with_auth(unauthed_builder, &["ApiKeyAuth"]);
let response = authed_builder.send().await.map_err(result::Error::Dispatch)?;
let response = authed_builder
.send()
.await
.map_err(result::Error::Dispatch)?;
let status_code = response.status().as_u16();
match status_code {
200 => {
let response_text = response.text().await.unwrap_or_default();
let data = serde_json::from_str::<ApiKey>(&response_text)
.map_err(|serde_err| result::Error::UnexpectedResponseBody {
let data = serde_json::from_str::<ApiKey>(&response_text).map_err(|serde_err| {
result::Error::UnexpectedResponseBody {
status_code,
method: "GET".to_string(),
url: url.to_string(),
response_text,
expected_signature: "ApiKey".to_string(),
serde_err,
})?;
}
})?;
Ok(data)
}
_ => {
let expected_status_codes: Vec<String> = vec!["200".to_string(),];
let expected_status_codes: Vec<String> = vec!["200".to_string()];
Err(result::Error::UnexpectedStatus {
status_code,
method: "".to_string(),
Expand All @@ -112,29 +106,33 @@ impl Client {
&self,
request: CliCheckUpdatesRequest,
) -> result::Result<Vec<CliUpdate>, error_enums::CliCheckUpdatesErrors> {
let endpoint = format!("/api/cli/updates/{}", request.cli_version);
let endpoint = format!("/v1/cli/updates/{}", request.cli_version);
let url = format!("{}{}", self.base_url, endpoint);
let query_params: Vec<(&str, String)> = vec![];
let unauthed_builder = ReqwestClient::default().get(&url).query(&query_params);
let authed_builder = self.builder_with_auth(unauthed_builder, &["ApiKeyAuth"]);
let response = authed_builder.send().await.map_err(result::Error::Dispatch)?;
let response = authed_builder
.send()
.await
.map_err(result::Error::Dispatch)?;
let status_code = response.status().as_u16();
match status_code {
200 => {
let response_text = response.text().await.unwrap_or_default();
let data = serde_json::from_str::<Vec<CliUpdate>>(&response_text)
.map_err(|serde_err| result::Error::UnexpectedResponseBody {
let data = serde_json::from_str::<Vec<CliUpdate>>(&response_text).map_err(
|serde_err| result::Error::UnexpectedResponseBody {
status_code,
method: "GET".to_string(),
url: url.to_string(),
response_text,
expected_signature: "Vec<CliUpdate>".to_string(),
serde_err,
})?;
},
)?;
Ok(data)
}
_ => {
let expected_status_codes: Vec<String> = vec!["200".to_string(),];
let expected_status_codes: Vec<String> = vec!["200".to_string()];
Err(result::Error::UnexpectedStatus {
status_code,
method: "".to_string(),
Expand All @@ -149,13 +147,13 @@ impl Client {
&self,
request: StatelessGenerateSdkRequest,
) -> result::Result<BinaryResponse, error_enums::StatelessGenerateSdkErrors> {
let endpoint = "/api/stateless/generate_sdk";
let endpoint = "/v1/stateless/generate_sdk";
let url = format!("{}{}", self.base_url, endpoint);
let query_params: Vec<(&str, String)> = vec![];
let unauthed_builder = ReqwestClient::default().post(&url).query(&query_params);
let authed_builder = self.builder_with_auth(unauthed_builder, &["ApiKeyAuth"]);
let request_body: serde_json::Value = serde_json::to_value(request.data)
.map_err(result::Error::Serialize)?;
let request_body: serde_json::Value =
serde_json::to_value(request.data).map_err(result::Error::Serialize)?;
let response = authed_builder
.json(&request_body)
.send()
Expand All @@ -168,13 +166,11 @@ impl Client {
.bytes()
.await
.map_err(result::Error::ResponseBytes)?;
let data = BinaryResponse {
content: res_bytes,
};
let data = BinaryResponse { content: res_bytes };
Ok(data)
}
_ => {
let expected_status_codes: Vec<String> = vec!["201".to_string(),];
let expected_status_codes: Vec<String> = vec!["201".to_string()];
Err(result::Error::UnexpectedStatus {
status_code,
method: "".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion sideko-py/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sideko-py"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = [
"Elias Posen <[email protected]>",
Expand Down
6 changes: 3 additions & 3 deletions sideko_openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ security:

paths:
# Auth exchange
/api/auth/exchange_key:
/v1/auth/exchange_key:
get:
summary: Exchange one-time auth key for api key
operationId: exchange_code_for_key
Expand All @@ -28,7 +28,7 @@ paths:
schema:
$ref: "#/components/schemas/ApiKey"
# CLI-specific
/api/cli/updates/{cli_version}:
/v1/cli/updates/{cli_version}:
get:
summary: Checks if current CLI has updates
operationId: cli_check_updates
Expand All @@ -53,7 +53,7 @@ paths:
$ref: "#/components/schemas/CliUpdate"

# Stateless Operations
/api/stateless/generate_sdk:
/v1/stateless/generate_sdk:
post:
summary: Generate SDK outside of Sideko's versioning flow
operationId: stateless_generate_sdk
Expand Down

0 comments on commit a5b48f8

Please sign in to comment.