Last active
August 18, 2024 03:22
-
-
Save BlackthornYugen/943c5cee2d61de13da1dc45e4df03c04 to your computer and use it in GitHub Desktop.
Playing with bash and jq pipe formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
cd "$(mktemp -d)" | |
openssl req \ | |
-subj "/C=CA/ST=Ontario/L=Waterloo/O=jskw/OU=IT/CN=jskw.dev" \ | |
-new \ | |
-outform PEM \ | |
-nodes \ | |
-keyout /dev/null \ | |
-out - \ | |
-newkey ec:<(openssl ecparam --name prime256v1) \ | |
| tee csr.pem >(openssl req --outform DER -in - | xxd > der.hex) \ | |
| curl https://httpbin.org/post \ | |
--silent \ | |
--form "name=My Cool CSR" \ | |
--form "description=This is a certificate signing request generated with OpenSSL" \ | |
--form "file=@-" \ | |
| jq --arg date "$(date)" ' | |
{files, form} | |
| debug({pem: .files.file}) | |
| { | |
date: $date, | |
encoded: (.files.file | gsub("-----.+-----|\n| "; "")), | |
} + .form | |
| del(.files) | |
' | |
# Print Hex & PEM side by side | |
paste -d '🦊' der.hex csr.pem \ | |
| column -s '🦊' -t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment