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

Is OPLOG supported? #194

Open
tallesl opened this issue Apr 24, 2019 · 5 comments
Open

Is OPLOG supported? #194

tallesl opened this issue Apr 24, 2019 · 5 comments

Comments

@tallesl
Copy link

tallesl commented Apr 24, 2019

https://docs.python-eve.org/en/stable/features.html#operations-log

@dkellner
Copy link
Collaborator

I've never tried it. But I've skimmed through the code in Eve and it seems it is independent of the datalayer anyway.

So you could try to manually configure an appropriate model and setting the OPLOG_* settings accordingly. If this works, we can add an example to the docs or think about including that oplog model in our codebase.

@opensorceror
Copy link

opensorceror commented Feb 15, 2021

@tallesl Did you happen to get this to work? If I simply enable OPLOG in the Eve settings, it doesn't seem to work (no error messages either).

@opensorceror
Copy link

Update: Looks like I'm hitting this bug, which seems to have been fixed in eve 0.8.

@dkellner The latest release of eve-sqlalchemy requires eve < 0.8, which was released in 2018. Any plans to support a newer version of eve?

@opensorceror
Copy link

opensorceror commented Feb 15, 2021

Got this to work. Posting it here, in case it helps anyone. Had to do the following:

  1. Had to fork Eve 0.7.10 (the latest version supported by eve-sqlalchemy) and and integrate this fix into my fork.
  2. Unfortunately, eve hardcodes the oplog schema, so even after defining the model using sqlalchemy, eve would simply overwrite the schema and consequently fail. I had to add a on_oplog_push hook to re-overwrite the schema.

My final configs look as follows:

Sqlalchemy model:

class CommonColumns(Base):
    """Common columns"""

    __abstract__ = True
    _created = Column(TIMESTAMP, default=func.now())
    _updated = Column(TIMESTAMP, default=func.now(), onupdate=func.now())

class Oplog(CommonColumns):
    """Model that stores operational logs"""

    __tablename__ = "oplog"
    o = Column(String(10))
    r = Column(String(100))
    i = Column(String(36), primary_key=True)
    c = Column(JSON)
    ip = Column(String(50))
    u = Column(String(50))

App settings:

DOMAIN = DomainConfig({"oplog": ResourceConfig(Oplog)}).render()
IF_MATCH = False
HATEOAS = False

# Oplog
OPLOG = True
OPLOG_CHANGE_METHODS = ['PATCH', 'PUT', 'DELETE', 'POST']
OPLOG_AUDIT = True
OPLOG_NAME = "oplog"

Oplog push hook:

def oplog_extras(resource, entries):
    schema = DOMAIN['oplog']['schema']

    app.config["DOMAIN"]['oplog']["schema"] = schema

app.on_oplog_push += oplog_extras

@dkellner
Copy link
Collaborator

@dkellner The latest release of eve-sqlalchemy requires eve < 0.8, which was released in 2018. Any plans to support a newer version of eve?

I'd be happy to provide compatibility for newer Eve versions, but my personal dev time is limited and I'm not able to use Eve-SQLAlchemy anymore at work. If anyone steps in and does the necessary work, I'd be happy to provide some guidance and review.

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

No branches or pull requests

3 participants