(Migrated) Store and retrieve service attributes

(This message has been automatically imported from the retired mailing list)


We have built a tiny access control system based on service name and
client credentials
(it just checks if there’s a match in the access matrix),
we would like to group services in order to be able to enable/disable
access on a group of services for a client.
The AC server has its own separate database (Zato has no access to that).

Our AC server retrieves the list of services from Zato using the public API,
I’m currently looking for a way to define group membership in the source
code of a service and retrieve it through Zato.

One solution could be to retrieve the source code for each service and
parse for a ‘group’ variable, but that’s kind of dirty and I would like
to check if there’s a more elegant solution to this.

Another solution would be to populate some database in
before_add_to_store() (assuming we have database [or kvdb] access in
that method). A downside of this is that we would have to deploy a
service to retrieve the service groups (or retrieve it directly from the
db which is not ideal either).

So there are a couple of possibilities, but I am looking for the
absolute super-elegant one :smiley:
Any ideas?


On 29/06/15 16:22, Andrea Peter wrote:

So there are a couple of possibilities, but I am looking for the
absolute super-elegant one :smiley:

Hi Andrea,

until this is implemented …


… the cleanest way is to iterate over services currently deployed on a
given server, which you already do, and for each one grab live Python
objects whose ‘group’ attribute you can consult in your code.

from zato.server.service import Service

class MyService(Service):

def handle(self):
    for data in self.server.service_store.services.values():

        # service_class is a live Python object
        service_class = data['service_class']