doublevcodes / sirius

Create APIs that shine like a star ✨
https://doublevcodes.github.io/sirius
11 stars 2 forks source link

Configuration system #4

Closed doublevcodes closed 2 years ago

doublevcodes commented 2 years ago

The user needs to be able to set options within a sirius.config.toml file. This will be implemented using tomli

Shivansh-007 commented 2 years ago

I would like to work on this, it would be based on the work done by arl on discord-modmail/modmail#75, where one could write configuration classes using marshmallow and attrs. This would support auto-generation of docs in the config file.

Example:

@attr.s(auto_attribs=True, slots=True)
class TwitterAuthCfg:
    """Twitter account authentication configuration."""

    api_key: str = attr.ib(
        default="",
        on_setattr=attr.setters.frozen,
        repr=False,
        metadata={
            "required": True,
            "allow_none": False,
            METADATA_TABLE: ConfigMetadata(
                description="Think of this as the user name that represents your account when using the app.",
            ),
        },
    )
    api_secret: str = attr.ib(
        default="",
        on_setattr=attr.setters.frozen,
        repr=False,
        metadata={
            "required": True,
            "allow_none": False,
            METADATA_TABLE: ConfigMetadata(
                description="Think of this as the password that represents your account when using the app.",
            ),
        },
    )

Would auto-generate:

[auth]
# Think of this as the user name that represents your account when using the app.
api_key = ""
# Think of this as the password that represents your account when using the app.
api_secret = ""
doublevcodes commented 2 years ago

So how would this work, a default configuration is generated with lots of empty keys? I'd prefer that the configuration file only contain keys that need to be used.

Shivansh-007 commented 2 years ago

So how would this work, a default configuration is generated with lots of empty keys? I'd prefer that the configuration file only contain keys that need to be used.

Yes, it would only include the config keys which are required, and possibly I could add a separate flag if the user wants to generate with "all" of the keys.

doublevcodes commented 2 years ago

So how would this work, a default configuration is generated with lots of empty keys? I'd prefer that the configuration file only contain keys that need to be used.

Yes, it would only include the config keys which are required, and possibly I could add a separate flag if the user wants to generate with "all" of the keys.

That sounds good.

So:

Shivansh-007 commented 2 years ago

Should be closed by #6