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

Ingest adds keyhash to files db table #1073

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

MalinAhlberg
Copy link
Contributor

@MalinAhlberg MalinAhlberg commented Oct 4, 2024

Related issue(s) and PR(s)
This PR closes #893.
It will be undrafted when #1036 is closed.

Commit tmp: temporary fixes to api/hash will not be included in the final version of this PR.

Description

  • ingest hex encodes the user's public key and adds it to the files info in the sda.files table
  • if the keyhash is not in the sda.encryption_keys, an error is thrown and ingest stops
  • code test and integration test are added

How to test
Add the hashed public key to sda.encryption_keys and then try to ingest a file. See the integration test for details.

@MalinAhlberg MalinAhlberg force-pushed the feature/ingest-add-keyhash branch 5 times, most recently from ecec008 to ceecb05 Compare October 9, 2024 09:05
@kostas-kou kostas-kou mentioned this pull request Oct 14, 2024
@jbygdell
Copy link
Collaborator

This PR should not have to be dependent on #1036

@MalinAhlberg
Copy link
Contributor Author

This PR should not have to be dependent on #1036

It's the tests (eg here). It could have been implemented without this dependecy, but I thought it was nice to test the intended workflow.

@MalinAhlberg MalinAhlberg force-pushed the feature/ingest-add-keyhash branch 6 times, most recently from ca919ba to 910a2db Compare October 21, 2024 12:00
@MalinAhlberg MalinAhlberg marked this pull request as ready for review October 21, 2024 13:18
@jbygdell jbygdell force-pushed the feature/api-keys branch 5 times, most recently from 440b590 to b488b73 Compare October 22, 2024 06:19
Base automatically changed from feature/api-keys to main October 22, 2024 10:14
@MalinAhlberg MalinAhlberg requested a review from a team October 22, 2024 11:27
sda/cmd/ingest/ingest.go Show resolved Hide resolved
sda/internal/database/db_functions.go Outdated Show resolved Hide resolved
sda/internal/database/db_functions_test.go Outdated Show resolved Hide resolved
sda/internal/database/db_functions.go Outdated Show resolved Hide resolved
sda/internal/database/db_functions_test.go Show resolved Hide resolved
postgresql/initdb.d/04_grants.sql Outdated Show resolved Hide resolved
.github/integration/tests/sda/11_api-getfiles_test.sh Outdated Show resolved Hide resolved
.github/integration/tests/sda/20_ingest-verify_test.sh Outdated Show resolved Hide resolved
@MalinAhlberg MalinAhlberg self-assigned this Oct 23, 2024
Copy link
Contributor

@kostas-kou kostas-kou left a comment

Choose a reason for hiding this comment

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

Very good job. Just an extremely minor thing, in the PR's description I would change the part saying that it prints a warning if the keyhash does not exist in the sda.encryption_keys table because in reality it will through an error. I know that maybe is too much but my eye caught it :)

@MalinAhlberg
Copy link
Contributor Author

MalinAhlberg commented Oct 25, 2024

Very good job. Just an extremely minor thing, in the PR's description I would change the part saying that it prints a warning if the keyhash does not exist in the sda.encryption_keys table because in reality it will through an error. I know that maybe is too much but my eye caught it :)

Thanks @kostas-kou! The description was indeed outdated, very good that you noticed! It's updated now.

exit 1
fi

apt-get -o DPkg::Lock::Timeout=60 update >/dev/null
Copy link
Contributor

Choose a reason for hiding this comment

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

It is inefficient and waste of time to (potentially) run apt-get update multiple times. It can be refactored to run apt-get update only once.

echo "ingestion and verification test completed successfully"
# check that the files have key hashes assigned
key_hashes="$(psql -U postgres -h postgres -d sda -At -c "select distinct key_hash from sda.files" | wc -l)"
if [ "$key_hashes" -lt 0 ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if [ "$key_hashes" -lt 0 ]; then
if [ "$key_hashes" -eq 0 ]; then

Copy link
Contributor

Choose a reason for hiding this comment

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

The result of wc -l can never be negative.

err = db.SetKeyHash(keyhash, fileID)
if err != nil {
log.Errorf("Key hash %s could not be set for fileID %s: (%s)", keyhash, fileID, err.Error())
if err = delivered.Nack(false, true); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would use a different variable name for the inner err to increase the clarity. However, maybe this not inline with the style of sda? What do others think?


return err
}
if rowsAffected, _ := result.RowsAffected(); rowsAffected == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why ignore the potentially returned error message?

Copy link
Contributor

@nanjiangshu nanjiangshu left a comment

Choose a reason for hiding this comment

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

Looks good. I added a few comments in the integrations test shell scripts and some questions regarding error handling in the go code.

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.

[ingest] Add key hash to database table
4 participants