Re: Re: custom promises: use data from python list in mustache template
Xander Cage <[email protected]>
| Newsgroups | gmane.comp.sysutils.cfengine.general |
|---|---|
| Message-ID | <[email protected]> |
hi, ah ok...thanx for the explanation, will implement to whole file write stuff in the module than. chris On Wednesday, November 23, 2022 at 5:07:30 PM UTC+1 [email protected] wrote: > Hi Chris! > Yes, that's expected. The custom promise types are just like the other, > built in, promise types -- they implement support for promises, i.e. state > definitions, and the communication protocol only passes the definitions to > the custom module and then promise results and log messages back. What your > use case requires would be custom policy functions support of which is part > of our plans [1], but currently not with high priority. > > [1] https://tracker.mender.io/browse/CFE-2839 > > -- > Vratislav > > On Wed, 2022-11-23 at 05:38 -0800, Xander Cage wrote: > > toyed around a bit...returning just json seems not to work very well > > import os > import json > from cfengine import PromiseModule, ValidationError, Result > > > class MkSudoPermsModule(PromiseModule): > def __init__(self): > super().__init__("itsv_mk_sudo_perms_promise_module", "0.0.1") > > def validate_promise(self, promiser, attributes): > pass > > def evaluate_promise(self, promiser, attributes): > lst = ['jboss1', 'jboss2', 'jboss3'] > return json.dumps(lst) > > return Result.KEPT > > > if __name__ == "__main__": > MkSudoPermsModule().start() > ~ > > result: > > verbose: Begin policy/promise evaluation > verbose: ---------------------------------------------------------------- > verbose: Using bundlesequence => {"main"} > verbose: B: > ***************************************************************** > verbose: B: BEGIN bundle main > verbose: B: > ***************************************************************** > debug: DeRefCopyPromise(): promiser:'/usr/security/user' > debug: DeRefCopyPromise(): copying constraint: 'name' > verbose: Starting custom promise module > '/var/cfengine/modules/promises/itsv_mk_sudo_perms.py' with command > '/opt/freeware/bin/python3 > /var/cfengine/modules/promises/itsv_mk_sudo_perms.py' > debug: Received header from promise module: > 'itsv_mk_sudo_perms_promise_module 0.0.1 v1 json_based' > debug: Received line from module: '{"operation": "validate_promise", > "promiser": "/usr/security/user", "attributes": {"name": "jboss"}, > "result": "valid"}' > debug: Received line from module: '{"operation": "evaluate_promise", > "promiser": "/usr/security/user", "attributes": {"name": "jboss"}, > "result": "[\"jboss1\", \"jboss2\", \"jboss3\"]"}' > error: Promise module returned unacceptable result: '["jboss1", > "jboss2", "jboss3"]' (mk_sudo_perms promise, promiser: '/usr/security/user' > module: '/var/cfengine/modules/promises/itsv_mk_sudo_perms.py') > verbose: A: Promise NOT KEPT! > verbose: P: END mk_sudo_perms promise (/usr/security/user) > debug: DeRefCopyPromise(): promiser:'/usr/security/user' > debug: DeRefCopyPromise(): copying constraint: 'name' > debug: DeRefCopyPromise(): promiser:'/usr/security/user' > debug: DeRefCopyPromise(): copying constraint: 'name' > verbose: A: ................................................... > verbose: A: Bundle Accounting Summary for 'main' in namespace default > > > not very promising *gg* > > > On Wednesday, November 23, 2022 at 1:08:22 PM UTC+1 Xander Cage wrote: > > Hi, > > i need to create a "custom promise" which read some string base data from > system files. i want to use this data inside a cfengine mustache template > to write out to another file. > i skimmed through the "custom" api docs but could not find a hint how to > transpose data from the underlying module code (python list) in an cfengine > variable. or is it as easy as just returning the list as a json string? > is this even possible? > > wbr > > chris > > > > -- > You received this message because you are subscribed to the Google Groups > "help-cfengine" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/help-cfengine/22988450-5566-4e45-bbe8-79c0c54a85b4n%40googlegroups.com > <https://groups.google.com/d/msgid/help-cfengine/22988450-5566-4e45-bbe8-79c0c54a85b4n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > > -- You received this message because you are subscribed to the Google Groups "help-cfengine" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/help-cfengine/953ea994-e395-477c-9fb9-bc0833cc6ec7n%40googlegroups.com.