Skip to content

Commit

Permalink
feat(auth): add email and billing management to CLI (#155)
Browse files Browse the repository at this point in the history
Introduced commands for setting email and enabling billing. Updated GraphQL schema to support these actions.
  • Loading branch information
steebchen authored Jan 9, 2025
1 parent 96d1b7c commit 9e71117
Show file tree
Hide file tree
Showing 6 changed files with 544 additions and 2 deletions.
29 changes: 29 additions & 0 deletions cli/src/command/auth/billing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use anyhow::Result;
use clap::Args;
use slot::graphql::auth::{update_me::*, UpdateMe};
use slot::graphql::GraphQLQuery;
use slot::{api::Client, credential::Credentials};

#[derive(Debug, Args)]
#[command(next_help_heading = "Set billing options")]
pub struct BillingArgs {
#[arg(help = "Enable slot billing for the authenticated user.")]
#[clap(long, short, action)]
pub enabled: bool,
}

impl BillingArgs {
pub async fn run(&self) -> Result<()> {
let credentials = Credentials::load()?;
let client = Client::new_with_token(credentials.access_token);

let request_body = UpdateMe::build_query(Variables {
email: None,
slot_billing: Some(self.enabled),
});
let res: ResponseData = client.query(&request_body).await?;
print!("{:?}", res);

Ok(())
}
}
28 changes: 28 additions & 0 deletions cli/src/command/auth/email.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use anyhow::Result;
use clap::Args;
use slot::graphql::auth::{update_me::*, UpdateMe};
use slot::graphql::GraphQLQuery;
use slot::{api::Client, credential::Credentials};

#[derive(Debug, Args)]
#[command(next_help_heading = "Set email options")]
pub struct EmailArgs {
#[arg(help = "The email address of the user.")]
pub email: String,
}

impl EmailArgs {
pub async fn run(&self) -> Result<()> {
let credentials = Credentials::load()?;
let client = Client::new_with_token(credentials.access_token);

let request_body = UpdateMe::build_query(Variables {
email: Some(self.email.clone()),
slot_billing: None,
});
let res: ResponseData = client.query(&request_body).await?;
print!("{:?}", res);

Ok(())
}
}
16 changes: 14 additions & 2 deletions cli/src/command/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use self::{email::EmailArgs, info::InfoArgs, login::LoginArgs};
use crate::command::auth::billing::BillingArgs;
use anyhow::Result;
use clap::Subcommand;

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

mod billing;
mod email;
mod info;
mod login;
mod session;
Expand All @@ -11,8 +13,16 @@ mod session;
pub enum Auth {
#[command(about = "Login to your Cartridge account.")]
Login(LoginArgs),

#[command(about = "Display info about the authenticated user.")]
Info(InfoArgs),

#[command(about = "Set the email address for the authenticated user.")]
SetEmail(EmailArgs),

#[command(about = "Manage slot billing for the authenticated user.")]
EnableSlotBilling(BillingArgs),

// Mostly for testing purposes, will eventually turn it into a library call from `sozo`.
#[command(hide = true)]
CreateSession(session::CreateSession),
Expand All @@ -24,6 +34,8 @@ impl Auth {
Auth::Login(args) => args.run().await,
Auth::Info(args) => args.run().await,
Auth::CreateSession(args) => args.run().await,
Auth::SetEmail(args) => args.run().await,
Auth::EnableSlotBilling(args) => args.run().await,
}
}
}
Loading

0 comments on commit 9e71117

Please sign in to comment.