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]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.