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

feat(auth): add email and billing management to CLI #155

Merged
merged 1 commit into from
Jan 9, 2025
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
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
Loading