diff --git a/command_line_assistant/config/schemas.py b/command_line_assistant/config/schemas.py index 410ffc3..8264bad 100644 --- a/command_line_assistant/config/schemas.py +++ b/command_line_assistant/config/schemas.py @@ -11,6 +11,14 @@ class DatabaseSchema: """This class represents the [history.database] section of our config.toml file. + Notes: + If you are running MySQL or MariaDB in a container and want to test it + out, don't set the host to "localhost", but set it to "127.0.0.1". The + "localhost" will use the mysql socket connector, and "127.0.0.1" will + use TCP connector. + + Reference: https://stackoverflow.com/a/4448568 + Attributes: connection (str): The connection string. """ diff --git a/command_line_assistant/daemon/database/models/history.py b/command_line_assistant/daemon/database/models/history.py index a4cd62f..45c9f15 100644 --- a/command_line_assistant/daemon/database/models/history.py +++ b/command_line_assistant/daemon/database/models/history.py @@ -3,7 +3,7 @@ import uuid from datetime import datetime -from sqlalchemy import Column, DateTime, ForeignKey, Integer, String +from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Text from sqlalchemy.orm import relationship from command_line_assistant.daemon.database.models.base import GUID, BaseModel @@ -30,11 +30,11 @@ class InteractionModel(BaseModel): __tablename__ = "interaction" id = Column(GUID(), primary_key=True, default=uuid.uuid4) - query_text = Column(String) - query_role = Column(String, default="user") - response_text = Column(String) - response_role = Column(String, default="assistant") + query_text = Column(Text) + query_role = Column(String(4), default="user") + response_text = Column(Text) + response_role = Column(String(9), default="assistant") response_tokens = Column(Integer, default=0) - os_distribution = Column(String, default="RHEL") - os_version = Column(String, nullable=False) - os_arch = Column(String, nullable=False) + os_distribution = Column(String(4), default="RHEL") + os_version = Column(String(100), nullable=False) + os_arch = Column(String(7), nullable=False) diff --git a/data/release/xdg/config.toml b/data/release/xdg/config.toml index abeb85c..de48a8f 100644 --- a/data/release/xdg/config.toml +++ b/data/release/xdg/config.toml @@ -1,31 +1,71 @@ -[output] +# ------------------ experimental +# Experimental settings for output. Not yet working. +#[output] # otherwise recording via script session will be enforced -enforce_script = false +#enforce_script = false # file with output(s) of regular commands (e.g. ls, echo, etc.) -file = "/tmp/command-line-assistant/output.txt" +#file = "/tmp/command-line-assistant/output.txt" # Keep non-empty if your file contains only output of commands (not prompt itself) -prompt_separator = "$" +#prompt_separator = "$" +# ------------------ experimental +# History management configuration [history] +# If the history for all conversation should be enabled or not. By default, +# this is enabled and will store in a database defined under +# [history.database]. The conversation is stored per-user. enabled = true +# History Database settings. By default, sqlite is used. [history.database] +# Available types for databases are: sqlite, postgresql and mysql. Mariadb can +# be used as well with "mysql" type. type = "sqlite" +# Connection string refers to the path where the sqlite database will be +# placed. Only available with sqlite type. connection_string = "/var/lib/command-line-assistant/history.db" +# In order to use postgresql, uncomment the following settings: +# [history.database] +# type = "postgresql" +# host = "localhost" +# port = "5432" +# database = "history" +# user = "your-user" +# password = "your-password" + +# Or, to use mysql, uncomment the following: +# [history.database] +# type = "mysql" +# host = "localhost" +# port = "3306" +# database = "history" +# user = "your-user" +# password = "your-password" + +# Backend settings for communicating with the external API. [backend] +# The endpoint points to an API server. endpoint = "http://localhost:8080" +# Configure authentication settings for backend [backend.auth] -# cert_file = "/etc/pki/consumer/cert.pem" -# key_file = "/etc/pki/consumer/key.pem" -# verify_ssl = true - +# The path to the certificate file generated by RHSM. +cert_file = "/etc/pki/consumer/cert.pem" +# The path to the key file generated by RHSM. +key_file = "/etc/pki/consumer/key.pem" +# If SSL verification should be set. Don't disabled tihs for production server. +verify_ssl = true +# Logging configuration settings [logging] -level = "DEBUG" -responses = true # Global setting - don't log responses by default +# The default logging level for all messages logged by CLAD. +level = "INFO" +# Global setting to enable logging responses in an audit file and journald +responses = true +# Global setting to enable logging question in an audit file and journald question = true # Global setting - don't log questions by default -# User-specific settings +# User-specific settings that can override the global settings based on user name. +# Note: The user must exist in order for this to work. # users.admin = { responses = true, question = true } diff --git a/packaging/command-line-assistant.spec b/packaging/command-line-assistant.spec index 7142f6a..71d6de8 100644 --- a/packaging/command-line-assistant.spec +++ b/packaging/command-line-assistant.spec @@ -169,6 +169,7 @@ fi %changelog * Wed Jan 22 2025 Rodolfo Olivieri 0.2.0 +- Add String siez liimt to SQLAlchemy models - Add workaround for SQLite UUID types - Update packaging to include selinux custom policy - Fix returncode when running commands diff --git a/pdm.lock b/pdm.lock index 4d3498a..d174bb0 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["inherit_metadata"] lock_version = "4.5.0" -content_hash = "sha256:0766be8f03c0e5a45a024af107efc70f7b301f28f33351465bac1b7a33416a28" +content_hash = "sha256:f4824296123f6c8de494d892494900c0abf932856504d3e2bfa2d7d972ad1361" [[metadata.targets]] requires_python = ">=3.9" @@ -644,13 +644,13 @@ files = [ [[package]] name = "pygments" -version = "2.18.0" +version = "2.19.1" requires_python = ">=3.8" summary = "Pygments is a syntax highlighting package written in Python." groups = ["dev"] files = [ - {file = "pygments-2.18.0-py3-none-any.whl", hash = "sha256:b8e6aca0523f3ab76fee51799c488e38782ac06eafcf95e7ba832985c8e7b13a"}, - {file = "pygments-2.18.0.tar.gz", hash = "sha256:786ff802f32e91311bff3889f6e9a86e81505fe99f2735bb6d60ae0c5004f199"}, + {file = "pygments-2.19.1-py3-none-any.whl", hash = "sha256:9ea1544ad55cecf4b8242fab6dd35a93bbce657034b0611ee383099054ab6d8c"}, + {file = "pygments-2.19.1.tar.gz", hash = "sha256:61c16d2a8576dc0649d9f39e089b5f02bcd27fba10d8fb4dcc28173f7a45151f"}, ] [[package]] @@ -834,7 +834,7 @@ files = [ [[package]] name = "responses" -version = "0.25.3" +version = "0.25.6" requires_python = ">=3.8" summary = "A utility library for mocking out the `requests` Python library." groups = ["dev"] @@ -844,8 +844,8 @@ dependencies = [ "urllib3<3.0,>=1.25.10", ] files = [ - {file = "responses-0.25.3-py3-none-any.whl", hash = "sha256:521efcbc82081ab8daa588e08f7e8a64ce79b91c39f6e62199b19159bea7dbcb"}, - {file = "responses-0.25.3.tar.gz", hash = "sha256:617b9247abd9ae28313d57a75880422d55ec63c29d33d629697590a034358dba"}, + {file = "responses-0.25.6-py3-none-any.whl", hash = "sha256:9cac8f21e1193bb150ec557875377e41ed56248aed94e4567ed644db564bacf1"}, + {file = "responses-0.25.6.tar.gz", hash = "sha256:eae7ce61a9603004e76c05691e7c389e59652d91e94b419623c12bbfb8e331d8"}, ] [[package]] @@ -1201,7 +1201,7 @@ files = [ [[package]] name = "virtualenv" -version = "20.28.0" +version = "20.29.1" requires_python = ">=3.8" summary = "Virtual Python Environment builder" groups = ["dev"] @@ -1212,8 +1212,8 @@ dependencies = [ "platformdirs<5,>=3.9.1", ] files = [ - {file = "virtualenv-20.28.0-py3-none-any.whl", hash = "sha256:23eae1b4516ecd610481eda647f3a7c09aea295055337331bb4e6892ecce47b0"}, - {file = "virtualenv-20.28.0.tar.gz", hash = "sha256:2c9c3262bb8e7b87ea801d715fae4495e6032450c71d2309be9550e7364049aa"}, + {file = "virtualenv-20.29.1-py3-none-any.whl", hash = "sha256:4e4cb403c0b0da39e13b46b1b2476e505cb0046b25f242bee80f62bf990b2779"}, + {file = "virtualenv-20.29.1.tar.gz", hash = "sha256:b8b8970138d32fb606192cb97f6cd4bb644fa486be9308fb9b63f81091b5dc35"}, ] [[package]] diff --git a/podman-compose.yaml b/podman-compose.yaml index ebc1783..8a6ea65 100644 --- a/podman-compose.yaml +++ b/podman-compose.yaml @@ -1,22 +1,38 @@ version: "3" services: - mock-server: - image: mockoon/cli:latest - command: ["--data", "data", "--port", "3000"] - healthcheck: - test: ["CMD-SHELL", "curl -f http://localhost:3000/your-healthcheck-route || exit 1"] - interval: 30s - timeout: 5s - retries: 2 - start_period: 10s + postgres: + image: postgres + shm_size: 128mb + environment: + POSTGRES_PASSWORD: cla + POSTGRES_DB: history ports: - - 3000:3000 - volumes: - - ./mocks/mockoon/routes.json:/data:Z - networks: - - demo + - 5432:5432 -networks: - demo: - driver: bridge + mariadb: + image: mariadb + environment: + MARIADB_ROOT_PASSWORD: cla + MARIADB_DATABASE: history + ports: + - 3306:3306 + expose: + - 3306 + + mysql: + image: mysql + environment: + MYSQL_ROOT_PASSWORD: cla + MYSQL_DATABASE: history + ports: + - 3306:3306 + expose: + - 3306 + + # Inspect DB + adminer: + image: adminer + restart: always + ports: + - 8080:8080 diff --git a/pyproject.toml b/pyproject.toml index fe69956..2a0ce0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,11 @@ scripts = { c = "command_line_assistant.initialize:initialize", clad = "command_ requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" -[dependency-groups] +[project.optional-dependencies] +db = [ + "psycopg2>=2.9.10", + "mysqlclient>=2.2.7", +] dev = [ "pytest==8.3.4", "pytest-cov==6.0.0", diff --git a/tests/conftest.py b/tests/conftest.py index 140a724..c00c247 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -70,7 +70,8 @@ def mock_config(tmp_path): ), ), history=HistorySchema( - enabled=True, database=DatabaseSchema(connection_string=history_db) + enabled=True, + database=DatabaseSchema(type="sqlite", connection_string=history_db), ), logging=LoggingSchema( level="debug",