...
This commit is contained in:
@@ -3,9 +3,15 @@
|
||||
import freeflowuniverse.herolib.core.generator.generic as generator
|
||||
import freeflowuniverse.herolib.core.pathlib
|
||||
|
||||
// mut args := generator.GeneratorArgs{
|
||||
// path: '~/code/github/freeflowuniverse/herolib/lib/installers'
|
||||
// force: true
|
||||
// }
|
||||
|
||||
mut args := generator.GeneratorArgs{
|
||||
path: '~/code/github/freeflowuniverse/herolib/lib/installers'
|
||||
path: '~/code/github/freeflowuniverse/herolib/lib'
|
||||
force: true
|
||||
}
|
||||
|
||||
|
||||
generator.scan(args)!
|
||||
|
||||
@@ -19,9 +19,6 @@ pub mut:
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = ipapi_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
@@ -29,56 +26,65 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&IPApi {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := IPApi{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in ipapi_global {
|
||||
if args.name == 'default' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
config_save(args)!
|
||||
}
|
||||
}
|
||||
config_load(args)!
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('ipapi', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return ipapi_global[args.name] or {
|
||||
println(ipapi_global)
|
||||
panic('could not get config for ipapi with name:${args.name}')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for ipapi with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
// register the config for the future
|
||||
pub fn set(o IPApi) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('ipapi', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('ipapi', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('ipapi', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
context.hero_config_delete('ipapi', args.name)!
|
||||
if args.name in ipapi_global {
|
||||
// del ipapi_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('ipapi', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o IPApi) ! {
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o IPApi) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
ipapi_global[o.name] = &o2
|
||||
ipapi_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'ipapi.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,3 +93,10 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
pub fn switch(name string) {
|
||||
ipapi_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ module jina
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
jina_global map[string]&Jina
|
||||
@@ -28,7 +28,9 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
pub fn get(args_ ArgsGet) !&Jina {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := Jina{}
|
||||
mut obj := Jina{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in jina_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
@@ -76,9 +78,7 @@ fn set_in_mem(o Jina) ! {
|
||||
jina_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'jina.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
|
||||
102
lib/clients/livekit/livekit_factory_.v
Normal file
102
lib/clients/livekit/livekit_factory_.v
Normal file
@@ -0,0 +1,102 @@
|
||||
module livekit
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
livekit_global map[string]&LivekitClient
|
||||
livekit_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&LivekitClient {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := LivekitClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in livekit_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('livekit', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return livekit_global[args.name] or {
|
||||
println(livekit_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for livekit with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o LivekitClient) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('livekit', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('livekit', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('livekit', args.name)!
|
||||
if args.name in livekit_global {
|
||||
// del livekit_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o LivekitClient) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
livekit_global[o.name] = &o2
|
||||
livekit_default = o.name
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut install_actions := plbook.find(filter: 'livekit.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for livekit
|
||||
pub fn switch(name string) {
|
||||
livekit_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
42
lib/clients/livekit/livekit_model.v
Normal file
42
lib/clients/livekit/livekit_model.v
Normal file
@@ -0,0 +1,42 @@
|
||||
module livekit
|
||||
|
||||
import freeflowuniverse.herolib.data.paramsparser
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
import os
|
||||
|
||||
pub const version = '0.0.0'
|
||||
const singleton = false
|
||||
const default = true
|
||||
|
||||
// THIS THE THE SOURCE OF THE INFORMATION OF THIS FILE, HERE WE HAVE THE CONFIG OBJECT CONFIGURED AND MODELLED
|
||||
|
||||
@[heap]
|
||||
pub struct LivekitClient {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
mail_from string
|
||||
mail_password string @[secret]
|
||||
mail_port int
|
||||
mail_server string
|
||||
mail_username string
|
||||
}
|
||||
|
||||
// your checking & initialization code if needed
|
||||
fn obj_init(mycfg_ LivekitClient) !LivekitClient {
|
||||
mut mycfg := mycfg_
|
||||
if mycfg.password == '' && mycfg.secret == '' {
|
||||
return error('password or secret needs to be filled in for ${mycfg.name}')
|
||||
}
|
||||
return mycfg
|
||||
}
|
||||
|
||||
/////////////NORMALLY NO NEED TO TOUCH
|
||||
|
||||
pub fn heroscript_dumps(obj LivekitClient) !string {
|
||||
return encoderhero.encode[LivekitClient](obj)!
|
||||
}
|
||||
|
||||
pub fn heroscript_loads(heroscript string) !LivekitClient {
|
||||
mut obj := encoderhero.decode[LivekitClient](heroscript)!
|
||||
return obj
|
||||
}
|
||||
@@ -19,9 +19,6 @@ pub mut:
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = mailclient_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
@@ -29,12 +26,19 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&MailClient {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := MailClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in mailclient_global {
|
||||
if !config_exists(args) {
|
||||
config_save(args)!
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('mailclient', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
config_load(args)!
|
||||
}
|
||||
return mailclient_global[args.name] or {
|
||||
println(mailclient_global)
|
||||
@@ -43,46 +47,44 @@ pub fn get(args_ ArgsGet) !&MailClient {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn config_exists(args_ ArgsGet) bool {
|
||||
// register the config for the future
|
||||
pub fn set(o MailClient) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('mailclient', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('mailclient', args.name)
|
||||
}
|
||||
|
||||
pub fn config_load(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('mailclient', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
pub fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('mailclient', args.name, heroscript_default(instance: args.name)!)!
|
||||
}
|
||||
|
||||
pub fn config_delete(args_ ArgsGet) ! {
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('mailclient', args.name)!
|
||||
if args.name in mailclient_global {
|
||||
// del mailclient_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
fn set(o MailClient) ! {
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o MailClient) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
mailclient_global[o.name] = &o2
|
||||
mailclient_default = o.name
|
||||
}
|
||||
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'mailclient.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ module meilisearch
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
|
||||
__global (
|
||||
meilisearch_global map[string]&MeilisearchClient
|
||||
@@ -19,75 +18,85 @@ pub mut:
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut model := args_
|
||||
if model.name == '' {
|
||||
model.name = meilisearch_default
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
if model.name == '' {
|
||||
model.name = 'default'
|
||||
}
|
||||
return model
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&MeilisearchClient {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := MeilisearchClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in meilisearch_global {
|
||||
if args.name == 'default' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
mut context := base.context() or { panic('bug') }
|
||||
context.hero_config_set('meilisearch', model.name, heroscript_default()!)!
|
||||
}
|
||||
}
|
||||
load(args)!
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('meilisearch', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return meilisearch_global[args.name] or {
|
||||
println(meilisearch_global)
|
||||
panic('could not get config for ${args.name} with name:${model.name}')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for meilisearch with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
// set the model in mem and the config on the filesystem
|
||||
// register the config for the future
|
||||
pub fn set(o MeilisearchClient) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('meilisearch', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('meilisearch', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('meilisearch', args.name)!
|
||||
if args.name in meilisearch_global {
|
||||
// del meilisearch_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o MeilisearchClient) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
meilisearch_global[o.name] = &o2
|
||||
meilisearch_default = o.name
|
||||
}
|
||||
|
||||
// check we find the config on the filesystem
|
||||
pub fn exists(args_ ArgsGet) bool {
|
||||
mut model := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('meilisearch', model.name)
|
||||
}
|
||||
|
||||
// load the config error if it doesn't exist
|
||||
pub fn load(args_ ArgsGet) ! {
|
||||
mut model := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('meilisearch', model.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
// save the config to the filesystem in the context
|
||||
pub fn save(o MeilisearchClient) ! {
|
||||
mut context := base.context()!
|
||||
heroscript := encoderhero.encode[MeilisearchClient](o)!
|
||||
context.hero_config_set('meilisearch', model.name, heroscript)!
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut configure_actions := plbook.find(filter: 'meilisearch.configure')!
|
||||
if configure_actions.len > 0 {
|
||||
for config_action in configure_actions {
|
||||
mut p := config_action.params
|
||||
mycfg := cfg_play(p)!
|
||||
console.print_debug('install action meilisearch.configure\n${mycfg}')
|
||||
set(mycfg)!
|
||||
save(mycfg)!
|
||||
mut install_actions := plbook.find(filter: 'meilisearch.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for meilisearch
|
||||
pub fn switch(name string) {
|
||||
meilisearch_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ module mycelium
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
mycelium_global map[string]&Mycelium
|
||||
@@ -27,7 +28,9 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
pub fn get(args_ ArgsGet) !&Mycelium {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := Mycelium{}
|
||||
mut obj := Mycelium{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in mycelium_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
@@ -75,9 +78,7 @@ fn set_in_mem(o Mycelium) ! {
|
||||
mycelium_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'mycelium.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
|
||||
@@ -78,9 +78,7 @@ fn set_in_mem(o MyceliumRPC) ! {
|
||||
mycelium_rpc_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'mycelium_rpc.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
|
||||
@@ -2,7 +2,7 @@ module openai
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
openai_global map[string]&OpenAI
|
||||
@@ -43,7 +43,7 @@ pub fn get(args_ ArgsGet) !&OpenAI {
|
||||
return openai_global[args.name] or {
|
||||
println(openai_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for openai with name, is bug, was for: ${args.name}')
|
||||
panic('could not get config for openai with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ fn set_in_mem(o OpenAI) ! {
|
||||
openai_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut install_actions := plbook.find(filter: 'openai.configure')!
|
||||
if install_actions.len > 0 {
|
||||
|
||||
@@ -3,8 +3,6 @@ module postgresql_client
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.core
|
||||
import freeflowuniverse.herolib.data.encoderhero
|
||||
|
||||
__global (
|
||||
postgresql_client_global map[string]&PostgresClient
|
||||
@@ -20,75 +18,85 @@ pub mut:
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut model := args_
|
||||
if model.name == '' {
|
||||
model.name = postgresql_client_default
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
if model.name == '' {
|
||||
model.name = 'default'
|
||||
}
|
||||
return model
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&PostgresClient {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := PostgresClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in postgresql_client_global {
|
||||
if args.name == 'default' {
|
||||
if !exists(args)! {
|
||||
if default {
|
||||
mut context := base.context() or { panic('bug') }
|
||||
context.hero_config_set('postgresql_client', args.name, heroscript_default()!)!
|
||||
}
|
||||
}
|
||||
load(args)!
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('postgresql_client', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return postgresql_client_global[args.name] or {
|
||||
println(postgresql_client_global)
|
||||
panic('could not get config for ${args.name}.')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for postgresql_client with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
// set the model in mem and the config on the filesystem
|
||||
// register the config for the future
|
||||
pub fn set(o PostgresClient) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('postgresql_client', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('postgresql_client', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('postgresql_client', args.name)!
|
||||
if args.name in postgresql_client_global {
|
||||
// del postgresql_client_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o PostgresClient) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
postgresql_client_global[o.name] = &o2
|
||||
postgresql_client_default = o.name
|
||||
}
|
||||
|
||||
// check we find the config on the filesystem
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut model := args_get(args_)
|
||||
mut context := base.context()!
|
||||
return context.hero_config_exists('postgresql_client', model.name)
|
||||
}
|
||||
|
||||
// load the config error if it doesn't exist
|
||||
pub fn load(args_ ArgsGet) ! {
|
||||
mut model := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('postgresql_client', model.name)!
|
||||
play(heroscript: heroscript)!
|
||||
}
|
||||
|
||||
// save the config to the filesystem in the context
|
||||
pub fn save(o PostgresClient) ! {
|
||||
mut context := base.context()!
|
||||
heroscript := encoderhero.encode[PostgresClient](o)!
|
||||
context.hero_config_set('postgresql_client', o.name, heroscript)!
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut configure_actions := plbook.find(filter: 'postgresql_client.configure')!
|
||||
if configure_actions.len > 0 {
|
||||
for config_action in configure_actions {
|
||||
mut p := config_action.params
|
||||
mycfg := cfg_play(p)!
|
||||
console.print_debug('install action postgresql_client.configure\n${mycfg}')
|
||||
set(mycfg)!
|
||||
save(mycfg)!
|
||||
mut install_actions := plbook.find(filter: 'postgresql_client.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for postgresql_client
|
||||
pub fn switch(name string) {
|
||||
postgresql_client_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ module qdrant
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
// import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
qdrant_global map[string]&QDrantClient
|
||||
@@ -28,7 +28,9 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
pub fn get(args_ ArgsGet) !&QDrantClient {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := QDrantClient{}
|
||||
mut obj := QDrantClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in qdrant_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
@@ -77,7 +79,6 @@ fn set_in_mem(o QDrantClient) ! {
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'qdrant.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
|
||||
@@ -2,6 +2,7 @@ module rclone
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
rclone_global map[string]&RCloneClient
|
||||
@@ -13,14 +14,11 @@ __global (
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = rclone_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
@@ -28,53 +26,65 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&RCloneClient {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := RCloneClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in rclone_global {
|
||||
if !config_exists() {
|
||||
if default {
|
||||
config_save()!
|
||||
}
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('rclone', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
config_load()!
|
||||
}
|
||||
return rclone_global[args.name] or {
|
||||
println(rclone_global)
|
||||
panic('bug in get from factory: ')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for rclone with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
// register the config for the future
|
||||
pub fn set(o RCloneClient) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('rclone', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('rclone', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('rclone', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
context.hero_config_delete('rclone', args.name)!
|
||||
if args.name in rclone_global {
|
||||
// del rclone_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('rclone', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o RCloneClient) ! {
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o RCloneClient) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
rclone_global['default'] = &o2
|
||||
rclone_global[o.name] = &o2
|
||||
rclone_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'rclone.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,3 +93,10 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
pub fn switch(name string) {
|
||||
rclone_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ pub mut:
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = runpod_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
@@ -29,56 +26,65 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&RunPod {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := RunPod{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in runpod_global {
|
||||
if args.name == 'default' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
config_save(args)!
|
||||
}
|
||||
}
|
||||
config_load(args)!
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('runpod', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return runpod_global[args.name] or {
|
||||
println(runpod_global)
|
||||
panic('could not get config for runpod with name:${args.name}')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for runpod with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
// register the config for the future
|
||||
pub fn set(o RunPod) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('runpod', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('runpod', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('runpod', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
context.hero_config_delete('runpod', args.name)!
|
||||
if args.name in runpod_global {
|
||||
// del runpod_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('runpod', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o RunPod) ! {
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o RunPod) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
runpod_global[o.name] = &o2
|
||||
runpod_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'runpod.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,3 +93,10 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
pub fn switch(name string) {
|
||||
runpod_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -10,3 +10,93 @@ __global (
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&SendGrid {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := SendGrid{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in sendgrid_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('sendgrid', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return sendgrid_global[args.name] or {
|
||||
println(sendgrid_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for sendgrid with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o SendGrid) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('sendgrid', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('sendgrid', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('sendgrid', args.name)!
|
||||
if args.name in sendgrid_global {
|
||||
// del sendgrid_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o SendGrid) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
sendgrid_global[o.name] = &o2
|
||||
sendgrid_default = o.name
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut install_actions := plbook.find(filter: 'sendgrid.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for sendgrid
|
||||
pub fn switch(name string) {
|
||||
sendgrid_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -19,9 +19,6 @@ pub mut:
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = vastai_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
@@ -29,56 +26,65 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&VastAI {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := VastAI{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in vastai_global {
|
||||
if args.name == 'default' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
config_save(args)!
|
||||
}
|
||||
}
|
||||
config_load(args)!
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('vastai', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return vastai_global[args.name] or {
|
||||
println(vastai_global)
|
||||
panic('could not get config for vastai with name:${args.name}')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for vastai with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
// register the config for the future
|
||||
pub fn set(o VastAI) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('vastai', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('vastai', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('vastai', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
context.hero_config_delete('vastai', args.name)!
|
||||
if args.name in vastai_global {
|
||||
// del vastai_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('vastai', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o VastAI) ! {
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o VastAI) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
vastai_global[o.name] = &o2
|
||||
vastai_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'vastai.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,3 +93,10 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
pub fn switch(name string) {
|
||||
vastai_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ module wireguard
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
wireguard_global map[string]&WireGuard
|
||||
@@ -19,66 +20,71 @@ pub mut:
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = wireguard_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'wireguard'
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&WireGuard {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := WireGuard{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in wireguard_global {
|
||||
if args.name == 'wireguard' {
|
||||
if !config_exists(args) {
|
||||
if default {
|
||||
println('When saving')
|
||||
config_save(args)!
|
||||
}
|
||||
}
|
||||
config_load(args)!
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('wireguard', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return wireguard_global[args.name] or {
|
||||
println(wireguard_global)
|
||||
panic('could not get config for wireguard with name:${args.name}')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for wireguard with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
// register the config for the future
|
||||
pub fn set(o WireGuard) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('wireguard', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('wireguard', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('wireguard', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
context.hero_config_delete('wireguard', args.name)!
|
||||
if args.name in wireguard_global {
|
||||
// del wireguard_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('wireguard', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o WireGuard) ! {
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o WireGuard) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
wireguard_global[o.name] = &o2
|
||||
wireguard_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
mut install_actions := plbook.find(filter: 'wireguard.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
cfg_play(p)!
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,3 +93,10 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
pub fn switch(name string) {
|
||||
wireguard_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -10,3 +10,93 @@ __global (
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&ZeroDBClient {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := ZeroDBClient{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in zerodb_client_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('zerodb_client', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return zerodb_client_global[args.name] or {
|
||||
println(zerodb_client_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for zerodb_client with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o ZeroDBClient) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('zerodb_client', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('zerodb_client', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('zerodb_client', args.name)!
|
||||
if args.name in zerodb_client_global {
|
||||
// del zerodb_client_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o ZeroDBClient) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
zerodb_client_global[o.name] = &o2
|
||||
zerodb_client_default = o.name
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut install_actions := plbook.find(filter: 'zerodb_client.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for zerodb_client
|
||||
pub fn switch(name string) {
|
||||
zerodb_client_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ fn set_in_mem(o ZinitRPC) ! {
|
||||
zinit_rpc_default = o.name
|
||||
}
|
||||
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut install_actions := plbook.find(filter: 'zinit_rpc.configure')!
|
||||
if install_actions.len > 0 {
|
||||
|
||||
@@ -3,11 +3,10 @@ module deployer
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
import freeflowuniverse.herolib.installers.threefold.griddriver
|
||||
|
||||
__global (
|
||||
tfgrid3deployer_global map[string]&TFGridDeployer
|
||||
tfgrid3deployer_default string
|
||||
deployer_global map[string]&TFGridDeployer
|
||||
deployer_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
@@ -27,13 +26,12 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&TFGridDeployer {
|
||||
mut installer := griddriver.get()!
|
||||
installer.install()!
|
||||
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := TFGridDeployer{}
|
||||
if args.name !in tfgrid3deployer_global {
|
||||
mut obj := TFGridDeployer{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in deployer_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
@@ -42,8 +40,8 @@ pub fn get(args_ ArgsGet) !&TFGridDeployer {
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return tfgrid3deployer_global[args.name] or {
|
||||
println(tfgrid3deployer_global)
|
||||
return deployer_global[args.name] or {
|
||||
println(deployer_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for deployer with name, is bug:${args.name}')
|
||||
}
|
||||
@@ -68,31 +66,19 @@ pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('deployer', args.name)!
|
||||
if args.name in tfgrid3deployer_global {
|
||||
// del tfgrid3deployer_global[args.name]
|
||||
if args.name in deployer_global {
|
||||
// del deployer_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o TFGridDeployer) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
tfgrid3deployer_global[o.name] = &o2
|
||||
tfgrid3deployer_default = o.name
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
deployer_global[o.name] = &o2
|
||||
deployer_default = o.name
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut args := args_
|
||||
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut install_actions := plbook.find(filter: 'deployer.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
@@ -105,7 +91,7 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
|
||||
// switch instance to be used for deployer
|
||||
pub fn switch(name string) {
|
||||
tfgrid3deployer_default = name
|
||||
deployer_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
@@ -2,6 +2,7 @@ module hetzner
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
hetzner_global map[string]&HetznerManager
|
||||
@@ -13,14 +14,11 @@ __global (
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = hetzner_default
|
||||
}
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
@@ -28,73 +26,65 @@ fn args_get(args_ ArgsGet) ArgsGet {
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&HetznerManager {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := HetznerManager{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in hetzner_global {
|
||||
if !config_exists() {
|
||||
if default {
|
||||
config_save()!
|
||||
}
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('hetzner', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
config_load()!
|
||||
}
|
||||
return hetzner_global[args.name] or {
|
||||
println(hetzner_global)
|
||||
panic('bug in get from factory: ')
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for hetzner with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
fn config_exists(args_ ArgsGet) bool {
|
||||
// register the config for the future
|
||||
pub fn set(o HetznerManager) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('hetzner', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context() or { panic('bug') }
|
||||
return context.hero_config_exists('hetzner', args.name)
|
||||
}
|
||||
|
||||
fn config_load(args_ ArgsGet) ! {
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
mut heroscript := context.hero_config_get('hetzner', args.name)!
|
||||
play(heroscript: heroscript)!
|
||||
context.hero_config_delete('hetzner', args.name)!
|
||||
if args.name in hetzner_global {
|
||||
// del hetzner_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
fn config_save(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_set('hetzner', args.name, heroscript_default()!)!
|
||||
}
|
||||
|
||||
fn set(o HetznerManager) ! {
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o HetznerManager) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
hetzner_global['default'] = &o2
|
||||
}
|
||||
|
||||
@[params]
|
||||
pub struct PlayArgs {
|
||||
pub mut:
|
||||
name string = 'default'
|
||||
heroscript string // if filled in then plbook will be made out of it
|
||||
plbook ?playbook.PlayBook
|
||||
reset bool
|
||||
start bool
|
||||
stop bool
|
||||
restart bool
|
||||
delete bool
|
||||
configure bool // make sure there is at least one installed
|
||||
hetzner_global[o.name] = &o2
|
||||
hetzner_default = o.name
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut args := args_
|
||||
|
||||
if args.heroscript == '' {
|
||||
args.heroscript = heroscript_default()!
|
||||
}
|
||||
mut plbook := args.plbook or { playbook.new(text: args.heroscript)! }
|
||||
|
||||
mut install_actions := plbook.find(filter: 'hetzner.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
mut p := install_action.params
|
||||
mycfg := cfg_play(p)!
|
||||
set(mycfg)!
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,3 +93,10 @@ pub fn play(mut plbook PlayBook) ! {
|
||||
pub fn switch(name string) {
|
||||
hetzner_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
|
||||
!!hero_code.play
|
||||
name:'docusaurus'
|
||||
102
lib/web/mdbook/mdbook_factory_.v
Normal file
102
lib/web/mdbook/mdbook_factory_.v
Normal file
@@ -0,0 +1,102 @@
|
||||
module mdbook
|
||||
|
||||
import freeflowuniverse.herolib.core.base
|
||||
import freeflowuniverse.herolib.core.playbook
|
||||
import freeflowuniverse.herolib.ui.console
|
||||
|
||||
__global (
|
||||
mdbook_global map[string]&MDBooks
|
||||
mdbook_default string
|
||||
)
|
||||
|
||||
/////////FACTORY
|
||||
|
||||
@[params]
|
||||
pub struct ArgsGet {
|
||||
pub mut:
|
||||
name string
|
||||
}
|
||||
|
||||
fn args_get(args_ ArgsGet) ArgsGet {
|
||||
mut args := args_
|
||||
if args.name == '' {
|
||||
args.name = 'default'
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
pub fn get(args_ ArgsGet) !&MDBooks {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
mut obj := MDBooks{
|
||||
name: args.name
|
||||
}
|
||||
if args.name !in mdbook_global {
|
||||
if !exists(args)! {
|
||||
set(obj)!
|
||||
} else {
|
||||
heroscript := context.hero_config_get('mdbook', args.name)!
|
||||
mut obj_ := heroscript_loads(heroscript)!
|
||||
set_in_mem(obj_)!
|
||||
}
|
||||
}
|
||||
return mdbook_global[args.name] or {
|
||||
println(mdbook_global)
|
||||
// bug if we get here because should be in globals
|
||||
panic('could not get config for mdbook with name, is bug:${args.name}')
|
||||
}
|
||||
}
|
||||
|
||||
// register the config for the future
|
||||
pub fn set(o MDBooks) ! {
|
||||
set_in_mem(o)!
|
||||
mut context := base.context()!
|
||||
heroscript := heroscript_dumps(o)!
|
||||
context.hero_config_set('mdbook', o.name, heroscript)!
|
||||
}
|
||||
|
||||
// does the config exists?
|
||||
pub fn exists(args_ ArgsGet) !bool {
|
||||
mut context := base.context()!
|
||||
mut args := args_get(args_)
|
||||
return context.hero_config_exists('mdbook', args.name)
|
||||
}
|
||||
|
||||
pub fn delete(args_ ArgsGet) ! {
|
||||
mut args := args_get(args_)
|
||||
mut context := base.context()!
|
||||
context.hero_config_delete('mdbook', args.name)!
|
||||
if args.name in mdbook_global {
|
||||
// del mdbook_global[args.name]
|
||||
}
|
||||
}
|
||||
|
||||
// only sets in mem, does not set as config
|
||||
fn set_in_mem(o MDBooks) ! {
|
||||
mut o2 := obj_init(o)!
|
||||
mdbook_global[o.name] = &o2
|
||||
mdbook_default = o.name
|
||||
}
|
||||
|
||||
pub fn play(mut plbook PlayBook) ! {
|
||||
mut install_actions := plbook.find(filter: 'mdbook.configure')!
|
||||
if install_actions.len > 0 {
|
||||
for install_action in install_actions {
|
||||
heroscript := install_action.heroscript()
|
||||
mut obj2 := heroscript_loads(heroscript)!
|
||||
set(obj2)!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// switch instance to be used for mdbook
|
||||
pub fn switch(name string) {
|
||||
mdbook_default = name
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
@[params]
|
||||
pub struct DefaultConfigArgs {
|
||||
instance string = 'default'
|
||||
}
|
||||
Reference in New Issue
Block a user