core.base #
context & sessions
Everything we do in hero lives in a context, each context has a unique name.
Redis is used to manage the contexts and the sessions.
- redis db 0
context:current
curent id of the context, is also the DB if redis if redis is used- redis db X, x is nr of context
context:name
name of this contextcontext:secret
secret as is used in context (is md5 of original config secret)context:privkey
secp256k1 privkey as is used in context (encrypted by secret)context:params
params for a context, can have metadatacontext:lastid
last id for our dbsession:$id
the location of sessionsession:$id:params
params for the session, can have metadata
Session id is $contextid:$sessionid (e.g. 10:111)
The SessionNewArgs:
- context_name string = 'default'
- session_name string //default will be an incremental nr if not filled in
- interactive bool = true //can ask questions, default on true
- coderoot string //this will define where all code is checked out
import freeflowuniverse.crystallib.core.base
mut session:=context_new(
coderoot:'/tmp/code'
interactive:true
)!
mut session:=session_new(context:'default',session:'mysession1')!
mut session:=session_new()! //returns default context & incremental new session
fn configurator_new #
fn configurator_new[T](args ConfiguratorArgs) !Configurator[T]
name is e.g. mailclient (the type of configuration setting) instance is the instance of the config e.g. kds the context defines the context in which we operate, is optional will get the default one if not set
fn context #
fn context() !&Context
fn context_get #
fn context_get(id u32) !&Context
fn context_new #
fn context_new(args_ ContextConfigArgs) !&Context
configure a context object params: .
id u32 //if not set then redis will get a new context id
name string = 'default'
params string
coderoot string
interactive bool
secret string
priv_key_hex string //hex representation of private key
fn context_select #
fn context_select(id u32) !&Context
fn (BaseConfig[T]) session #
fn (mut self BaseConfig[T]) session() !&Session
fn (BaseConfig[T]) configurator #
fn (mut self BaseConfig[T]) configurator() !&Configurator[T]
management class of the configs of this obj
fn (BaseConfig[T]) config_set #
fn (mut self BaseConfig[T]) config_set(myconfig T) !
will overwrite the config
fn (BaseConfig[T]) config_new #
fn (mut self BaseConfig[T]) config_new() !&T
fn (BaseConfig[T]) config #
fn (mut self BaseConfig[T]) config() !&T
fn (BaseConfig[T]) config_get #
fn (mut self BaseConfig[T]) config_get() !&T
fn (BaseConfig[T]) config_save #
fn (mut self BaseConfig[T]) config_save() !
fn (BaseConfig[T]) config_delete #
fn (mut self BaseConfig[T]) config_delete() !
fn (BaseConfig[T]) init #
fn (mut self BaseConfig[T]) init(configtype string, instance string, action Action, myconfig T) !
init our class with the base session_args
fn (Configurator[T]) set #
fn (mut self Configurator[T]) set(args T) !
set the full configuration as one object to dbconfig
fn (Configurator[T]) exists #
fn (mut self Configurator[T]) exists() !bool
fn (Configurator[T]) new #
fn (mut self Configurator[T]) new() !T
fn (Configurator[T]) get #
fn (mut self Configurator[T]) get() !T
fn (Configurator[T]) delete #
fn (mut self Configurator[T]) delete() !
fn (Configurator[T]) getset #
fn (mut self Configurator[T]) getset(args T) !T
fn (Configurator[T]) list #
fn (mut self Configurator[T]) list() ![]string
fn (Configurator[T]) configprint #
fn (mut self Configurator[T]) configprint(args PrintArgs) !
enum Action #
enum Action {
set
get
new
delete
}
enum ErrorType #
enum ErrorType {
uknown
value
}
enum LogType #
enum LogType {
stdout
error
}
struct Base #
struct Base {
configtype string @[required]
mut:
instance string
session_ ?&Session
}
fn (Base) session #
fn (mut self Base) session() !&Session
struct BaseConfig #
struct BaseConfig[T] {
mut:
configurator_ ?Configurator[T] @[skip; str: skip]
config_ ?&T
session_ ?&Session @[skip; str: skip]
configtype string
pub mut:
instance string
}
is an object which has a configurator, session and config object which is unique for the model T is the Config Object
struct Configurator #
struct Configurator[T] {
pub mut:
// context &Context @[skip; str: skip]
instance string
description string
configured bool
configtype string // e.g. sshclient
}
struct ConfiguratorArgs #
struct ConfiguratorArgs {
pub mut:
// context &Context // optional context for the configurator
instance string @[required]
}
struct Context #
struct Context {
mut:
// priv_key_ ?&secp256k1.Secp256k1 @[skip; str: skip]
params_ ?¶msparser.Params
dbcollection_ ?&dbfs.DBCollection @[skip; str: skip]
redis_ ?&redisclient.Redis @[skip; str: skip]
pub mut:
// snippets map[string]string
config ContextConfig
}
fn (Context) dbcollection #
fn (mut self Context) dbcollection() !&dbfs.DBCollection
return db collection
fn (Context) guid #
fn (self Context) guid() string
fn (Context) hero_config_exists #
fn (mut self Context) hero_config_exists(cat string, name string) bool
fn (Context) hero_config_get #
fn (mut self Context) hero_config_get(cat string, name string) !string
fn (Context) hero_config_set #
fn (mut self Context) hero_config_set(cat string, name string, content_ string) !
fn (Context) id #
fn (self Context) id() string
fn (Context) load #
fn (mut self Context) load() !
get context from out of redis
fn (Context) name #
fn (self Context) name() string
fn (Context) params #
fn (mut self Context) params() !¶msparser.Params
return the gistructure as is being used in context
fn (Context) redis #
fn (mut self Context) redis() !&redisclient.Redis
pub fn (mut self Context) heroscript() !string { panic("implement") mut out := '!!core.context_define ${self.str2()}\n' mut p:=self.params()! if !p.empty() { out += '\n!!core.params_context_set' out += texttools.indent(p.heroscript(), ' ') + '\n' } // if self.snippets.len > 0 { // for key, snippet in self.snippets { // out += '\n!!core.snippet guid:${self.guid()} name:${key}' // out += texttools.indent(snippet.heroscript()," ") + '\n' // } // } return out }
fn (Context) save #
fn (mut self Context) save() !
fn (Context) secret_configure #
fn (mut self Context) secret_configure() !
show a UI in console to configure the secret
fn (Context) secret_decrypt #
fn (mut self Context) secret_decrypt(txt string) !string
fn (Context) secret_encrypt #
fn (mut self Context) secret_encrypt(txt string) !string
will use our secret as configured for the hero to encrypt, uses base64
fn (Context) secret_get #
fn (mut self Context) secret_get() !string
fn (Context) secret_set #
fn (mut self Context) secret_set(secret_ string) !
unhashed secret
fn (Context) session_get #
fn (mut context Context) session_get(args_ ContextSessionGetArgs) !Session
fn (Context) session_latest #
fn (mut context Context) session_latest() !Session
fn (Context) session_new #
fn (mut context Context) session_new(args_ SessionConfig) !Session
get a session object based on the name / params:
name string
struct ContextConfig #
struct ContextConfig {
pub mut:
id u32 @[required]
name string = 'default'
params string
coderoot string
interactive bool
secret string // is hashed secret
priv_key string // encrypted version
db_path string // path to dbcollection
encrypt bool
}
struct ContextConfigArgs #
struct ContextConfigArgs {
pub mut:
id u32
name string = 'default'
params string
coderoot string
interactive bool
secret string
encrypt bool
priv_key_hex string // hex representation of private key
}
struct ContextSessionGetArgs #
struct ContextSessionGetArgs {
pub mut:
name string
}
struct ErrorArgs #
struct ErrorArgs {
pub mut:
cat string
error string
errortype ErrorType
}
struct ErrorItem #
struct ErrorItem {
pub mut:
time ourtime.OurTime
cat string
error string
errortype ErrorType
session string // the unique name for the session
}
struct LogArgs #
struct LogArgs {
pub mut:
cat string
log string @[required]
logtype LogType
}
struct LogItem #
struct LogItem {
pub mut:
time ourtime.OurTime
cat string
log string
logtype LogType
session string
}
fn (LogItem) str #
fn (li LogItem) str() string
struct Logger #
struct Logger {
pub mut:
session string
}
struct PrintArgs #
struct PrintArgs {
pub mut:
name string
}
struct Session #
struct Session {
pub mut:
name string // unique id for session (session id), can be more than one per context
interactive bool = true
params paramsparser.Params
start ourtime.OurTime
end ourtime.OurTime
context &Context @[skip; str: skip]
config SessionConfig
env map[string]string
}
fn (Session) check #
fn (self Session) check() !
//////// REPRESENTATION
fn (Session) db_config_get #
fn (mut self Session) db_config_get() !dbfs.DB
get the db of the config, is unique per context
fn (Session) db_get #
fn (mut self Session) db_get() !dbfs.DB
get db of the session, is unique per session
fn (Session) env_delete #
fn (mut self Session) env_delete(key string)
Delete an environment variable
fn (Session) env_get #
fn (mut self Session) env_get(key string) !string
Get an environment variable
fn (Session) env_set #
fn (mut self Session) env_set(key string, value string) !
Set an environment variable
fn (Session) error #
fn (mut session Session) error(args_ ErrorArgs) !ErrorItem
fn (Session) guid #
fn (self Session) guid() string
fn (Session) load #
fn (mut self Session) load() !
load the params from redis
fn (Session) log #
fn (mut session Session) log(args_ LogArgs) !LogItem
cat & log are the arguments . category can be any well chosen category e.g. vm
fn (Session) logger_new #
fn (session Session) logger_new() !Logger
fn (Session) save #
fn (mut self Session) save() !
save the params to redis
struct SessionConfig #
struct SessionConfig {
pub mut:
name string // unique name for session (id), there can be more than 1 session per context
start string // can be e.g. +1h
description string
params string
}
- README
- fn configurator_new
- fn context
- fn context_get
- fn context_new
- fn context_select
- type BaseConfig[T]
- type Configurator[T]
- enum Action
- enum ErrorType
- enum LogType
- struct Base
- struct BaseConfig
- struct Configurator
- struct ConfiguratorArgs
- struct Context
- struct ContextConfig
- struct ContextConfigArgs
- struct ContextSessionGetArgs
- struct ErrorArgs
- struct ErrorItem
- struct LogArgs
- struct LogItem
- struct Logger
- struct PrintArgs
- struct Session
- struct SessionConfig