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

feat: add DB initialization module #556

Merged
merged 25 commits into from
Feb 7, 2024
Merged

feat: add DB initialization module #556

merged 25 commits into from
Feb 7, 2024

Conversation

7flying
Copy link
Contributor

@7flying 7flying commented Sep 29, 2023

This provides an interface defining the methods that we expect to be used for OV handling operations.

Added an implementation for sqlite and postgress. I have been unable to make the implementation more generic (aka just one definition of each of the functions of the lib) with a trait with two generic types instead of one, because the Connection trait (which holds SqliteConnection and PgConnection) cannot be made into an object. But I'm happy to learn how to refactor it if someone has ideas.

Added db creation files and tests, the PR is marked as draft since I still need to wire the tests to our upstream CI, making just the sqlite dependencies required, we don't want to install a postgresql server.

Update: This also adds the capability to select the DB storage method in the relevant server configuration files, the store interface implementation, and two new functions in the fdo-owner-cli in order to export OVs from the manufacturing server and import OVs into the owner-onboarding server.

@7flying 7flying force-pushed the db-init branch 16 times, most recently from 1ae2321 to 228bc45 Compare October 2, 2023 15:58
@7flying 7flying marked this pull request as ready for review October 2, 2023 15:58
db/Cargo.toml Outdated Show resolved Hide resolved
Copy link
Contributor

@djach7 djach7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm, reviewed for English conventions and with limited Rust knowledge.

@7flying 7flying force-pushed the db-init branch 2 times, most recently from 718e550 to 7585e98 Compare October 3, 2023 09:24
db/Cargo.toml Show resolved Hide resolved
db/src/lib.rs Outdated Show resolved Hide resolved
migrations_sqlite/2023-09-07-131701_create_db/up.sql Outdated Show resolved Hide resolved
@7flying
Copy link
Contributor Author

7flying commented Oct 3, 2023

Moving this PR back to draft since we need separate sql initialization files.

db/src/schema.rs Outdated Show resolved Hide resolved
@7flying
Copy link
Contributor Author

7flying commented Oct 11, 2023

Updated, there are now three different databases.

Build/tests blocked until puiterwijk/rust-openssl-kdf#16 goes in and a new release is made.

Copy link
Contributor

@say-paul say-paul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

7flying and others added 25 commits February 7, 2024 09:15
The `StoredItem` struct is no longer needed just in the rendezvous server, we
are making it public and moving it to the data-formats lib so that it can be
easily included in other modules.

Signed-off-by: Irene Diez <[email protected]>
This provides an interface defining the methods
that we expect to be used for OV handling operations.

Added an implementation for sqlite and postgress.

Added db creation files and tests.

Signed-off-by: Irene Diez <[email protected]>
Adds new dependencies and creates a sqlite database to be used in the tests.

Signed-off-by: Irene Diez <[email protected]>
This adds the store interface methods for the SqliteManufacturerStore.

Signed-off-by: Irene Diez <[email protected]>
This adds the store trait for the Sqlite Owner DB.

Signed-off-by: Irene Diez <[email protected]>
This implements the store trait for the Sqlite Rendezvous DB.

Signed-off-by: Irene Diez <[email protected]>
When selecting to use the DB as the store type in the configuration files, this
requires to select the DB type (sqlite or postgres) and the server type.

Signed-off-by: Irene Diez <[email protected]>
When we are trying to parse raw data to make an ownership voucher
we did not check whether the slice was empty or not, causing a
panic in such case.
This change explicitly checks if the slice is empty or not, and
in the former case returns an error.

Signed-off-by: Irene Diez <[email protected]>
This adds the `export_manufacturer_vouchers` option to the Owner CLI, which
allows to export OVs from the Manufacturer Server's DB to a directory. The
options are to export a single OV by GUID or all of them.

Updated the DB trait to add the `select *` query that yields all the OVs in the
Manufacturer.

Signed-off-by: Irene Diez <[email protected]>
We are going to propagate the errors unless those are related
to getting a connection to the DB.

Signed-off-by: Irene Diez <[email protected]>
The `query_data` method makes no sense when using databases since it uses
different types of lists to query the required data, when that's a single query
in a database; thereby we are adding the `query_ovs_db` method which explicitly
queries the required data from the database.

We are also adding a new error type `StoreError::MethodNotAvailable` that will
be yielded when we call `query_data` from a database store implementation, or
when we call the new `query_ovs_db` method from a directory store
implementation.

Signed-off-by: Irene Diez <[email protected]>
When the Owner server needs to report OVs to the Rendezvous server, check
whether we have the old `query_data` method available or the new `query_ovs_db`
method to choose the most effective one.

Signed-off-by: Irene Diez <[email protected]>
Replace all the `StoreError::Unspecified` errors with the new
`StoreError::Database` when there is an internal database error.

Signed-off-by: Irene Diez <[email protected]>
This changes the filters so that they correctly take into account NULL values.
In order to set a NULL value we need to use None in rust, but for filtering
instead of using None we need to filter by `is_null()`.

Signed-off-by: Irene Diez <[email protected]>
This changes the `store_data` method so that it expects a Value of type
`StoredItem` for the serialization and deserialization of data.

Signed-off-by: Irene Diez <[email protected]>
Since the migrations are unified in a single folder the tests have been updated
accordingly.

Signed-off-by: Irene Diez <[email protected]>
Adds sqlite and libpq crates to devcontainer creation
for successful building and testing in dev container.
Also adds diesel scripts to dev container build to
enable successful dev container integration testing.

Signed-off-by: djach7 <[email protected]>
Signed-off-by: Irene Diez <[email protected]>
@runcom runcom merged commit 072e027 into fdo-rs:main Feb 7, 2024
15 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants