You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-09 04:22:45 +03:00
Embed templates in binary & add command to export them
This commit is contained in:
@@ -27,12 +27,14 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilte
|
||||
|
||||
use self::{
|
||||
config::ConfigCommand, database::DatabaseCommand, manage::ManageCommand, server::ServerCommand,
|
||||
templates::TemplatesCommand,
|
||||
};
|
||||
|
||||
mod config;
|
||||
mod database;
|
||||
mod manage;
|
||||
mod server;
|
||||
mod templates;
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
enum Subcommand {
|
||||
@@ -47,6 +49,9 @@ enum Subcommand {
|
||||
|
||||
/// Manage the instance
|
||||
Manage(ManageCommand),
|
||||
|
||||
/// Templates-related commands
|
||||
Templates(TemplatesCommand),
|
||||
}
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
@@ -67,6 +72,7 @@ impl RootCommand {
|
||||
Some(S::Database(c)) => c.run(self).await,
|
||||
Some(S::Server(c)) => c.run(self).await,
|
||||
Some(S::Manage(c)) => c.run(self).await,
|
||||
Some(S::Templates(c)) => c.run(self).await,
|
||||
None => ServerCommand::default().run(self).await,
|
||||
}
|
||||
}
|
||||
|
@@ -49,7 +49,8 @@ impl ServerCommand {
|
||||
let pool = config.database.connect().await?;
|
||||
|
||||
// Load and compile the templates
|
||||
let templates = Templates::load().context("could not load templates")?;
|
||||
// TODO: custom template path from the config
|
||||
let templates = Templates::load(None, true).context("could not load templates")?;
|
||||
|
||||
// Start the server
|
||||
let root = mas_core::handlers::root(&pool, &templates, &config);
|
||||
|
64
crates/cli/src/templates.rs
Normal file
64
crates/cli/src/templates.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright 2021 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Clap;
|
||||
use mas_core::templates::Templates;
|
||||
|
||||
use super::RootCommand;
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
pub(super) struct TemplatesCommand {
|
||||
#[clap(subcommand)]
|
||||
subcommand: TemplatesSubcommand,
|
||||
}
|
||||
|
||||
#[derive(Clap, Debug)]
|
||||
enum TemplatesSubcommand {
|
||||
/// Save the builtin templates to a folder
|
||||
Save {
|
||||
/// Where the templates should be saved
|
||||
path: PathBuf,
|
||||
|
||||
/// Overwrite existing template files
|
||||
#[clap(long)]
|
||||
overwrite: bool,
|
||||
},
|
||||
|
||||
/// Check for template validity at given path.
|
||||
Check {
|
||||
/// Path where the templates are
|
||||
path: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl TemplatesCommand {
|
||||
pub async fn run(&self, _root: &RootCommand) -> anyhow::Result<()> {
|
||||
use TemplatesSubcommand as SC;
|
||||
match &self.subcommand {
|
||||
SC::Save { path, overwrite } => {
|
||||
Templates::save(path, *overwrite).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
SC::Check { path } => {
|
||||
Templates::load(Some(path.clone()), false)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user