Skip to content

ENT-14319: Added function to initialize promise-type/-module-projects - #198

Open
SimonThalvorsen wants to merge 1 commit into
cfengine:mainfrom
SimonThalvorsen:main
Open

ENT-14319: Added function to initialize promise-type/-module-projects#198
SimonThalvorsen wants to merge 1 commit into
cfengine:mainfrom
SimonThalvorsen:main

Conversation

@SimonThalvorsen

Copy link
Copy Markdown
Contributor

Ticket: ENT-14319
Changelog: None

@cf-bottom

Copy link
Copy Markdown

Thank you for submitting a PR! Maybe @craigcomstock can review this?

@olehermanse
olehermanse self-requested a review July 28, 2026 13:36
@SimonThalvorsen
SimonThalvorsen marked this pull request as draft July 28, 2026 17:06
@olehermanse
olehermanse marked this pull request as ready for review July 29, 2026 12:37
@olehermanse
olehermanse requested a review from larsewi July 29, 2026 12:38
Comment thread src/cfengine_cli/main.py Outdated
Comment thread src/cfengine_cli/main.py Outdated
Comment thread src/cfengine_cli/main.py Outdated
Comment thread src/cfengine_cli/main.py Outdated
Comment thread src/cfengine_cli/main.py Outdated
Comment thread src/cfengine_cli/commands.py
Comment thread src/cfengine_cli/initialize_project.py Outdated
Comment thread src/cfengine_cli/initialize_project.py Outdated
Comment thread src/cfengine_cli/initialize_project.py Outdated
Comment thread src/cfengine_cli/initialize_project.py Outdated
Comment thread src/cfengine_cli/initialize_project.py Outdated
Comment thread src/cfengine_cli/initialize_project.py Outdated

@olehermanse olehermanse left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, left some suggestions / feedback. Will have more when I test it.

@larsewi

larsewi commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

LGTM 🚀 For some reason this does not work for me

$ make install
pipx install --force --editable .
Installing to existing venv 'cfengine'
  installed package cfengine 0.20.1.dev3+ge62ae5d80, installed using Python 3.12.3
  These apps are now globally available
    - cfengine
done! ✨ 🌟 ✨
$ cfengine --help
Traceback (most recent call last):
  File "/home/larsewi/.local/bin/cfengine", line 3, in <module>
    from cfengine_cli.main import main
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/__init__.py", line 8, in <module>
    __import__("cfengine_cli." + module)
ModuleNotFoundError: No module named 'cfengine_cli.format.old'; 'cfengine_cli.format' is not a package

am I doing something wrong?

@SimonThalvorsen

Copy link
Copy Markdown
Contributor Author

LGTM 🚀 For some reason this does not work for me

Traceback (most recent call last):
  File "/home/larsewi/.local/bin/cfengine", line 3, in <module>
    from cfengine_cli.main import main
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/__init__.py", line 8, in <module>
    __import__("cfengine_cli." + module)
ModuleNotFoundError: No module named 'cfengine_cli.format.old'; 'cfengine_cli.format' is not a package

am I doing something wrong?

@larsewi
Try renaming any .old.py -> .py.old (or remove them) and it should work

@SimonThalvorsen
SimonThalvorsen force-pushed the main branch 2 times, most recently from 6a28fd8 to 37eb07b Compare July 30, 2026 12:57

@larsewi larsewi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ cfengine init --policy-module --with-input
Try to follow existing naming conventions, for example:
- compliance-report-lynis: Adds the lynis compliance report
- delete-files: Deletes files specified by the user
- inventory-etc-hosts: Adds inventory information based on the /etc/hosts file
- library-sshd-config: A library for working with sshd config, intended to be used by other modules.
Name of module [distribute-ssh-keys]: 
Initialized empty Git repository in /home/larsewi/ntech/distribute-ssh-keys/.git/
Traceback (most recent call last):
  File "/home/larsewi/.local/bin/cfengine", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/main.py", line 416, in main
    exit_code = _main()
                ^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/main.py", line 408, in _main
    return run_command_with_args(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/main.py", line 215, in run_command_with_args
    return commands.init(args)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/commands.py", line 59, in init
    rc = init_policy_module(
         ^^^^^^^^^^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/initialize_project.py", line 112, in init_policy_module
    config = _scaffold(
             ^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/initialize_project.py", line 162, in _scaffold
    validate_config_raise_exceptions(config, empty_build_list_ok=True)
  File "/home/larsewi/.local/share/pipx/venvs/cfengine/lib/python3.12/site-packages/cfbs/validate.py", line 319, in validate_config_raise_exceptions
    validate_single_module("provides", name, module, config)
  File "/home/larsewi/.local/share/pipx/venvs/cfengine/lib/python3.12/site-packages/cfbs/validate.py", line 863, in validate_single_module
    _validate_module_input(name, module)
  File "/home/larsewi/.local/share/pipx/venvs/cfengine/lib/python3.12/site-packages/cfbs/validate.py", line 698, in _validate_module_input
    raise CFBSValidationError(
cfbs.utils.CFBSValidationError: Error in cfbs.json for module 'distribute-ssh-keys': "distribute-ssh-keys" is not an acceptable namespace, must match regex "[a-z_][a-z0-9_]+"

I'm guessing namespace should be canonicalized to distribute_ssh_keys

@SimonThalvorsen

Copy link
Copy Markdown
Contributor Author
$ cfengine init --policy-module --with-input
Try to follow existing naming conventions, for example:
- compliance-report-lynis: Adds the lynis compliance report
- delete-files: Deletes files specified by the user
- inventory-etc-hosts: Adds inventory information based on the /etc/hosts file
- library-sshd-config: A library for working with sshd config, intended to be used by other modules.
Name of module [distribute-ssh-keys]: 
Initialized empty Git repository in /home/larsewi/ntech/distribute-ssh-keys/.git/
Traceback (most recent call last):
  File "/home/larsewi/.local/bin/cfengine", line 6, in <module>
    sys.exit(main())
             ^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/main.py", line 416, in main
    exit_code = _main()
                ^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/main.py", line 408, in _main
    return run_command_with_args(args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/main.py", line 215, in run_command_with_args
    return commands.init(args)
           ^^^^^^^^^^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/commands.py", line 59, in init
    rc = init_policy_module(
         ^^^^^^^^^^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/initialize_project.py", line 112, in init_policy_module
    config = _scaffold(
             ^^^^^^^^^^
  File "/home/larsewi/ntech/cfengine-cli/src/cfengine_cli/initialize_project.py", line 162, in _scaffold
    validate_config_raise_exceptions(config, empty_build_list_ok=True)
  File "/home/larsewi/.local/share/pipx/venvs/cfengine/lib/python3.12/site-packages/cfbs/validate.py", line 319, in validate_config_raise_exceptions
    validate_single_module("provides", name, module, config)
  File "/home/larsewi/.local/share/pipx/venvs/cfengine/lib/python3.12/site-packages/cfbs/validate.py", line 863, in validate_single_module
    _validate_module_input(name, module)
  File "/home/larsewi/.local/share/pipx/venvs/cfengine/lib/python3.12/site-packages/cfbs/validate.py", line 698, in _validate_module_input
    raise CFBSValidationError(
cfbs.utils.CFBSValidationError: Error in cfbs.json for module 'distribute-ssh-keys': "distribute-ssh-keys" is not an acceptable namespace, must match regex "[a-z_][a-z0-9_]+"

I'm guessing namespace should be canonicalized to distribute_ssh_keys

I think you are on an outdated commit?

~/tmp
❯ mkdir distribute-ssh-keys

~/tmp
❯ cd distribute-ssh-keys/

~/tmp/distribute-ssh-keys
❯
~/tmp/distribute-ssh-keys
❯ cfengine init --policy-module --with-input
Try to follow existing naming conventions, for example:
- compliance-report-lynis: Adds the lynis compliance report
- delete-files: Deletes files specified by the user
- inventory-etc-hosts: Adds inventory information based on the /etc/hosts file
- library-sshd-config: A library for working with sshd config, intended to be used by other modules.
Name of module [distribute-ssh-keys]:
Initialized empty Git repository in /home/tide/tmp/distribute-ssh-keys/.git/
Added module: masterfiles
Committing using git:

[main (root-commit) 20a97f8] Initialized a new CFEngine Build project for module 'distribute-ssh-keys'
 5 files changed, 174 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 cfbs.json
 create mode 100644 distribute-ssh-keys/README.md
 create mode 100644 distribute-ssh-keys/input.json
 create mode 100644 distribute-ssh-keys/main.cf

Committing using git:

[main ea65bb3] Added module './distribute-ssh-keys/'
 1 file changed, 46 insertions(+)


Initialized a project for developing the policy module 'distribute-ssh-keys'

To build and test a policy set with your module:
  `cfbs build` and `cf-remote deploy`
   or `cfengine build`

To change the module's input:
  cfbs input distribute-ssh-keys

See distribute-ssh-keys/README.md for what to edit before publishing.

@larsewi

larsewi commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Works now. However, it seems like the formatter gets run after the commit and you end up with a diff.

$ git diff | tail
     "while": "Do you want to specify more inputs?",
-    "response": [
-      {
-        "key1": "Value1",
-        "key2": "Value2"
-      }
-    ]
+    "response": [{ "key1": "Value1", "key2": "Value2" }]
   }
 ]

could you fix that?

@larsewi

larsewi commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Also I think the README.md should be in the root of the repository. Maybe I'm wrong

Ticket: ENT-14319
Changelog: None

Signed-off-by: Simon Halvorsen <simon.halvorsen@northern.tech>
@SimonThalvorsen

Copy link
Copy Markdown
Contributor Author

Also I think the README.md should be in the root of the repository. Maybe I'm wrong

Fair enough, if you would create it as a module-git-repo you would want the README to the first thing you see. It will probably change over time (details, how to publish and so on) anyways so I do not think it matters that much at this point

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants