Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enh] support config_panel in TOML format #732

Merged
merged 1 commit into from Jun 24, 2019

Conversation

Projects
None yet
5 participants
@Psycojoker
Copy link
Member

commented May 31, 2019

The problem

Writting a config_panel in json turns out to be unecessary complicated and error prone.

Solution

After looking at a lot of different formats, toml turns out to be the most intuitive one and less error prone to use for not super-turbo-nerdy people which most app devs are (and even for turbo-nerdy writting json by hand sucks). App group people confirmed that it really looks like an improvement other json.

The solution to limit the modification of the code is to transform this new toml format in the current json format internally on load (which is easier to use for code)

Sidenode: I'm considering introducing support for manifest.toml and will certainly do actions.toml as it also really looks like an improvment: https://gist.github.com/Psycojoker/71aca1767738c4b254b6cd74e09c28e1#file-manifest-toml

In json it looks like that:

{
	"name": "Unattended-upgrades configuration panel",
	"version": "0.1",
	"panel": [{
		"name": "Unattended-upgrades configuration",
		"id": "main",
		"sections": [{
			"name": "50unattended-upgrades configuration file",
			"id": "unattended_configuration",
			"options": [{
				"name": "Choose the sources of packages to automatically upgrade.",
				"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>Security only, Security and updates.",
				"id": "upgrade_level",
				"type": "text",
				"//": "\"choices\" : [\"Security only\", \"Security and updates\"]",
				"default" : "Security only"
			},
			{
				"name": "Would you like to update YunoHost packages automatically ?",
				"id": "ynh_update",
				"type": "bool",
				"default": true
			},
			{
				"name": "Would you like to receive an email from Unattended-Upgrades ?",
				"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>If an upgrade has been done, Only if there was an error, Never.",
				"id": "unattended_mail",
				"type": "text",
				"//": "\"choices\" : [\"If an upgrade has been done\", \"Only if there was an error\", \"Never\"]",
				"default" : "If an upgrade has been done"
			}]
		},
		{
			"name": "apticron cron file",
			"id": "apticron_configuration",
			"options": [{
				"name": "Would you like to receive an email to inform which upgrades need to be done ?",
				"id": "previous_apticron",
				"type": "bool",
				"default": true
			},
			{
				"name": "When do you want to receive this email ?",
				"help": "Choose an hour between 12 and 23.<br>",
				"id": "previous_apticron_hour",
				"type": "number",
				"default": 20
			},
			{
				"name": "Would you like to receive an email to verify if there any upgrades left after each auto upgrade ?",
				"id": "after_apticron",
				"type": "bool",
				"default": true
			},
			{
				"name": "When do you want to receive this email ?",
				"help": "Choose an hour between 0 and 10.",
				"id": "after_apticron_hour",
				"type": "number",
				"default": 2
			}]
		},
		{
			"name": "02periodic apt config file",
			"id": "periodic_configuration",
			"options": [{
				"name": "Choose the level of verbosity of Unattended-Upgrades mail",
				"help": "We can't use a choices field for now. In the meantime please choose between one of this values:<br>1, 2, 3.",
				"help": "1: Progress report only.<br>2: Progress report and command outputs.<br>3: Progress report and command outputs and trace.",
				"id": "unattended_verbosity",
				"type": "text",
				"//": "\"choices\" : [\"1\", \"2\", \"3\"]",
				"default" : "1"
			}]
		},
		{
			"name": "Overwriting config files",
			"id": "overwrite_files",
			"options": [{
				"name": "Overwrite the config file 02periodic ?",
				"help": "If the file is overwritten, a backup will be created.",
				"id": "overwrite_periodic",
				"type": "bool",
				"default": true
			}]
		},
		{
			"name": "Global configuration",
			"id": "global_config",
			"options": [{
				"name": "Send HTML email to admin ?",
				"help": "Allow app scripts to send HTML mails instead of plain text.",
				"id": "email_type",
				"type": "bool",
				"default": true
			}]
		}]
	}
]
}

In TOML like that:

version = "0.1"
name = "Unattended-upgrades configuration panel"

[main]
name = "Unattended-upgrades configuration"

    [main.unattended_configuration]
    name = "50unattended-upgrades configuration file"

        [main.unattended_configuration.upgrade_level]
        name = "Choose the sources of packages to automatically upgrade."
        default = "Security only"
        type = "text"
        help = "We can't use a choices field for now. In the meantime please choose between one of this values:<br>Security only, Security and updates."
        # choices = ["Security only", "Security and updates"]

        [main.unattended_configuration.ynh_update]
        name = "Would you like to update YunoHost packages automatically ?"
        type = "bool"
        default = true

        [main.unattended_configuration.unattended_mail]
        name = "Would you like to receive an email from Unattended-Upgrades ?"
        default = "If an upgrade has been done"
        type = "text"
        help = "We can't use a choices field for now. In the meantime please choose between one of this values:<br>If an upgrade has been done, Only if there was an error, Never."
        # choices = ["If an upgrade has been done", "Only if there was an error", "Never"]


    [main.apticron_configuration]
    name = "apticron cron file"

        [main.apticron_configuration.previous_apticron]
        name = "Would you like to receive an email to inform which upgrades need to be done ?"
        type = "bool"
        default = true

        [main.apticron_configuration.previous_apticron_hours]
        name = "When do you want to receive this email ?"
        type = "number"
        default = 20
        help = "Choose an hour between 12 and 23.<br>"

        [main.apticron_configuration.after_apticron]
        name = "Would you like to receive an email to verify if there any upgrades left after each auto upgrade ?"
        type = "bool"
        default = true

        [main.apticron_configuration.after_apticron_hour]
        name = "When do you want to receive this email ?"
        type = "number"
        default = 2
        help = "Choose an hour between 0 and 10."


    [main.periodic_configuration]
    name = "02periodic apt config file"

        [main.periodic_configuration.unattended_verbosity]
        name = "Choose the level of verbosity of Unattended-Upgrades mail"
        default = "1"
        type = "text"
        # choices = ["1", "2", "3"]
        help = "1: Progress report only.<br>2: Progress report and command outputs.<br>3: Progress report and command outputs and trace."


    [main.overwrite_files]
    name = "Overwriting config files"

        [main.overwrite_files.overwrite_periodic]
        name = "Overwrite the config file 02periodic ?"
        type = "bool"
        default = true
        help = "If the file is overwritten, a backup will be created."


    [main.global_config]
    name = "Global configuration"

        [main.global_config.email_type]
        name = "Send HTML email to admin ?"
        default = true
        type = "bool"
        help = "Allow app scripts to send HTML mails instead of plain text."

PR Status

Tested by me and working.

How to test

Install an app in which you have put a "config_panel.toml" file like in the example.

Validation

  • Principle agreement 0/2 : ljf
  • Quick review 0/1 :
  • Simple test 0/1 :
  • Deep review 0/1 :

@Psycojoker Psycojoker referenced this pull request Jun 1, 2019

Closed

[mod] switch to config_panel.yaml #718

0 of 4 tasks complete
@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

Looks clearly like an improvement, easier to read, easier to write.
I can't test though because of an error with ldap...

@Josue-T

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

I can't test though because of an error with ldap...

You should probably call the regen-conf to update the LDAP config

@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

After a regen-conf, sudo yunohost tools regen-conf, and a restart of the service, still the same error.

ERROR error during LDAP search operation with: base='ou=domains,dc=yunohost,dc=org', filter='virtualdomain=*', attrs=['virtualdomain'] and exception 'NoneType' object has no attribute 'search_s'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/moulinette/authenticators/ldap.py", line 135, in search
    result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs)
AttributeError: 'NoneType' object has no attribute 'search_s'
@Josue-T

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

ERROR error during LDAP search operation with: base='ou=domains,dc=yunohost,dc=org', filter='virtualdomain=*', attrs=['virtualdomain'] and exception 'NoneType' object has no attribute 'search_s'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/moulinette/authenticators/ldap.py", line 135, in search
    result = self.con.search_s(base, ldap.SCOPE_SUBTREE, filter, attrs)
AttributeError: 'NoneType' object has no attribute 'search_s'

Have you a the log before this because look like that the LDAP authentication failed

@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

The line before is 3082 DEBUG initialize authenticator 'as-root' with: uri='ldapi://%2Fvar%2Frun%2Fslapd%2Fldapi', base_dn='dc=yunohost,dc=org', user_rdn='gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth'

@Josue-T

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

Maybe all the log will help 🤔

@alexAubin

This comment has been minimized.

Copy link
Member

commented Jun 3, 2019

After a regen-conf, sudo yunohost tools regen-conf, and a restart of the service, still the same error.

Can you check that the moulinette is up to date as well ? This very much look like a bad version of one piece of software I believe

@Psycojoker

This comment has been minimized.

Copy link
Member Author

commented Jun 3, 2019

After a regen-conf, sudo yunohost tools regen-conf, and a restart of the service, still the same error.

Can you check that the moulinette is up to date as well ? This very much look like a bad version of one piece of software I believe

iirc, reading irc/xmpp (the discussion continued there) it was the problem, it's supposed to be solved now

@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

commented Jun 3, 2019

It was solved indeed. Not fully tested though because of other errors with the UX. Gave up after that.
But I trust you tests.

@zamentur
Copy link
Contributor

left a comment

LGTM (untested)

@alexAubin
Copy link
Member

left a comment

LGTM though untested

@alexAubin

This comment has been minimized.

Copy link
Member

commented Jun 24, 2019

Yolomergin' to move forward

@alexAubin alexAubin merged commit b1f5914 into stretch-unstable Jun 24, 2019

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@alexAubin alexAubin deleted the config_panel_toml branch Jun 24, 2019

@alexAubin alexAubin added this to the 3.6.x milestone Jun 24, 2019

@maniackcrudelis

This comment has been minimized.

Copy link
Contributor

commented Jul 15, 2019

[16:52:04] <Maniack_C> @bram, I'm currently trying the PR for config-panel, with some troubles
[16:52:26] <Maniack_C> I may have missed something
[16:52:34] <Maniack_C> I turn my json into a toml
[16:52:47] <Maniack_C> I use ynh_return instead of echo
[16:52:59] <Maniack_C> Still, the default value aren't use
[16:54:07] <Maniack_C> My config-panel.toml https://paste.yunohost.org/wejavasepi
[16:54:17] <Maniack_C> And the config script https://paste.yunohost.org/ahevaciyab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.