Things I learned/revisited this week#1
Reading SSL certificate material with python cryptography library…deleting git branches…docker command formatting…escaping liquid syntax in markdown.
- Load x509 certificate and rsa key files using Python cryptography library
from cryptography as x509
with open(cert_file, "rb") as cert_file_fp:
# opening the file in byte mode
cert_file_pem = x509.load_pem_x509_certificate(cert_file_fp.read())
print(cert_file_pem.serial_number, cert_file_pem.subject)
# backend parameter deprecated from version 36.0.0 onwards
# See https://cryptography.io/en/latest/faq/#what-happened-to-the-backend-argument
# cert_file_pem = x509.load_pem_x509_certificate(cert_file_fp.read(), backend=default_backend())
from cryptography.hazmat.primitives import serialization
with open(key_file, "rb") as key_file_fp:
# unencrypted key, so leaving the password as None
key_file_pem = serialization.load_pem_private_key(
key_file_fp.read(),
password=None)
# dumping the public key info
public_key = key_file_pem.public_key()
print(public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo
))
- Deleting local and remote branches in Git.
- local
- to delete =>
git branch --delete <branch-name>
(orgit branch -d
) - to force delete =>
git branch --delete --force <branch-name>
(orgit branch -D <branch-name>
)
- to delete =>
- remote -
git push origin --delete <remote-branch-name>
- local
-
perror(“some msg”) from standard library - prints
some msg: <description of error matching errno>
. (use strerror(errno) to get just the description of errno) - Format docker images output to display only the image and tag information =>
$(docker images --format '{{.Repository}}:{{.Tag}}')
. Formatting is based on Go templates. This is often useful in scripting to use only the needed fields.
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nginx latest 7425d3a7c478 3 weeks ago 142MB
$ # {{..}} are the Actions
$ # all text between actions is copied verbatim
$ docker images --format '{{.Repository}}:{{.Tag}}'
nginx:latest
- Escape liquid syntax in markdown with {% raw %} and {% endraw %} tags. Thanks to this post. The second workaround of using jekyll variables was helpful to even escape raw and endraw tags.
Comments