-
Notifications
You must be signed in to change notification settings - Fork 8
CLAD
CLAD (or Command Line Assistant Daemon) is our systemd managed process that is used to communicate with our backend services. CLAD itself is small and only do a few operations.
- Read certificate file from RHSM
- Log information to journald
- Communicate with external backend (API)
- Handle user history (conversation cache)
CLAD is an important piece for the success of Command Line Assistant project itself as it leverages all the power and core functionalities to a single piece of program running via systemd where the system administrators can set access configurations for their users.
CLAD uses dbus as his IPC to communicate and receive commands from the client. Everything passes through CLAD and the final data/representation is exihibit in the client.
flowchart LR
Client
D-Bus
Daemon
Client --> D-Bus --> Daemon
CLAD implements two different interfaces, one for the query
commands and the
other for history
commands.
Those two interfaces are used to separate the concerns between the main commands that the client can operate with. Each of the interfaces implements their own methods to handle the specific use cases.
For the query
interface, it will usually live in the following namespace:
- com.redhat.lightspeed.query
And for the history
interface, it will usually live in the following
namespace:
- com.redhat.lightspeed.history
To find more about the other dbus methods and structures, you can check it out in our docs here: https://command-line-assistant.readthedocs.io/en/latest/dbus/index.html
For a more general information about the development environment, please check out our wiki about Development Environment.
This section will talk more about the special tricks and tweaks we can do to run CLAD in our development machines.
To execute CLAD through systemd, you can use the make commands that will handle all the operation changes that needs to be in place for you.
To do that, simply run the following command:
make link-systemd-units
This command will do the following operations:
- Read the systemd devel file
- Replace the keywords inside the devel file to mock paths
- Create a systemd "user" file
- Link that user file to the systemd unit user folder
This systemd "user" file is created with some tweaks and modifications from the original devel one that points to the development configuration file in your project, and a special systemd bus address.
When systemd runs our daemon, it will assign the default
$DBUS_SYSTEM_BUS_ADDRESS
when the application starts, althought this is fine
for a production environment, in a development one we would need to maintain
policy files and other configurations to make it run normally in our system.
Since this is a lot of work and trouble, we are doing a special tweak to the
systemd devel file that is the following:
...
Environment="DBUS_SYSTEM_BUS_ADDRESS=unix:path=/run/user/1000/bus"
...
This overwrites the default system bus address and points it to a session bus instead. The reason that we do this is to avoid managing policy files and requiring root privileges in the development environment. As long as this is done locally, it doesn't affect anything else of the product itself.
Important
Never, ever, push that tweak to the release systemd file. This can lead to a security vulnerability in the user system.
To run CLAD locally, we simple need to launch a new (and temporary) system bus address, and add it to the environment of CLAD.
First, start with the following command:
dbus-launch
Which will output something along the lines of:
rolivier@fedora:~/Workspace/command-line-assistant$ dbus-launch
DBUS_SESSION_BUS_ADDRESS=unix:path=/tmp/dbus-31VRAcNbSv,guid=40e4ce5f9dec7be32c9156ce6772f525
DBUS_SESSION_BUS_PID=16751
DBUS_SESSION_BUS_WINDOWID=20971521
The important piece of information in the above output is the first variable,
the $DBUS_SESSION_BUS_ADDRESS
.
Simply copy and either export this variable or add it to the same line before running CLAD, like so:
export DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/dbus-31VRAcNbSv,guid=40e4ce5f9dec7be32c9156ce6772f525
make clad
Or, like this:
DBUS_SYSTEM_BUS_ADDRESS=unix:path=/tmp/dbus-31VRAcNbSv,guid=40e4ce5f9dec7be32c9156ce6772f525 make clad