Skip to content

Commit

Permalink
Merge pull request #4967 from wasmerio/secrets-redeploy
Browse files Browse the repository at this point in the history
  • Loading branch information
xdoardo authored Jul 30, 2024
2 parents 287bf8d + a9a0e9f commit d6ba243
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 10 deletions.
15 changes: 15 additions & 0 deletions lib/backend-api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,9 @@ type Mutation {

"""Delete secret with given ID"""
deleteAppSecret(input: DeleteAppSecretInput!): DeleteAppSecretPayload

"""Redeploy the active version of an app."""
redeployActiveVersion(input: RedeployActiveVersionInput!): RedeployActiveVersionPayload
tokenAuth(input: ObtainJSONWebTokenInput!): ObtainJSONWebTokenPayload
generateDeployToken(input: GenerateDeployTokenInput!): GenerateDeployTokenPayload
verifyAccessToken(token: String): Verify
Expand Down Expand Up @@ -3441,6 +3444,18 @@ input DeleteAppSecretInput {
clientMutationId: String
}

"""Redeploy the active version of an app."""
type RedeployActiveVersionPayload {
app: DeployApp!
clientMutationId: String
}

input RedeployActiveVersionInput {
"""ID of the app to redeploy."""
id: ID!
clientMutationId: String
}

type ObtainJSONWebTokenPayload {
payload: GenericScalar!
refreshExpiresIn: Int!
Expand Down
14 changes: 14 additions & 0 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ use crate::{
GraphQLApiFailure, WasmerClient,
};

pub async fn redeploy_app_by_id(
client: &WasmerClient,
app_id: impl Into<String>,
) -> Result<Option<DeployApp>, anyhow::Error> {
client
.run_graphql_strict(types::RedeployActiveApp::build(
RedeployActiveAppVariables {
id: types::Id::from(app_id),
},
))
.await
.map(|v| v.redeploy_active_version.map(|v| v.app))
}

/// Revoke an existing token
pub async fn revoke_token(
client: &WasmerClient,
Expand Down
17 changes: 17 additions & 0 deletions lib/backend-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1069,6 +1069,23 @@ mod queries {
pub apps: DeployAppConnection,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct RedeployActiveAppVariables {
pub id: cynic::Id,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Mutation", variables = "RedeployActiveAppVariables")]
pub struct RedeployActiveApp {
#[arguments(input: { id: $id })]
pub redeploy_active_version: Option<RedeployActiveVersionPayload>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct RedeployActiveVersionPayload {
pub app: DeployApp,
}

#[derive(cynic::QueryVariables, Debug)]
pub struct PublishDeployAppVars {
pub config: String,
Expand Down
31 changes: 26 additions & 5 deletions lib/cli/src/commands/app/secrets/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub struct CmdAppSecretsCreate {
#[clap(long, name = "from-file", conflicts_with = "name")]
pub from_file: Option<PathBuf>,

/// Whether or not to redeploy the app after creating the secrets.
#[clap(long)]
pub redeploy: bool,

/* --- Parameters --- */
/// The name of the secret to create.
#[clap(name = "name")]
Expand Down Expand Up @@ -153,13 +157,30 @@ impl CmdAppSecretsCreate {
} else {
if !self.quiet {
eprintln!("Succesfully created secret(s):");
for secret in secrets {
for secret in &secrets {
eprintln!("{}", secret.name.bold());
}
eprintln!(
"{}: In order for secrets to appear in your app, re-deploy it.",
"Info".bold()
);

let should_redeploy = self.redeploy || {
if !self.non_interactive && self.from_file.is_some() {
let theme = ColorfulTheme::default();
dialoguer::Confirm::with_theme(&theme)
.with_prompt("Do you want to redeploy your app?")
.interact()?
} else {
false
}
};

if should_redeploy {
wasmer_api::query::redeploy_app_by_id(client, app_id).await?;
eprintln!("{} Deployment complete", "𖥔".yellow().bold());
} else {
eprintln!(
"{}: In order for secrets to appear in your app, re-deploy it.",
"Info".bold()
);
}
}

Ok(())
Expand Down
30 changes: 25 additions & 5 deletions lib/cli/src/commands/app/secrets/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ pub struct CmdAppSecretsUpdate {
)]
pub from_file: Option<PathBuf>,

/// Whether or not to redeploy the app after creating the secrets.
#[clap(long)]
pub redeploy: bool,

/* --- Parameters --- */
/// The name of the secret to update.
#[clap(name = "name")]
Expand Down Expand Up @@ -147,14 +151,30 @@ impl CmdAppSecretsUpdate {
} else {
if !self.quiet {
eprintln!("Succesfully updated secret(s):");
for secret in secrets {
for secret in &secrets {
eprintln!("{}", secret.name.bold());
}

eprintln!(
"{}: In order for secrets to appear in your app, re-deploy it.",
"Info".bold()
);
let should_redeploy = self.redeploy || {
if !self.non_interactive && self.from_file.is_some() {
let theme = ColorfulTheme::default();
dialoguer::Confirm::with_theme(&theme)
.with_prompt("Do you want to redeploy your app?")
.interact()?
} else {
false
}
};

if should_redeploy {
wasmer_api::query::redeploy_app_by_id(client, app_id).await?;
eprintln!("{} Deployment complete", "𖥔".yellow().bold());
} else {
eprintln!(
"{}: In order for secrets to appear in your app, re-deploy it.",
"Info".bold()
);
}
}

Ok(())
Expand Down

0 comments on commit d6ba243

Please sign in to comment.