Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/stakwork/sphinx-swarm
Browse files Browse the repository at this point in the history
  • Loading branch information
Evanfeenstra committed Oct 3, 2024
2 parents a7cb002 + bd4d330 commit d5200d8
Show file tree
Hide file tree
Showing 13 changed files with 270 additions and 73 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion app/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Sphinx Stack</title>
<link rel="stylesheet" href="g100.css" />
<script type="module" crossorigin src="/assets/index-4d51d08f.js"></script>
<script type="module" crossorigin src="/assets/index-ea82fb0b.js"></script>
<link rel="stylesheet" href="/assets/index-873385bf.css">
</head>
<body>
Expand Down
3 changes: 2 additions & 1 deletion app/src/api/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ export type Cmd =
| "StopChildSwarmContainers"
| "StartChildSwarmContainers"
| "UpdateChildSwarmContainers"
| "CreateNewEc2Instance";
| "CreateNewEc2Instance"
| "GetAwsInstanceTypes";

interface CmdData {
cmd: Cmd;
Expand Down
10 changes: 7 additions & 3 deletions app/src/api/swarm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,19 @@ export async function update_child_swarm_containers({
export async function create_new_swarm_ec2({
name,
vanity_address,
swarm_number,
instance_type,
}: {
vanity_address?: string;
name: string;
swarm_number: number;
instance_type: string;
}) {
return await swarmCmd("CreateNewEc2Instance", {
vanity_address,
name,
swarm_number,
instance_type,
});
}

export async function get_aws_instance_types() {
return await swarmCmd("GetAwsInstanceTypes");
}
1 change: 1 addition & 0 deletions app/src/components/SecondBrain/roles/setSuperAdmin.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
placeholder="Enter Admin Pubkey ..."
bind:value={superAdminPubkey}
onInput={handleAdminPubkeyInput}
isPubkey={true}
/>
</div>
<div class="submit_btn_container">
Expand Down
3 changes: 3 additions & 0 deletions app/src/components/SecondBrain/roles/userRecord.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@
placeholder="Paste Pubkey ..."
onInput={updateUserPubkey}
value={userpubkey}
isPubkey={true}
/>
<Select
value={role}
Expand Down Expand Up @@ -482,6 +483,7 @@
placeholder="Type Pubkey Here"
onInput={updateAdminPubkey}
value={adminpubkey}
isPubkey={true}
/>
<div class="edit_admin_btn_container">
<button on:click={closeEditAdminModal} class="edit_admin_cancel_btn"
Expand Down Expand Up @@ -574,6 +576,7 @@
placeholder="Paste Pubkey ..."
onInput={updateEditPubkey}
value={editPubkey}
isPubkey={true}
/>
<Select
value={editRole}
Expand Down
19 changes: 17 additions & 2 deletions app/src/components/input/input.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
export let placeholder = "Enter text";
export let onInput;
export let label;
export let isPubkey = false;
function splitPubkey(pubkey: string) {
if (pubkey.includes("_")) {
return pubkey.split("_")[0];
}
if (pubkey.includes(":")) {
return pubkey.split(":")[0];
}
return pubkey;
}
function handleInput(event) {
const inputValue = event.target.value;
onInput(inputValue);
let value = event.target.value;
if (isPubkey && value.length > 66) {
value = splitPubkey(value);
}
onInput(value);
}
</script>

Expand Down
3 changes: 2 additions & 1 deletion src/bin/super/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub enum SwarmCmd {
StartChildSwarmContainers(AccessNodesInfo),
UpdateChildSwarmContainers(AccessNodesInfo),
CreateNewEc2Instance(CreateEc2InstanceInfo),
GetAwsInstanceTypes,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -109,6 +110,6 @@ pub struct AccessNodesInfo {
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct CreateEc2InstanceInfo {
pub name: String,
pub swarm_number: i64,
pub vanity_address: Option<String>,
pub instance_type: String,
}
13 changes: 7 additions & 6 deletions src/bin/super/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use sphinx_swarm::utils::getenv;
use state::RemoteStack;
use state::Super;
use util::{
accessing_child_container_controller, add_new_swarm_details, get_child_swarm_config,
get_child_swarm_containers,
accessing_child_container_controller, add_new_swarm_details, get_aws_instance_types,
get_child_swarm_config, get_child_swarm_containers,
};

use crate::checker::swarm_checker;
Expand Down Expand Up @@ -296,16 +296,17 @@ pub async fn super_handle(

Some(serde_json::to_string(&res)?)
}
SwarmCmd::GetAwsInstanceTypes => {
let res = get_aws_instance_types();
Some(serde_json::to_string(&res)?)
}
SwarmCmd::CreateNewEc2Instance(info) => {
let res: SuperSwarmResponse;
match create_swarm_ec2(&info).await {
Ok(_) => {
res = SuperSwarmResponse {
success: true,
message: format!(
"Swarm{}.sphinx.chat was created successfully",
&info.swarm_number
),
message: format!("{} was created successfully", &info.name.clone()),
data: None,
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/bin/super/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ pub struct RemoteStack {
pub default_host: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
pub struct AwsInstanceType {
pub name: String,
pub value: String,
}

#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Default)]
pub struct BotCred {
pub bot_id: String,
Expand Down
Loading

0 comments on commit d5200d8

Please sign in to comment.