python-microservices / pyms

Library of utils to create REST Python Microservices
https://python-microservices.github.io/home/
GNU General Public License v3.0
265 stars 45 forks source link

Add a `enabled` key on configuration of every service #217

Closed alexppg closed 3 years ago

alexppg commented 3 years ago

Is your feature request related to a problem? Please describe. It's uncomfortable to know that a service is loaded. You have to assume that if it exists in the configuration, it's loaded, but you can't really be sure. Also, the only way to deactivate it is to delete it from the configuration.

Describe the solution you'd like Add a enabled key on every service, that pyms uses to load (or not) the service. I think it's easier to understand and to use any service if you can activate it and deactivated just changing the enabled key.

Change the next configuration:

pyms:
  services:
    requests:
      data: ""
    swagger:
      path: ""
      file: "swagger.yaml"

To:

pyms:
  services:
    requests:
      enabled: true
      data: ""
    swagger:
      enabled: false
      path: ""
      file: "swagger.yaml"

So the requests service is enabled, but the swagger is not.

avara1986 commented 3 years ago

This option already exists :smile:

https://github.com/python-microservices/pyms/blob/d4e8683e5f9f4a0a2cea6fc408e1616136381995/pyms/flask/services/driver.py#L68

alexppg commented 3 years ago

What does defined self.enabled? I only see this: https://github.com/python-microservices/pyms/blob/aefb690659ff9a6529a3249e50ad150e3589f066/pyms/flask/services/driver.py#L51

How can you change its value?

avara1986 commented 3 years ago

It's magic :stuck_out_tongue:

DriverService has this method:

https://github.com/python-microservices/pyms/blob/aefb690659ff9a6529a3249e50ad150e3589f066/pyms/flask/services/driver.py#L46

When you "call" an attribute, DriverService searchs in self.config, and self.config contains the key-values ​​that you've defined in your config.yaml for this service. Therefore, each key in your config.yaml is an attribute of your Service

alexppg commented 3 years ago

I see. So if we add a if self.service.enabled: in all the init_$service methods, we would make it a de facto standard, don't we? Do you agree with doing that?

avara1986 commented 3 years ago

But each service has an enabled attribute, that inherits from DriverService

https://github.com/python-microservices/pyms/blob/d4e8683e5f9f4a0a2cea6fc408e1616136381995/pyms/flask/services/driver.py#L40

Or sorry if i didn't understand the proposal, what do you mean? Thanks @alexppg :)

alexppg commented 3 years ago

Oh, I see. So just to clarify, if I do:

pyms:
  services:
    requests:
      enabled: true
      data: ""
    swagger:
      enabled: false
      path: ""
      file: "swagger.yaml"

The swagger service won't be loaded?

avara1986 commented 3 years ago

yes it is :smile: the service won't be loaded :+1:

alexppg commented 3 years ago

Nice! Then I'll just close it.