This commit is contained in:
2025-08-16 11:23:58 +02:00
parent be19609855
commit de60c5f78e
38 changed files with 1374 additions and 869 deletions

View File

@@ -9,9 +9,9 @@ import os
@[heap]
pub struct Context {
mut:
params_ ?&paramsparser.Params
redis_ ?&redisclient.Redis @[skip; str: skip]
path_ ?pathlib.Path
params_ ?&paramsparser.Params
redis_ ?&redisclient.Redis @[skip; str: skip]
path_ ?pathlib.Path
pub mut:
// snippets map[string]string
config ContextConfig
@@ -88,7 +88,6 @@ fn (mut self Context) cfg_redis_exists() !bool {
return r.exists('context:config')!
}
// pub fn (mut self Context) secret_encrypt(txt string) !string {
// return aes_symmetric.encrypt_str(txt, self.secret_get()!)
// }

View File

@@ -31,7 +31,6 @@ pub mut:
// return 'hero:sessions:${self.guid()}'
// }
// load the params from redis
pub fn (mut self Session) load() ! {
mut r := self.context.redis()!

View File

@@ -5,6 +5,7 @@ import freeflowuniverse.herolib.core.base
@end
import freeflowuniverse.herolib.core.playbook { PlayBook }
import freeflowuniverse.herolib.ui.console
import json
@if args.cat == .installer
import freeflowuniverse.herolib.osal.startupmanager
@@ -21,7 +22,7 @@ __global (
/////////FACTORY
@[params]
@@[params]
pub struct ArgsGet {
pub mut:
name string = "default"
@@ -42,21 +43,25 @@ pub fn get(args ArgsGet) !&${args.classname} {
mut context := base.context()!
${args.name}_default = args.name
if args.fromdb || args.name !in ${args.name}_global {
if context.hero_config_exists('${args.name}', args.name) {
heroscript := context.hero_config_get('${args.name}', args.name)!
mut obj_ := heroscript_loads(heroscript)!
set_in_mem(obj_)!
mut r := context.redis()!
if r.hexists('context:${args.name}', args.name)! {
data := r.hget('context:${args.name}', args.name)!
if data.len == 0 {
return error('${args.name} with name: ${args.name} does not exist, prob bug.')
}
mut obj := json.decode(${args.classname},data)!
set_in_mem(obj)!
}else{
if args.create {
new(args)!
}else{
return error("${args.classname} with name '\${args.name}' does not exist")
return error("${args.classname} with name '${args.name}' does not exist")
}
}
return get(name: args.name)! //no longer from db nor create
}
return ${args.name}_global[args.name] or {
return error('could not get config for ${args.name} with name:\${args.name}')
return error('could not get config for ${args.name} with name:${args.name}')
}
}
@@ -65,23 +70,24 @@ pub fn set(o ${args.classname}) ! {
set_in_mem(o)!
${args.name}_default = o.name
mut context := base.context()!
heroscript := heroscript_dumps(o)!
context.hero_config_set('${args.name}', o.name, heroscript)!
mut r := context.redis()!
r.hset('context:${args.name}', o.name, json.encode(o))!
}
// does the config exists?
pub fn exists(args ArgsGet) !bool {
mut context := base.context()!
return context.hero_config_exists('${args.name}', args.name)
mut r := context.redis()!
return r.hexists('context:${args.name}', args.name)!
}
pub fn delete(args ArgsGet) ! {
mut context := base.context()!
${args.name}_global.delete(args.name)
context.hero_config_delete('${args.name}', args.name)!
mut r := context.redis()!
r.hdel('context:${args.name}', args.name)!
}
@[params]
@@[params]
pub struct ArgsList {
pub mut:
fromdb bool //will load from filesystem
@@ -97,11 +103,11 @@ pub fn list(args ArgsList) ![]&${args.classname} {
${args.name}_default = ''
}
if args.fromdb {
for name in context.hero_config_list('${args.name}')!{
mut hscript := context.hero_config_get('${args.name}', name)!
mut obj := heroscript_loads(hscript)!
set_in_mem(obj)!
res << &obj
mut r := context.redis()!
mut l := r.hkeys('context:${args.name}')!
for name in l{
res << get(name:name,fromdb:true)!
}
return res
} else {
@@ -331,7 +337,3 @@ pub fn (mut self ${args.classname}) destroy() ! {
@end
//switch instance to be used for ${args.name}
pub fn switch(name string) {
${args.name}_default = name
}

View File

@@ -66,3 +66,10 @@ fn configure() ! {
}
@end
/////////////NORMALLY NO NEED TO TOUCH
pub fn heroscript_loads(heroscript string) !${args.classname} {
mut obj := encoderhero.decode[${args.classname}](heroscript)!
return obj
}

View File

@@ -11,8 +11,9 @@ import os
// -------------------------------------------------------------------
fn play_core(mut plbook PlayBook) ! {
if plbook.exists(filter: 'play.')==false && plbook.exists(filter: 'play.')==false && plbook.exists(filter: 'core.')==false{
if plbook.exists(filter: 'play.') == false && plbook.exists(filter: 'play.') == false && plbook.exists(
filter: 'core.'
) == false {
return
}

View File

@@ -11,8 +11,7 @@ import freeflowuniverse.herolib.ui.console // For verbose error reporting
// ---------------------------------------------------------------
fn play_git(mut plbook PlayBook) ! {
if plbook.exists(filter: 'git.')==false{
if plbook.exists(filter: 'git.') == false {
return
}

View File

@@ -5,12 +5,10 @@ import freeflowuniverse.herolib.core.playbook { PlayBook }
// import os
fn play_luadns(mut plbook PlayBook) ! {
if plbook.exists(filter: 'luadns.')==false{
if plbook.exists(filter: 'luadns.') == false {
return
}
// Variables below are not used, commenting them out
// mut buildroot := '${os.home_dir()}/hero/var/mdbuild'
// mut publishroot := '${os.home_dir()}/hero/www/info'

View File

@@ -4,9 +4,7 @@ import freeflowuniverse.herolib.osal.sshagent
import freeflowuniverse.herolib.core.playbook { PlayBook }
fn play_ssh(mut plbook PlayBook) ! {
if plbook.exists(filter: 'sshagent.')==false{
if plbook.exists(filter: 'sshagent.') == false {
return
}