Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slot lib #61

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
695 changes: 359 additions & 336 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ tempfile = "3.10.1"

[[bin]]
name = "slot"
path = "src/main.rs"
path = "src/bin/main.rs"
6 changes: 6 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,9 @@ impl Client {
url
}
}

impl Default for Client {
fn default() -> Self {
Self::new()
}
}
17 changes: 4 additions & 13 deletions src/command/auth/info.rs → src/bin/command/auth/info.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};
use me::{ResponseData, Variables};

use crate::{api::Client, credential::Credentials};

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/auth/info.graphql",
response_derives = "Debug, Clone, Serialize"
)]
pub struct Me;
use slot::graphql::auth::{me::*, Me};
use slot::graphql::{GraphQLQuery, Response};
use slot::{api::Client, credential::Credentials};

#[derive(Debug, Args)]
pub struct InfoArgs {}
pub struct InfoArgs;

impl InfoArgs {
// TODO: find the account info from `credentials.json` first before making a request
Expand Down
4 changes: 2 additions & 2 deletions src/command/auth/login.rs → src/bin/command/auth/login.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{browser::Browser, server::LocalServer};
use anyhow::Result;
use clap::Args;
use slot::{browser::Browser, server::LocalServer};
use tokio::runtime::Runtime;

#[derive(Debug, Args)]
pub struct LoginArgs {}
pub struct LoginArgs;

impl LoginArgs {
pub fn run(&self) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion src/command/auth/mod.rs → src/bin/command/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clap::Subcommand;

use self::{info::InfoArgs, login::LoginArgs};

pub mod info;
mod info;
mod login;

#[derive(Subcommand, Debug)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,22 @@

use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};
use katana_primitives::contract::ContractAddress;
use katana_primitives::genesis::allocation::GenesisAccountAlloc;
use katana_primitives::genesis::allocation::{
DevAllocationsGenerator, DevGenesisAccount, GenesisAccount,
};
use katana_primitives::genesis::Genesis;
use slot::graphql::deployments::katana_accounts::KatanaAccountsDeploymentConfig::KatanaConfig;
use slot::graphql::deployments::{katana_accounts::*, KatanaAccounts};
use slot::graphql::{GraphQLQuery, Response};
use starknet::core::types::FieldElement;

use crate::api::Client;
use crate::credential::Credentials;
use slot::api::Client;
use slot::credential::Credentials;

use super::services::KatanaAccountCommands;

use self::katana_accounts::{
KatanaAccountsDeploymentConfig::KatanaConfig, ResponseData, Variables,
};

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/accounts.graphql",
response_derives = "Debug"
)]
pub struct KatanaAccounts;

#[derive(Debug, Args)]
#[command(next_help_heading = "Accounts options")]
pub struct AccountsArgs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,16 @@

use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};

use crate::{
api::Client,
command::deployments::create::create_deployment::{
CreateDeploymentCreateDeployment::{KatanaConfig, MadaraConfig, ToriiConfig},
CreateKatanaConfigInput, CreateMadaraConfigInput, CreateServiceConfigInput,
CreateServiceInput, CreateToriiConfigInput, DeploymentService, DeploymentTier, Variables,
},
credential::Credentials,
use slot::api::Client;
use slot::credential::Credentials;
use slot::graphql::deployments::create_deployment::CreateDeploymentCreateDeployment::{
KatanaConfig, MadaraConfig, ToriiConfig,
};
use slot::graphql::deployments::create_deployment::{self, *};
use slot::graphql::deployments::CreateDeployment;
use slot::graphql::{GraphQLQuery, Response};

use super::{services::CreateServiceCommands, Long, Tier};

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/create.graphql",
response_derives = "Debug"
)]
pub struct CreateDeployment;
use super::{services::CreateServiceCommands, Tier};

#[derive(Debug, Args)]
#[command(next_help_heading = "Create options")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
#![allow(clippy::enum_variant_names)]

use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};

use crate::{
api::Client,
command::deployments::delete::delete_deployment::{DeploymentService, Variables},
credential::Credentials,
};

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/delete.graphql",
response_derives = "Debug"
)]
pub struct DeleteDeployment;
use slot::graphql::deployments::{delete_deployment::*, DeleteDeployment};
use slot::graphql::{GraphQLQuery, Response};
use slot::{api::Client, credential::Credentials};

#[derive(clap::ValueEnum, Clone, Debug, serde::Serialize)]
pub enum Service {
Expand Down Expand Up @@ -51,7 +37,7 @@ impl DeleteArgs {
let user = Credentials::load()?;
let client = Client::new_with_token(user.access_token);

let res: Response<delete_deployment::ResponseData> = client.query(&request_body).await?;
let res: Response<ResponseData> = client.query(&request_body).await?;
if let Some(errors) = res.errors.clone() {
for err in errors {
println!("Error: {}", err.message);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
#![allow(clippy::enum_variant_names)]

use super::services::Service;
use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};

use crate::{api::Client, credential::Credentials};

use self::describe_deployment::{
DeploymentService,
DescribeDeploymentDeploymentConfig::{KatanaConfig, MadaraConfig, ToriiConfig},
ResponseData, Variables,
use slot::graphql::deployments::describe_deployment::DescribeDeploymentDeploymentConfig::{
KatanaConfig, MadaraConfig, ToriiConfig,
};

use super::services::Service;

type Long = u64;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/describe.graphql",
response_derives = "Debug"
)]
pub struct DescribeDeployment;
use slot::graphql::deployments::{describe_deployment::*, DescribeDeployment};
use slot::graphql::{GraphQLQuery, Response};
use slot::{api::Client, credential::Credentials};

#[derive(Debug, Args)]
#[command(next_help_heading = "Describe options")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,14 @@

use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};
use slot::graphql::deployments::fork_deployment::ForkDeploymentForkDeployment::KatanaConfig;
use slot::graphql::deployments::{fork_deployment::*, ForkDeployment};
use slot::graphql::{GraphQLQuery, Response};
use slot::{api::Client, credential::Credentials};
use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient, Provider};
use url::Url;

use crate::{
api::Client,
command::deployments::fork::fork_deployment::{
DeploymentTier, ForkDeploymentForkDeployment::KatanaConfig, Variables,
},
credential::Credentials,
};

use super::{services::ForkServiceCommands, Long, Tier};

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/fork.graphql",
response_derives = "Debug"
)]
pub struct ForkDeployment;
use super::{services::ForkServiceCommands, Tier};

#[derive(Debug, Args)]
#[command(next_help_heading = "Fork options")]
Expand Down Expand Up @@ -57,7 +44,7 @@ impl ForkArgs {
let user = Credentials::load()?;
let client = Client::new_with_token(user.access_token);

let res: Response<fork_deployment::ResponseData> = client.query(&request_body).await?;
let res: Response<ResponseData> = client.query(&request_body).await?;
if let Some(errors) = res.errors.clone() {
for err in errors {
println!("Error: {}", err.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@

use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};

use crate::{api::Client, credential::Credentials};

use self::list_deployments::{ResponseData, Variables};

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/list.graphql",
response_derives = "Debug"
)]
pub struct ListDeployments;
use slot::graphql::deployments::list_deployments::{ResponseData, Variables};
use slot::graphql::deployments::ListDeployments;
use slot::graphql::{GraphQLQuery, Response};
use slot::{api::Client, credential::Credentials};

#[derive(Debug, Args)]
#[command(next_help_heading = "List options")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,16 @@ use std::{
time::Duration,
};

// use tokio::selectV
use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};
use tokio::time::sleep;

use crate::{
api::Client, command::deployments::logs::deployment_logs::DeploymentService,
credential::Credentials,
};

use self::deployment_logs::{DeploymentLogsDeploymentLogs, ResponseData, Variables};
use slot::credential::Credentials;
use slot::graphql::deployments::deployment_logs::DeploymentService;
use slot::graphql::{deployments::deployment_logs::*, GraphQLQuery, Response};
use slot::{api::Client, graphql::deployments::DeploymentLogs};

use super::services::Service;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/logs.graphql",
response_derives = "Debug"
)]
pub struct DeploymentLogs;

type Time = String;

#[derive(Debug, Args)]
#[command(next_help_heading = "Deployment logs options")]
pub struct LogsArgs {
Expand Down Expand Up @@ -135,7 +121,7 @@ impl LogReader {

let mut since = logs.until;
while running.load(Ordering::SeqCst) {
sleep(Duration::from_millis(1000)).await;
tokio::time::sleep(Duration::from_millis(1000)).await;
logs = self.query(Some(since.clone()), 25).await?;

if !printed_logs.contains(&logs.content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ mod logs;
mod services;
mod update;

type Long = u64;

#[derive(Subcommand, Debug)]
pub enum Deployments {
#[command(about = "Create a new deployment.")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@

use anyhow::Result;
use clap::Args;
use graphql_client::{GraphQLQuery, Response};

use self::update_deployment::UpdateServiceInput;
use crate::{
api::Client,
command::deployments::update::update_deployment::{
DeploymentService, DeploymentTier,
UpdateDeploymentUpdateDeployment::{KatanaConfig, MadaraConfig, ToriiConfig},
UpdateKatanaConfigInput, UpdateServiceConfigInput, Variables,
},
credential::Credentials,
use slot::api::Client;
use slot::credential::Credentials;
use slot::graphql::deployments::update_deployment::UpdateDeploymentUpdateDeployment::{
KatanaConfig, MadaraConfig, ToriiConfig,
};
use slot::graphql::deployments::update_deployment::{
self, UpdateKatanaConfigInput, UpdateServiceConfigInput, UpdateServiceInput,
};
use slot::graphql::deployments::{update_deployment::*, UpdateDeployment};
use slot::graphql::{GraphQLQuery, Response};

use super::services::UpdateServiceCommands;

type Long = u64;

#[derive(GraphQLQuery)]
#[graphql(
schema_path = "schema.json",
query_path = "src/command/deployments/update.graphql",
response_derives = "Debug"
)]
pub struct UpdateDeployment;

#[derive(clap::ValueEnum, Clone, Debug, serde::Serialize)]
pub enum Tier {
Basic,
Expand Down
File renamed without changes.
Loading
Loading