use crate::cmd::AxCliCommand;
use ax_core::{
certs::{AppDomain, DeveloperCertificateInput, ManifestDeveloperCertificate},
crypto::{PrivateKey, PublicKey},
util::formats::{ActyxOSCode, ActyxOSResult, ActyxOSResultExt},
};
use futures::{stream::once, FutureExt, Stream};
#[derive(clap::Parser, Clone, Debug)]
pub struct DevCertOpts {
#[arg(long, short = 'A', env, hide_env_values = true)]
ax_secret_key: PrivateKey,
#[arg(long, short)]
dev_public_key: PublicKey,
#[arg(long, short)]
app_domains: Vec<AppDomain>,
}
pub struct UsersDevCert;
impl AxCliCommand for UsersDevCert {
type Opt = DevCertOpts;
type Output = String;
fn run(opts: Self::Opt) -> Box<dyn Stream<Item = ActyxOSResult<Self::Output>> + Unpin> {
Box::new(once(
async move {
let input = DeveloperCertificateInput::new(opts.dev_public_key, opts.app_domains);
let dev_cert = ManifestDeveloperCertificate::new(input, opts.ax_secret_key)
.ax_err(ActyxOSCode::ERR_INTERNAL_ERROR)?;
serde_json::to_string(&dev_cert).ax_err(ActyxOSCode::ERR_INTERNAL_ERROR)
}
.boxed(),
))
}
fn pretty(result: Self::Output) -> String {
result
}
}