Skip to main content

A python wrapper package for the lego application written in Golang

Project description

pylego

pylego is a python extension package to utilize the certificate management application Lego written in Golang in python.

Installation

To install this package, all you need to do is run

pip install .

in your preferred Python venv.

Usage

You can import the lego command and run any function that you can run from the CLI:

from pylego import run_lego_command
test_env = {"NAMECHEAP_API_USER": "user", "NAMECHEAP_API_KEY": "key"}
run_lego_command("something@gmail.com", "https://localhost/directory", "-----BEGIN CERTIFICATE REQUEST----- ...", "namecheap", test_env)
Argument Description
email The provided email will be registered to LetsEncrypt. It may receive some emails notifying the user about certificate expiry.
server This is the full URL of a server that implements the ACME protocol. While letsencrypt is the most common one, there are other programs that provide this facility like Vault.
csr This must be a PEM string in bytes that is user generated and valid as according to the ACME server that is being provided above. Many providers have different requirements for what is allowed to be in the fields of the CSR.
plugin The plugin is a string that's supported by LEGO. The full list is located here. On top of the LEGO provided ones, we have an extra plugin called http that will allow users to use HTTP01 and TLSALPN01 challenges.
env The env is a dictionary mapping of strings to strings that will be loaded into the environment for LEGO to use. All plugins require some configuration values loaded into the environment. You can find them here

On top of the environment variables that LEGO supports, we have some extra ones that we use to configure the library:

Key Description
SSL_CERT_FILE Path to a CA certificate file for pylego to trust. This can be used for trusting the certificate of the ACME server provided.
HTTP01_IFACE The interface to be used for the HTTP01 challenge if the plugin is chosen. Any interface by default.
HTTP01_PORT The port to be used for the HTTP01 challenge if the plugin is chosen. 80 by default.
TLSALPN01_IFACE The interface to be used for the TLSALPN01 challenge if the plugin is chosen. Any interface by default.
TLSALPN01_PORT The port to be used for the TLSALPN01 challenge if the plugin is chosen. 443 by default.

How does it work?

Golang supports building a shared c library from its CLI build tool. We import and use the LEGO application from GoLang, and provide a stub with C bindings so that the shared C binary we produce exposes a C API for other programs to import and utilize. pylego then uses the ctypes standard library in python to load this binary, and make calls to its methods.

The output binary, lego.so, is installed alongside pylego, and pylego exposes a python function called run_lego_command that will convert the arguments into a JSON message, and send it to LEGO.

On pip install, setuptools attempts to build this binary by running the command

go build -o lego.so -buildmode=c-shared lego.go

If we don't have a .whl that supports your environment, you will need to have Go installed and configured for Python to be able to build this binary.

License

The Lego library used in this project is licensed under the MIT License.

pylego itself is licensed under the Apache License, Version 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pylego-0.1.3.tar.gz (42.6 MB view details)

Uploaded Source

Built Distribution

pylego-0.1.3-py3-none-any.whl (42.9 MB view details)

Uploaded Python 3

File details

Details for the file pylego-0.1.3.tar.gz.

File metadata

  • Download URL: pylego-0.1.3.tar.gz
  • Upload date:
  • Size: 42.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pylego-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4297da3d01a1fe0298c6bfbc8755185b5325a36c54a808749544bbb7fbfca805
MD5 1eee146229e7bcc0c4be063da78760f9
BLAKE2b-256 c63099ce351e6c53162bbedea69be069513096aafb8fc9fa75f13d38b82d35a1

See more details on using hashes here.

File details

Details for the file pylego-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pylego-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 42.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for pylego-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 189401935f938d5286cb94408d5fff91ac7f6cf87609045fcb23e32e56375177
MD5 660b78027f0408c41d422b2cb01f333a
BLAKE2b-256 780f48b239c8c12402b4963a15984aff4caf17eb71102765fff49689748df8aa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page