Skip to content

Commit

Permalink
pylxd/models/certificate: re-add password arg for backward compat
Browse files Browse the repository at this point in the history
Fixes canonical/charm-lxd#168 where charm-lxd is calling certificates.create():

```python
  config: Dict[str, Union[str, bytes, List[str], bool]] = {
      "name": name,
      "password": "",
      "cert_data": cert.encode(),
  }

  client.certificates.create(**config)
```

causing:

```
  File "./src/charm.py", line 1139, in _on_https_relation_changed
    if self.lxd_trust_add(cert=cert, name=cert_name, projects=projects):
  File "./src/charm.py", line 2294, in lxd_trust_add
    client.certificates.create(**config)
TypeError: create() got an unexpected keyword argument 'password'
```

Signed-off-by: Simon Deziel <[email protected]>
  • Loading branch information
simondeziel committed Sep 9, 2024
1 parent fb96065 commit f128461
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pylxd/models/certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ def all(cls, client):
def create(
cls,
client,
secret,
password,
cert_data,
cert_type="client",
name="",
projects=None,
restricted=False,
secret="",
):
"""Create a new certificate."""
cert = x509.load_pem_x509_certificate(cert_data, default_backend())
Expand All @@ -73,9 +74,9 @@ def create(
"projects": projects,
}
if client.has_api_extension("explicit_trust_token"):
data["trust_token"] = secret
data["trust_token"] = secret or password
else:
data["password"] = secret
data["password"] = password
response = client.api.certificates.post(json=data)
location = response.headers["Location"]
fingerprint = location.split("/")[-1]
Expand Down

0 comments on commit f128461

Please sign in to comment.