Skip to content

Commit 5aefdcd

Browse files
committed
feat(sdk): serialize (wip)
1 parent d6c5bc7 commit 5aefdcd

File tree

6 files changed

+44
-21
lines changed

6 files changed

+44
-21
lines changed

meta-cli/src/cli/deploy.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::path::{Path, PathBuf};
55
use std::sync::{Arc, Mutex};
66

77
use super::{Action, CommonArgs, GenArgs};
8+
use crate::com::store::{Command, ServerStore};
89
use crate::config::Config;
910
use crate::deploy::actors;
1011
use crate::deploy::actors::console::{Console, ConsoleActor};
@@ -143,6 +144,12 @@ impl Action for DeploySubcommand {
143144
if !self.options.allow_dirty {
144145
let repo = git2::Repository::discover(&deploy.config.base_dir).ok();
145146

147+
// Hint the server what state we are globally in
148+
ServerStore::with(
149+
Some(Command::Deploy),
150+
Some(deploy.config.as_ref().to_owned()),
151+
);
152+
146153
if let Some(repo) = repo {
147154
let dirty = repo.statuses(None)?.iter().any(|s| {
148155
// git2::Status::CURRENT.bits() == 0
@@ -310,6 +317,8 @@ mod watch_mode {
310317
let secrets =
311318
lade_sdk::hydrate(deploy.node.env.clone(), deploy.base_dir.to_path_buf()).await?;
312319

320+
ServerStore::set_secrets(secrets.clone());
321+
313322
let (loader_event_tx, loader_event_rx) = mpsc::unbounded_channel();
314323

315324
let loader = LoaderActor::new(

meta-cli/src/cli/serialize.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,6 @@ impl Action for Serialize {
143143

144144
impl Serialize {
145145
async fn write(&self, contents: &str) -> Result<()> {
146-
println!("Output {:?}", contents);
147-
148146
if let Some(path) = self.out.as_ref() {
149147
tokio::fs::OpenOptions::new()
150148
.truncate(true)

meta-cli/src/cli/undeploy.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
use crate::config::Config;
4+
use crate::{
5+
com::store::{Command, ServerStore},
6+
config::Config,
7+
};
58
use anyhow::Result;
69
use async_trait::async_trait;
710
use clap::Parser;
@@ -29,8 +32,11 @@ impl Action for Undeploy {
2932
let config = Config::load_or_find(config_path, &dir)?;
3033
let node_config = config.node(&self.node, &self.target);
3134
let node = node_config.build(&dir).await?;
32-
node.try_undeploy(&self.typegraphs).await?;
3335

36+
// Hint the server what state we are globally in
37+
ServerStore::with(Some(Command::Undeploy), Some(config.clone()));
38+
39+
node.try_undeploy(&self.typegraphs).await?;
3440
Ok(())
3541
}
3642
}

meta-cli/src/com/server.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33

44
use crate::com::store::ServerStore;
55
use actix_web::{get, post, App, HttpResponse, HttpServer, Responder};
6+
use lazy_static::lazy_static;
67
use reqwest::StatusCode;
78
use serde::Serialize;
89
use serde_json::{json, Value};
910

11+
lazy_static! {
12+
pub static ref SERVER_PORT: u16 = 1234;
13+
}
14+
1015
#[derive(Serialize)]
1116
struct ResponseSuccess {
1217
data: Value,
@@ -21,27 +26,21 @@ struct ResponseError {
2126
async fn config() -> impl Responder {
2227
match ServerStore::get_config() {
2328
Some(config) => {
24-
let endpoints = config
25-
.typegates
26-
.iter()
27-
.map(|(k, v)| serde_json::to_value((k, v)).unwrap())
28-
.collect::<Vec<_>>();
29-
3029
let data = json!({
31-
"endpoints": endpoints,
30+
"typegates": config.typegates,
31+
"secrets": ServerStore::get_secrets(),
3232
"artifactsConfig": json!({
3333
"dir": config.base_dir.display().to_string(),
34-
"prismaMigration": json!({
34+
"prismaMigration": {
35+
// TODO:
3536
"migrationDir": ".",
36-
"create": true,
37-
"action": json!({
37+
"action": {
38+
// TODO:
3839
"create": true,
3940
"reset": false,
40-
}),
41-
}),
41+
},
42+
},
4243
}),
43-
"secrets": json!({}),
44-
"cliVersion": ""
4544
});
4645

4746
HttpResponse::Ok()
@@ -85,7 +84,7 @@ pub async fn spawn_server() -> std::io::Result<()> {
8584
.service(command)
8685
.service(response)
8786
})
88-
.bind(("127.0.0.1", 1234))?
87+
.bind(("127.0.0.1", SERVER_PORT.to_owned()))?
8988
.run()
9089
.await
9190
}

meta-cli/src/com/store.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use lazy_static::lazy_static;
66
use serde::Serialize;
77
use std::{
88
borrow::{Borrow, BorrowMut},
9+
collections::HashMap,
910
sync::Mutex,
1011
};
1112

@@ -26,6 +27,7 @@ fn with_store_mut<T, F: FnOnce(&mut ServerStore) -> T>(f: F) -> T {
2627

2728
#[allow(dead_code)]
2829
#[derive(Clone, Debug, Serialize)]
30+
#[serde(rename_all = "lowercase")]
2931
pub enum Command {
3032
Deploy,
3133
Undeploy,
@@ -36,6 +38,7 @@ pub enum Command {
3638
pub struct ServerStore {
3739
config: Option<Config>,
3840
command: Option<Command>,
41+
secrets: HashMap<String, String>,
3942
}
4043

4144
#[allow(dead_code)]
@@ -58,4 +61,12 @@ impl ServerStore {
5861
pub fn get_command() -> Option<Command> {
5962
with_store(|s| s.command.clone())
6063
}
64+
65+
pub fn set_secrets(secrets: HashMap<String, String>) {
66+
with_store_mut(|s| s.secrets = secrets)
67+
}
68+
69+
pub fn get_secrets() -> HashMap<String, String> {
70+
with_store(|s| s.secrets.clone())
71+
}
6172
}

meta-cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use clap::Parser;
2222
use cli::upgrade::upgrade_check;
2323
use cli::Action;
2424
use cli::Args;
25-
use com::server::spawn_server;
25+
use com::server::{spawn_server, SERVER_PORT};
2626
use futures::try_join;
2727
use futures::TryFutureExt;
2828
use log::{error, warn};
@@ -33,7 +33,7 @@ shadow!(build);
3333
fn main() -> Result<()> {
3434
setup_panic_hook();
3535
logger::init();
36-
std::env::set_var("META_CLI_SERVER_PORT", "1234");
36+
std::env::set_var("META_CLI_SERVER_PORT", SERVER_PORT.to_string());
3737

3838
let _ = actix::System::with_tokio_rt(|| {
3939
tokio::runtime::Builder::new_multi_thread()

0 commit comments

Comments
 (0)