Skip to content

Commit

Permalink
wip: cert command
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaro00 committed Aug 20, 2024
1 parent b44c3e1 commit 18a6f12
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 10 deletions.
11 changes: 11 additions & 0 deletions api-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use reqwest::Response;
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use shuttle_common::certificate::AddCertificateRequest;
use shuttle_common::log::{LogsRange, LogsResponseBeta};
use shuttle_common::models::deployment::{
DeploymentRequest, DeploymentRequestBeta, UploadArchiveResponseBeta,
Expand Down Expand Up @@ -231,6 +232,16 @@ impl ShuttleApiClient {
.await
}

pub async fn add_certificate_beta(&self, project: &str, domain: String) -> Result<()> {
self.post(
format!("/projects/{project}/certificates"),
Some(AddCertificateRequest { domain }),
)
.await?;

Ok(())
}

pub async fn create_project(
&self,
project: &str,
Expand Down
31 changes: 24 additions & 7 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl ProjectArgs {
/// for more information.
#[derive(Parser)]
pub enum Command {
/// Create a new Shuttle project
/// Generate a Shuttle project from a template
Init(InitArgs),
/// Run a Shuttle service locally
Run(RunArgs),
Expand All @@ -110,16 +110,19 @@ pub enum Command {
Deployment(DeploymentCommand),
/// View the status of a Shuttle service
Status,
/// Stop this Shuttle service
/// Stop a Shuttle service
Stop,
/// View the logs of a deployment in this Shuttle service
/// View logs of a Shuttle service
Logs(LogsArgs),
/// List or manage projects on Shuttle
/// Manage projects on Shuttle
#[command(subcommand)]
Project(ProjectCommand),
/// Manage resources of a Shuttle project
/// Manage resources
#[command(subcommand)]
Resource(ResourceCommand),
/// BETA: Manage SSL certificates for custom domains
#[command(subcommand)]
Certificate(CertificateCommand),
/// Remove cargo build artifacts in the Shuttle environment
Clean,
/// Login to the Shuttle platform
Expand Down Expand Up @@ -156,7 +159,7 @@ pub struct TableArgs {

#[derive(Parser)]
pub enum DeploymentCommand {
/// List all the deployments for a service
/// List the deployments for a service
List {
#[arg(long, default_value = "1")]
/// Which page to display
Expand All @@ -180,7 +183,7 @@ pub enum DeploymentCommand {

#[derive(Parser)]
pub enum ResourceCommand {
/// List all the resources for a project
/// List the resources for a project
List {
#[command(flatten)]
table: TableArgs,
Expand All @@ -200,6 +203,20 @@ pub enum ResourceCommand {
},
}

#[derive(Parser)]
pub enum CertificateCommand {
/// Add an SSL certificate for a custom domain
Add {
/// Domain name
domain: String,
},
/// List the certificates for a project
List {
#[command(flatten)]
table: TableArgs,
},
}

#[derive(Parser)]
pub enum ProjectCommand {
/// Create an environment for this project on Shuttle
Expand Down
21 changes: 18 additions & 3 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ use tracing::{debug, error, info, trace, warn};
use uuid::Uuid;
use zip::write::FileOptions;

pub use crate::args::{Command, ProjectArgs, RunArgs, ShuttleArgs};
use crate::args::{
ConfirmationArgs, DeployArgs, DeploymentCommand, GenerateCommand, InitArgs, LoginArgs,
LogoutArgs, LogsArgs, ProjectCommand, ProjectStartArgs, ResourceCommand, TableArgs,
CertificateCommand, ConfirmationArgs, DeployArgs, DeploymentCommand, GenerateCommand, InitArgs,
LoginArgs, LogoutArgs, LogsArgs, ProjectCommand, ProjectStartArgs, ResourceCommand, TableArgs,
TemplateLocation,
};
pub use crate::args::{Command, ProjectArgs, RunArgs, ShuttleArgs};
use crate::config::RequestContext;
use crate::provisioner_server::beta::{ProvApiState, ProvisionerServerBeta};
use crate::provisioner_server::LocalProvisioner;
Expand Down Expand Up @@ -271,6 +271,10 @@ impl Shuttle {
confirmation: ConfirmationArgs { yes },
} => self.resource_delete(&resource_type, yes).await,
},
Command::Certificate(cmd) => match cmd {
CertificateCommand::Add { domain } => self.add_certificate(domain).await,
CertificateCommand::List { .. } => todo!(),
},
Command::Project(cmd) => match cmd {
ProjectCommand::Start(ProjectStartArgs { idle_minutes }) => {
if self.beta {
Expand Down Expand Up @@ -1276,6 +1280,17 @@ impl Shuttle {
Ok(CommandOutcome::Ok)
}

async fn add_certificate(&self, domain: String) -> Result<CommandOutcome> {
let client = self.client.as_ref().unwrap();
client
.add_certificate_beta(self.ctx.project_name(), domain.clone())
.await?;

println!("Added certificate for {domain}");

Ok(CommandOutcome::Ok)
}

fn get_secrets(run_args: &RunArgs, service: &BuiltService) -> Result<HashMap<String, String>> {
let secrets_file = run_args.secret_args.secrets.clone().or_else(|| {
let crate_dir = service.crate_directory();
Expand Down

0 comments on commit 18a6f12

Please sign in to comment.