Skip to content

Commit

Permalink
WIP fixes for clients (#203)
Browse files Browse the repository at this point in the history
Co-authored-by: kassem <[email protected]>
  • Loading branch information
ashraffouda and 0oM4R authored Sep 4, 2023
1 parent c68f99b commit c49454c
Show file tree
Hide file tree
Showing 33 changed files with 227 additions and 132 deletions.
2 changes: 1 addition & 1 deletion lib/threelang/nostr/channel.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module nostr

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }

fn (mut n NostrHandler) channel(action Action) ! {
match action.name {
Expand Down
2 changes: 1 addition & 1 deletion lib/threelang/nostr/direct.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module nostr

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }

fn (mut n NostrHandler) direct(action Action) ! {
match action.name {
Expand Down
2 changes: 1 addition & 1 deletion lib/threelang/nostr/handler.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module nostr

import threefoldtech.threebot.nostr as nostr_client { NostrClient }
import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }
import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient }
import log { Logger }

Expand Down
2 changes: 1 addition & 1 deletion lib/threelang/stellar/account.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module stellar

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }

fn (mut h StellarHandler) account(action Action) ! {
match action.name {
Expand Down
2 changes: 1 addition & 1 deletion lib/threelang/stellar/handler.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module stellar

import threefoldtech.threebot.stellar as stellar_client { StellarClient }
import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }
import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient }
import log { Logger }

Expand Down
35 changes: 35 additions & 0 deletions manual/src/threelang/examples/tfgrid/network.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Machines Example

- This example deployes, gets, udpates, and deletes a network of machines on the tfgrid.

```md
!!tfgrid.core.login
mnemonic: '<MNEMONICS>'
network: dev

!!tfgrid.sshkeys.new
name: SSH_KEY
ssh_key: ''

!!tfgrid.network.create
network: skynet
capacity: small
times: 2
gateway: yes
add_wireguard_access: yes
disk_size: 10GB

!!tfgrid.network.create
network: skynet
capacity: medium

!!tfgrid.network.remove
network: skynet
machine: ewbjpuqe

!!tfgrid.network.get
network: skynet

!!tfgrid.network.delete
network: skynet
```
4 changes: 2 additions & 2 deletions web3gw/client/threelang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
## Development

- To add new books to the parser, follow these instructions:

- Create a new module inside the threelang folder
- Inside the new module, create a new handler for this book.
- While creating a new Runner, the new handler should be initialized, then saved to the Runner's state.
- The new handler should have its actions exposed in the Runner.run() method
- The new handler must implement a handle_action method.
- The handle_action method receives an actionparser.Action, and executes the action however it sees fit.
- Handlers are responsible for logging their output, if any.
- To add docuemntation on how to use the new book, create a new folder [here](../../manual/src/threelang/) with the book's name, and add all needed documentation files in this folder.
- To add documentation on how to use the new book, create a new folder [here](../../manual/src/threelang/) with the book's name, and add all needed documentation files in this folder.
30 changes: 15 additions & 15 deletions web3gw/client/threelang/factory.v
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
module threelang

import log
import freeflowuniverse.crystallib.actionsparser
import freeflowuniverse.crystallib.baobab.actions
import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient }
import threefoldtech.threebot.tfgrid as tfgrid_client
import threefoldtech.threebot.tfchain as tfchain_client
import threefoldtech.threebot.stellar as stellar_client
import threefoldtech.threebot.eth as eth_client
import threefoldtech.threebot.btc as btc_client
import threefoldtech.threebot.threelang.tfgrid { TFGridHandler }
import threefoldtech.threebot.threelang.web3gw { Web3GWHandler }
import threefoldtech.threebot.threelang.clients { Clients }
import threefoldtech.threebot.threelang.stellar { StellarHandler }
import threefoldtech.web3gw.tfgrid as tfgrid_client
import threefoldtech.web3gw.tfchain as tfchain_client
import threefoldtech.web3gw.stellar as stellar_client
import threefoldtech.web3gw.eth as eth_client
import threefoldtech.web3gw.btc as btc_client
import threefoldtech.web3gw.threelang.tfgrid { TFGridHandler }
import threefoldtech.web3gw.threelang.web3gw { Web3GWHandler }
import threefoldtech.web3gw.threelang.clients { Clients }
import threefoldtech.web3gw.threelang.stellar { StellarHandler }

const (
tfgrid_book = 'tfgrid'
web3gw_book = 'web3gw'
tfgrid_book = 'tfgrid'
web3gw_book = 'web3gw'
stellar_book = 'stellar'
)

Expand All @@ -37,7 +37,7 @@ pub mut:
}

pub fn new(args RunnerArgs, debug_log bool) !Runner {
mut ap := actionsparser.new(path: args.path, defaultbook: 'aaa')!
mut ap := actions.new(path: args.path)!

mut logger := log.Logger(&log.Log{
level: if debug_log { .debug } else { .info }
Expand Down Expand Up @@ -66,8 +66,8 @@ pub fn new(args RunnerArgs, debug_log bool) !Runner {
return runner
}

pub fn (mut r Runner) run(mut action_parser actionsparser.ActionsParser) ! {
for action in action_parser.actions {
pub fn (mut r Runner) run(mut acs actions.Actions) ! {
for action in acs.actions {
match action.book {
threelang.tfgrid_book {
r.tfgrid_handler.handle_action(action)!
Expand Down
2 changes: 1 addition & 1 deletion web3gw/client/threelang/stellar/account.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module stellar

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }

fn (mut h StellarHandler) account(action Action) ! {
match action.name {
Expand Down
2 changes: 1 addition & 1 deletion web3gw/client/threelang/stellar/handler.v
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module stellar

import threefoldtech.web3gw.stellar as stellar_client { StellarClient }
import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }
import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient }
import log { Logger }

Expand Down
17 changes: 9 additions & 8 deletions web3gw/client/threelang/tfgrid/contracts.v
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
module tfgrid

import freeflowuniverse.crystallib.actionsparser { Action }
import threefoldtech.web3gw.explorer { ContractFilter, ContractsRequestParams, Limit }
import freeflowuniverse.crystallib.baobab.actions { Action }
import threefoldtech.web3gw.tfgrid as tfgrid_client { ContractFilter, FindContracts, Limit }

pub fn (mut h TFGridHandler) contracts(action Action) ! {
match action.name {
'get' {
mnemonics := action.params.get_default('mnemonics', '')!
network := action.params.get_default('network', 'main')!
h.explorer.load(network)!

h.tfgrid.load(
mnemonic: mnemonics
network: network
)!
mut filter := ContractFilter{}
if action.params.exists('contract_id') {
filter.contract_id = action.params.get_u64('contract_id')!
Expand Down Expand Up @@ -41,19 +44,17 @@ pub fn (mut h TFGridHandler) contracts(action Action) ! {
page := action.params.get_u64_default('page', 1)!
size := action.params.get_u64_default('size', 50)!
randomize := action.params.get_default_false('randomize')
count := action.params.get_default_false('count')

req := ContractsRequestParams{
req := FindContracts{
filters: filter
pagination: Limit{
page: page
size: size
randomize: randomize
ret_count: count
}
}

res := h.explorer.contracts(req)!
res := h.tfgrid.find_contracts(req)!
h.logger.info('contracts: ${res}')
}
else {
Expand Down
2 changes: 1 addition & 1 deletion web3gw/client/threelang/tfgrid/core.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module tfgrid

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }

fn (mut t TFGridHandler) core(action Action) ! {
match action.name {
Expand Down
9 changes: 4 additions & 5 deletions web3gw/client/threelang/tfgrid/discourse.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module tfgrid

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }
import rand

fn (mut t TFGridHandler) discourse(action Action) ! {
mut discourse_client := t.tfgrid.applications().discourse()
match action.name {
'create' {
name := action.params.get_default('name', rand.string(10).to_lower())!
Expand All @@ -19,7 +18,7 @@ fn (mut t TFGridHandler) discourse(action Action) ! {
smtp_password := action.params.get_default('smtp_password', '')!
smtp_tls := action.params.get_default_false('smtp_tls')

deploy_res := discourse_client.deploy(
deploy_res := t.tfgrid.deploy_discourse(
name: name
farm_id: u64(farm_id)
capacity: capacity
Expand All @@ -37,14 +36,14 @@ fn (mut t TFGridHandler) discourse(action Action) ! {
'get' {
name := action.params.get('name')!

get_res := discourse_client.get(name)!
get_res := t.tfgrid.get_discourse_deployment(name)!

t.logger.info('${get_res}')
}
'delete' {
name := action.params.get('name')!

discourse_client.delete(name) or {
t.tfgrid.cancel_discourse_deployment(name) or {
return error('failed to delete discourse instance: ${err}')
}
}
Expand Down
13 changes: 4 additions & 9 deletions web3gw/client/threelang/tfgrid/farms.v
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
module tfgrid

import freeflowuniverse.crystallib.actionsparser { Action }
import threefoldtech.web3gw.explorer { FarmFilter, FarmsRequestParams, Limit }
import freeflowuniverse.crystallib.baobab.actions { Action }
import threefoldtech.web3gw.tfgrid { FarmFilter, FindFarms, Limit }

pub fn (mut h TFGridHandler) farms(action Action) ! {
match action.name {
'get' {
network := action.params.get_default('network', 'main')!
h.explorer.load(network)!

mut filter := FarmFilter{}
if action.params.exists('free_ips') {
filter.free_ips = action.params.get_u64('free_ips')!
Expand Down Expand Up @@ -44,19 +41,17 @@ pub fn (mut h TFGridHandler) farms(action Action) ! {
page := action.params.get_u64_default('page', 1)!
size := action.params.get_u64_default('size', 50)!
randomize := action.params.get_default_false('randomize')
count := action.params.get_default_false('count')

req := FarmsRequestParams{
req := FindFarms{
filters: filter
pagination: Limit{
page: page
size: size
randomize: randomize
ret_count: count
}
}

res := h.explorer.farms(req)!
res := h.tfgrid.find_farms(req)!
h.logger.info('farms: ${res}')
}
else {
Expand Down
9 changes: 4 additions & 5 deletions web3gw/client/threelang/tfgrid/funkwhale.v
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module tfgrid

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }
import rand

fn (mut t TFGridHandler) funkwhale(action Action) ! {
mut funkwhale_client := t.tfgrid.applications().funkwhale()
match action.name {
'create' {
name := action.params.get_default('name', rand.string(10).to_lower())!
Expand All @@ -16,7 +15,7 @@ fn (mut t TFGridHandler) funkwhale(action Action) ! {
admin_username := action.params.get_default('admin_username', '')!
admin_password := action.params.get_default('admin_password', '')!

deploy_res := funkwhale_client.deploy(
deploy_res := t.tfgrid.deploy_funkwhale(
name: name
farm_id: u64(farm_id)
capacity: capacity
Expand All @@ -31,14 +30,14 @@ fn (mut t TFGridHandler) funkwhale(action Action) ! {
'get' {
name := action.params.get('name')!

get_res := funkwhale_client.get(name)!
get_res :=t.tfgrid.get_funkwhale_deployment(name)!

t.logger.info('${get_res}')
}
'delete' {
name := action.params.get('name')!

funkwhale_client.delete(name) or {
t.tfgrid.cancel_funkwhale_deployment(name) or {
return error('failed to delete funkwhale instance: ${err}')
}
}
Expand Down
8 changes: 4 additions & 4 deletions web3gw/client/threelang/tfgrid/gateway_fqdn.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module tfgrid

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }
import threefoldtech.web3gw.tfgrid as tfgrid_client { GatewayFQDN }
import rand

Expand All @@ -13,7 +13,7 @@ fn (mut t TFGridHandler) gateway_fqdn(action Action) ! {
backend := action.params.get('backend')!
fqdn := action.params.get('fqdn')!

gw_deploy := t.tfgrid.gateways_deploy_fqdn(GatewayFQDN{
gw_deploy := t.tfgrid.deploy_gateway_fqdn(GatewayFQDN{
name: name
node_id: u32(node_id)
tls_passthrough: tls_passthrough
Expand All @@ -25,11 +25,11 @@ fn (mut t TFGridHandler) gateway_fqdn(action Action) ! {
}
'delete' {
name := action.params.get('name')!
t.tfgrid.gateways_delete_fqdn(name)!
t.tfgrid.cancel_gateway_fqdn(name)!
}
'get' {
name := action.params.get('name')!
gw_get := t.tfgrid.gateways_get_fqdn(name)!
gw_get := t.tfgrid.get_gateway_fqdn(name)!

t.logger.info('${gw_get}')
}
Expand Down
8 changes: 4 additions & 4 deletions web3gw/client/threelang/tfgrid/gateway_name.v
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module tfgrid

import freeflowuniverse.crystallib.actionsparser { Action }
import freeflowuniverse.crystallib.baobab.actions { Action }
import threefoldtech.web3gw.tfgrid as tfgrid_client { GatewayName }
import rand

Expand All @@ -12,7 +12,7 @@ fn (mut t TFGridHandler) gateway_name(action Action) ! {
tls_passthrough := action.params.get_default_false('tls_passthrough')
backend := action.params.get('backend')!

gw_deploy := t.tfgrid.gateways_deploy_name(GatewayName{
gw_deploy := t.tfgrid.deploy_gateway_name(GatewayName{
name: name
node_id: u32(node_id)
tls_passthrough: tls_passthrough
Expand All @@ -23,11 +23,11 @@ fn (mut t TFGridHandler) gateway_name(action Action) ! {
}
'delete' {
name := action.params.get('name')!
t.tfgrid.gateways_delete_name(name)!
t.tfgrid.cancel_gateway_name(name)!
}
'get' {
name := action.params.get('name')!
gw_get := t.tfgrid.gateways_get_name(name)!
gw_get := t.tfgrid.get_gateway_name(name)!

t.logger.info('${gw_get}')
}
Expand Down
Loading

0 comments on commit c49454c

Please sign in to comment.