Re: Re: custom promises: use data from python list in mustache template

"'Vratislav Podzimek' via help-cfengine" <[email protected]>
Newsgroups gmane.comp.sysutils.cfengine.general
Message-ID <[email protected]>
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
> .

-- 
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/0c3a9b516930e2786c32283cde8cdb9c60d0cdf4.camel%40northern.tech.
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEENAH7ns+FyuCe6j1XmyV2peQQR/QFAmN+RT0ACgkQmyV2peQQ
R/TUGBAAgTOVKMbggpynDGh6zc9IxzowdM89iQ6ZrVHuzdQoLBcPtFMLOZetQmwv
Q6pNy15zqYY2l6ZZk+2w32yeuq3PGBR0rWccrq6q87LEHngznUW6OpgNgBWGCYsg
FCsrAmNcReh3+wMBrG9i7LPEEx0GNIMxBXYDPZHqZ33HBzwdIs+q3fcTR5HRpldE
d/E+zP7KgHtH69IV6grWehe2+RHktL3r+zYofFaopKiAzuZqBXXJd1NH8lQCjlPK
0myt3Zhazc+94AoJYeitGb+ZI12QEjCdkWFzLPpu4fmNAB/Vy7tWgbwo9q2wTvpj
q6qxBm//W6hL0o3PLP+XYriS+l0+oD2+V9jRmm74a8pQPIO2FvAS2+EScXK1zjEP
uRdtoOfZi7nhnocEvqiXC3U3kuVYbrFwSYm/HitHU84F0zWoINwlpMfrAbeLiEB7
/wE84DoirajsSERpXXJjrBhYTP7oubdH4GXv6iWaCVwwM0VHg+BnUsZ11jcYgLPJ
L3n3ESMpNLgEAxoumpyo0v3jm33YiTt91Dd6tUnLQgzLayFxHb1ntzaMNPZYmPWN
guB7+MuZedgUttDWhf5CzW30GLZ9zdPNPJWyEVKgE44WSKWKoVBYcagxDhEn5EP0
2pgSenRgk1x5/0Wka/bAVHKqmbTozueJCM+atwC8tZeBNVaFt6o=
=qFMH
-----END PGP SIGNATURE-----
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.