aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-09-10 16:04:53 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2021-09-10 16:04:53 -0400
commit2613bae14352346cabcd66688366ebfaff959aa5 (patch)
treefa7dadbefe597a71e38ae9987c31773a2dcc736a
parent89006ede71f146004240978621dda9a6753992d9 (diff)
downloadpatatt-2613bae14352346cabcd66688366ebfaff959aa5.tar.gz
Add patatt install-hook subcommandv0.4.7
Make it easy to enable a repo for signing. Instead of reading the manpage and finding the commands to add to the sendemail-validate hook, add a subcommand that will do it for you. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--README.rst7
-rw-r--r--man/patatt.521
-rw-r--r--man/patatt.5.rst14
-rw-r--r--patatt/__init__.py22
4 files changed, 55 insertions, 9 deletions
diff --git a/README.rst b/README.rst
index de299d1..7135b9f 100644
--- a/README.rst
+++ b/README.rst
@@ -182,7 +182,12 @@ You can now validate your own message::
Automatic signing via the sendemail-validate hook
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
If everything is working well, you can start automatically signing all
-outgoing patches sent via git-send-email::
+outgoing patches sent via git-send-email. Inside the repo you want enabled
+for signing, run::
+
+ $ patatt install-hook
+
+Or you can do it manually::
$ echo 'patatt sign --hook "${1}"' > "$(git rev-parse --git-dir)/hooks/sendemail-validate"
$ chmod a+x "$(git rev-parse --git-dir)/hooks/sendemail-validate"
diff --git a/man/patatt.5 b/man/patatt.5
index 1e46a8a..841f670 100644
--- a/man/patatt.5
+++ b/man/patatt.5
@@ -1,6 +1,6 @@
.\" Man page generated from reStructuredText.
.
-.TH PATATT 5 "2021-05-21" "0.4.0" ""
+.TH PATATT 5 "2021-09-10" "0.4.7" ""
.SH NAME
PATATT \- DKIM-like cryptographic patch attestation
.
@@ -32,7 +32,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
..
.SH SYNOPSIS
.sp
-patatt {sign,validate,genkey} [options]
+patatt {sign,validate,genkey,install\-hook} [options]
.SH DESCRIPTION
.sp
This tools allows cryptographically signing patches sent via email
@@ -75,7 +75,20 @@ end.
.SH USING AS A GIT HOOK
.sp
If you use \fBgit\-send\-email\fP for sending patches, then you can get
-them automatically signed via the \fBsendemail\-validate\fP hook:
+them automatically signed via the \fBsendemail\-validate\fP hook. To install,
+run the following command in the repository you want enabled for signing:
+.INDENT 0.0
+.INDENT 3.5
+.sp
+.nf
+.ft C
+$ patatt install\-hook
+.ft P
+.fi
+.UNINDENT
+.UNINDENT
+.sp
+Or you can install it manually:
.INDENT 0.0
.INDENT 3.5
.sp
@@ -95,6 +108,8 @@ $ chmod a+x .git/hooks/sendemail\-validate
\fIpatatt validate\fP: basic validation for signed messages
.IP \(bu 2
\fIpatatt genkey\fP: generate a new ed25519 keypair
+.IP \(bu 2
+\fIpatatt install\-hook\fP: install sendemail\-validate hook in the current repository
.UNINDENT
.sp
You can run \fBpatatt [subcommand] \-\-help\fP to see a summary of flags for
diff --git a/man/patatt.5.rst b/man/patatt.5.rst
index 845595b..12bb0bd 100644
--- a/man/patatt.5.rst
+++ b/man/patatt.5.rst
@@ -5,15 +5,15 @@ DKIM-like cryptographic patch attestation
-----------------------------------------
:Author: mricon@kernel.org
-:Date: 2021-05-21
+:Date: 2021-09-10
:Copyright: The Linux Foundation and contributors
:License: MIT-0
-:Version: 0.4.0
+:Version: 0.4.7
:Manual section: 5
SYNOPSIS
--------
-patatt {sign,validate,genkey} [options]
+patatt {sign,validate,genkey,install-hook} [options]
DESCRIPTION
-----------
@@ -42,7 +42,12 @@ end.
USING AS A GIT HOOK
-------------------
If you use ``git-send-email`` for sending patches, then you can get
-them automatically signed via the ``sendemail-validate`` hook::
+them automatically signed via the ``sendemail-validate`` hook. To install,
+run the following command in the repository you want enabled for signing::
+
+ $ patatt install-hook
+
+Or you can install it manually::
$ echo 'patatt sign --hook "${1}"' >> .git/hooks/sendemail-validate
$ chmod a+x .git/hooks/sendemail-validate
@@ -52,6 +57,7 @@ SUBCOMMANDS
* *patatt sign*: sign stdin or RFC2822 files passed as arguments
* *patatt validate*: basic validation for signed messages
* *patatt genkey*: generate a new ed25519 keypair
+* *patatt install-hook*: install sendemail-validate hook in the current repository
You can run ``patatt [subcommand] --help`` to see a summary of flags for
each subcommand.
diff --git a/patatt/__init__.py b/patatt/__init__.py
index 8f183d6..4262a4a 100644
--- a/patatt/__init__.py
+++ b/patatt/__init__.py
@@ -47,7 +47,7 @@ OPT_HDRS = [b'message-id']
KEYCACHE = dict()
# My version
-__VERSION__ = '0.4.6'
+__VERSION__ = '0.4.7'
MAX_SUPPORTED_FORMAT_VERSION = 1
@@ -1115,6 +1115,23 @@ def cmd_genkey(cmdargs, config: dict) -> None:
logger.critical(pkey)
+def cmd_install_hook(cmdargs, config: dict): # noqa
+ gitrepo = get_git_toplevel()
+ if not gitrepo:
+ logger.critical('Not in a git tree, cannot install hook')
+ sys.exit(1)
+ hookfile = os.path.join(gitrepo, '.git', 'hooks', 'sendemail-validate')
+ if os.path.exists(hookfile):
+ logger.critical('Hook already exists: %s', hookfile)
+ sys.exit(1)
+ with open(hookfile, 'w') as fh:
+ fh.write('#!/bin/sh\n')
+ fh.write('# installed by patatt install-hook\n')
+ fh.write('patatt sign --hook "${1}"\n')
+ os.chmod(hookfile, 0o755)
+ logger.critical('Hook installed as %s', hookfile)
+
+
def command() -> None:
import argparse
# noinspection PyTypeChecker
@@ -1150,6 +1167,9 @@ def command() -> None:
help='Overwrite any existing keys, if found')
sp_gen.set_defaults(func=cmd_genkey)
+ sp_install = subparsers.add_parser('install-hook', help='Install sendmail-validate hook into the current repo')
+ sp_install.set_defaults(func=cmd_install_hook)
+
_args = parser.parse_args()
logger.setLevel(logging.DEBUG)