eclecticiq / OpenTAXII

TAXII server implementation in Python from EclecticIQ
BSD 3-Clause "New" or "Revised" License
185 stars 88 forks source link

OpenTaxii + Postgresql DB configuration throws up 'Invalid argument(s) ..., using configuration PGDialect_psycopg2/QueuePool/Engine #248

Closed pratyushb closed 1 year ago

pratyushb commented 1 year ago

I have been trying to setup an openTaxii server with a postgresql DB running on the same box. I have the following configuration file (defaults.yml):

---

domain: "localhost:9000"

support_basic_auth: no
return_server_error_details: no

auth_api:
  class: opentaxii.persistence.sqldb.SQLDatabaseAPI
  parameters:
    db_connection: postgresql://opentaxii:**********@localhost:5432/opentaxii
    create_tables: yes
    secret: some-secret-key
    token_ttl_secs: 3600

taxii1:
  save_raw_inbox_messages: no
  xml_parser_supports_huge_tree: yes
  count_blocks_in_poll_responses: no
  unauthorized_status: UNAUTHORIZED
  hooks:
  persistence_api:
    class: opentaxii.persistence.sqldb.SQLDatabaseAPI
    parameters:
      db_connection: postgresql://opentaxii:*******@localhost:5432/opentaxii
      create_tables: yes

taxii2:

logging:
  opentaxii: info
  root: info

however, every time I try to startup the server or use opentaxii-sync-data, I am coming across the following error:

2022-12-01T17:36:12.571131Z [opentaxii.utils] info: api.initialized {api=opentaxii.persistence.sqldb.SQLDatabaseAPI}
2022-12-01T17:36:12.571381Z [opentaxii.server] info: opentaxii.server_configured 
Traceback (most recent call last):
  File "/usr/local/bin/opentaxii-sync-data", line 11, in <module>
    load_entry_point('opentaxii==0.9.3', 'console_scripts', 'opentaxii-sync-data')()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 490, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2854, in load_entry_point
    return ep.load()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
    return self.resolve()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/usr/local/lib/python3.8/dist-packages/opentaxii-0.9.3-py3.8.egg/opentaxii/cli/__init__.py", line 10, in <module>
    server = TAXIIServer(config)
  File "/usr/local/lib/python3.8/dist-packages/opentaxii-0.9.3-py3.8.egg/opentaxii/server.py", line 879, in __init__
    server=self, api=initialize_api(config["auth_api"])
  File "/usr/local/lib/python3.8/dist-packages/opentaxii-0.9.3-py3.8.egg/opentaxii/utils.py", line 41, in initialize_api
    instance = cls(**params)
```  File "/usr/local/lib/python3.8/dist-packages/opentaxii-0.9.3-py3.8.egg/opentaxii/common/sqldb.py", line 16, in __init__
    self.db = SQLAlchemyDB(
  File "/usr/local/lib/python3.8/dist-packages/opentaxii-0.9.3-py3.8.egg/opentaxii/sqldb_helper.py", line 28, in __init__
    self.engine = engine.create_engine(db_connection, **kwargs)
  File "<string>", line 2, in create_engine
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/util/deprecations.py", line 309, in warned
    return fn(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/sqlalchemy/engine/create.py", line 636, in create_engine
    raise TypeError(
TypeError: Invalid argument(s) 'secret','token_ttl_secs' sent to create_engine(), using configuration PGDialect_psycopg2/QueuePool/Engine.  Please check that the keyword arguments are appropriate for this combination of components.

NOTE: this works fine if I am using the default sqllite config!

I could not find much documentation on the web on this, so any information/response would be really helpful!

pratyushb commented 1 year ago

For reference, I am running the following versions of dependencies:

PyJWT~=2.4.0
structlog~=22.1.0
opentaxii~=0.9.3
SQLAlchemy~=1.4.40
Werkzeug~=2.2.2
pratyushb commented 1 year ago

Apologies, I figured out the problem, this was due to a misconfiguration for the auth_api class on my part:

I had mistakenly set it to class: opentaxii.persistence.sqldb.SQLDatabaseAPI instead of: class: opentaxii.auth.sqldb.SQLDatabaseAPI

With this setting corrected, everything works fine. I will close this issue now! Again apologies for this..