alexandrainst / alexandra-ml-template

Template for Python-based data science projects in the Alexandra Institute.
https://alexandra.dk/
MIT License
8 stars 1 forks source link

Problem when the user has more than one GPG key #6

Closed bourdeet closed 6 days ago

bourdeet commented 9 months ago

For some reason I had installed more than one GPG key on my machine, this meant that the output of the following command in the makefile (line 75, ommitting the last pipe):

gpg --list-secret-keys --keyid-format=long | grep sec

returned something like:

sec   rsa3072/[KEY_ID_1] 2020-01-01 [SC]
sec   rsa3072/[KEY_ID_2] 2021-01-03 [SC]

As a result, the last pipe that uses regex to retrieve the key ID actually returns a string that looks line

[KEY_ID_1] \n
[KEY_ID_2] 

and includes therefore a newline character, which breaks the subsequent configuration of the .env file.

A possible fix could be to add ;q to the existing regex, such that the command prints out the first available GPG key by default

peterbjorgensen commented 9 months ago

What does ;q do? Would it work if we do | grep -m 1 sec to only get the first match. I am not an expert in using GPG keys, and I am not sure where GPG_KEY_ID here gets set? https://github.com/alexandrainst/alexandra-ml-template/blob/040f85062cd236a16e340274626bb2656ee7911e/%7B%7Bcookiecutter.project_name%7D%7D/makefile#L96C10-L96C20

bourdeet commented 8 months ago

Actually ;qis a sed-related command that tells the program to quit after the first find. Another way of achieving the same result would be:

 grep sec | sed -E 's/.*\/([^ ]+).*/\1/' | head -n 1

You can test this uing the foolwing line:

echo "sec   rsa3072/[KEY_ID_1] 2020-01-01 [SC]
sec   rsa3072/[KEY_ID_2] 2021-01-03 [SC]" | grep sec | sed -E 's/.*\/([^ ]+).*/\1/' | head -n 1
saattrupdan commented 6 days ago

Fixed by removing all GPG-related things, as they caused way too many issues.