pylego 0.1.31__tar.gz → 0.1.32__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pylego
3
- Version: 0.1.31
3
+ Version: 0.1.32
4
4
  Summary: A python wrapper package for the lego application written in Golang
5
5
  Author-email: Canonical <telco-engineers@lists.canonical.com>
6
6
  Project-URL: Homepage, https://github.com/canonical/pylego
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pylego"
3
- version = "0.1.31"
3
+ version = "0.1.32"
4
4
  authors = [
5
5
  { name="Canonical", email="telco-engineers@lists.canonical.com" },
6
6
  ]
@@ -12,6 +12,7 @@ import (
12
12
  "errors"
13
13
  "fmt"
14
14
  "os"
15
+ "time"
15
16
 
16
17
  "github.com/go-acme/lego/v4/certcrypto"
17
18
  "github.com/go-acme/lego/v4/certificate"
@@ -24,12 +25,13 @@ import (
24
25
  )
25
26
 
26
27
  type LegoInputArgs struct {
27
- Email string `json:"email"`
28
- PrivateKey string `json:"private_key,omitempty"`
29
- Server string `json:"server"`
30
- CSR string `json:"csr"`
31
- Plugin string `json:"plugin"`
32
- Env map[string]string
28
+ Email string `json:"email"`
29
+ PrivateKey string `json:"private_key,omitempty"`
30
+ Server string `json:"server"`
31
+ CSR string `json:"csr"`
32
+ Plugin string `json:"plugin"`
33
+ Env map[string]string
34
+ DNSPropagationWait int `json:"dns_propagation_wait,omitempty"`
33
35
  }
34
36
 
35
37
  type LegoOutputResponse struct {
@@ -58,7 +60,7 @@ func RunLegoCommand(message *C.char) *C.char {
58
60
  }
59
61
 
60
62
  }
61
- certificate, err := requestCertificate(CLIArgs.Email, CLIArgs.PrivateKey, CLIArgs.Server, CLIArgs.CSR, CLIArgs.Plugin)
63
+ certificate, err := requestCertificate(CLIArgs.Email, CLIArgs.PrivateKey, CLIArgs.Server, CLIArgs.CSR, CLIArgs.Plugin, CLIArgs.DNSPropagationWait)
62
64
  if err != nil {
63
65
  return C.CString(fmt.Sprint("error: couldn't request certificate: ", err))
64
66
  }
@@ -70,7 +72,7 @@ func RunLegoCommand(message *C.char) *C.char {
70
72
  return return_message_ptr
71
73
  }
72
74
 
73
- func requestCertificate(email, privateKeyPem, server, csr, plugin string) (*LegoOutputResponse, error) {
75
+ func requestCertificate(email, privateKeyPem, server, csr, plugin string, propagationWait int) (*LegoOutputResponse, error) {
74
76
  var privateKey crypto.PrivateKey
75
77
  if privateKeyPem != "" {
76
78
  parsedKey, err := certcrypto.ParsePEMPrivateKey([]byte(privateKeyPem))
@@ -99,7 +101,7 @@ func requestCertificate(email, privateKeyPem, server, csr, plugin string) (*Lego
99
101
  return nil, fmt.Errorf("couldn't create lego client: %s", err)
100
102
  }
101
103
 
102
- err = configureClientChallenges(client, plugin)
104
+ err = configureClientChallenges(client, plugin, propagationWait)
103
105
  if err != nil {
104
106
  return nil, fmt.Errorf("couldn't configure client challenges: %s", err)
105
107
  }
@@ -140,7 +142,7 @@ func requestCertificate(email, privateKeyPem, server, csr, plugin string) (*Lego
140
142
  }, nil
141
143
  }
142
144
 
143
- func configureClientChallenges(client *lego.Client, plugin string) error {
145
+ func configureClientChallenges(client *lego.Client, plugin string, propagationWait int) error {
144
146
  switch plugin {
145
147
  case "", "http":
146
148
  if err := client.Challenge.SetHTTP01Provider(http01.NewProviderServer(os.Getenv("HTTP01_IFACE"), os.Getenv("HTTP01_PORT"))); err != nil {
@@ -157,9 +159,19 @@ func configureClientChallenges(client *lego.Client, plugin string) error {
157
159
  if err != nil {
158
160
  return errors.Join(fmt.Errorf("couldn't create %s provider: ", plugin), err)
159
161
  }
162
+ var wait time.Duration
163
+ if propagationWait < 0 {
164
+ return fmt.Errorf("DNS_PROPAGATION_WAIT cannot be negative: %d", propagationWait)
165
+ }
166
+ if propagationWait > 0 {
167
+ wait = time.Duration(propagationWait) * time.Second
168
+ }
169
+
160
170
  err = client.Challenge.SetDNS01Provider(dnsProvider,
161
171
  dns01.CondOption(os.Getenv("DNS_PROPAGATION_DISABLE_ANS") != "",
162
172
  dns01.DisableAuthoritativeNssPropagationRequirement()),
173
+ dns01.CondOption(wait > 0,
174
+ dns01.PropagationWait(wait, true)),
163
175
  dns01.CondOption(os.Getenv("DNS_PROPAGATION_RNS") != "", dns01.RecursiveNSsPropagationRequirement()))
164
176
  if err != nil {
165
177
  return errors.Join(fmt.Errorf("couldn't set %s DNS provider server: ", plugin), err)
@@ -35,7 +35,13 @@ class LEGOError(Exception):
35
35
 
36
36
 
37
37
  def run_lego_command(
38
- email: str, server: str, csr: bytes, env: dict[str, str], plugin: str = "", private_key: str = ""
38
+ email: str,
39
+ server: str,
40
+ csr: bytes,
41
+ env: dict[str, str],
42
+ plugin: str = "",
43
+ private_key: str = "",
44
+ dns_propagation_wait: int | None = None,
39
45
  ) -> LEGOResponse:
40
46
  """Run an arbitrary command in the Lego application. Read more at https://go-acme.github.io.
41
47
 
@@ -47,21 +53,27 @@ def run_lego_command(
47
53
  env: the environment variables required for the chosen plugin.
48
54
  private_key: the private key to be used for the registration on the ACME server (not the private key used to sign the CSR).
49
55
  If not provided, a new one will be generated.
56
+ dns_propagation_wait: optional wait duration for DNS propagation, in seconds (int).
50
57
  """
51
58
  library.RunLegoCommand.restype = ctypes.c_char_p
52
59
  library.RunLegoCommand.argtypes = [ctypes.c_char_p]
53
60
 
61
+ if dns_propagation_wait is not None and dns_propagation_wait < 0:
62
+ raise ValueError("dns_propagation_wait cannot be negative")
63
+
64
+ payload = {
65
+ "email": email,
66
+ "server": server,
67
+ "csr": csr.decode(),
68
+ "plugin": plugin,
69
+ "env": env,
70
+ "private_key": private_key,
71
+ }
72
+ if dns_propagation_wait is not None:
73
+ payload["dns_propagation_wait"] = dns_propagation_wait
74
+
54
75
  message = bytes(
55
- json.dumps(
56
- {
57
- "email": email,
58
- "server": server,
59
- "csr": csr.decode(),
60
- "plugin": plugin,
61
- "env": env,
62
- "private_key": private_key,
63
- }
64
- ),
76
+ json.dumps(payload),
65
77
  "utf-8",
66
78
  )
67
79
  result: bytes = library.RunLegoCommand(message)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pylego
3
- Version: 0.1.31
3
+ Version: 0.1.32
4
4
  Summary: A python wrapper package for the lego application written in Golang
5
5
  Author-email: Canonical <telco-engineers@lists.canonical.com>
6
6
  Project-URL: Homepage, https://github.com/canonical/pylego
@@ -6,7 +6,6 @@ src/pylego/__init__.py
6
6
  src/pylego/go.mod
7
7
  src/pylego/go.sum
8
8
  src/pylego/lego.go
9
- src/pylego/lego.so
10
9
  src/pylego/pylego.py
11
10
  src/pylego.egg-info/PKG-INFO
12
11
  src/pylego.egg-info/SOURCES.txt
Binary file
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes