---
title: Charmhub | Deploy Lego Base K8S using Charmhub - The Open Operator Collection
description: Deploy the latest version of Lego Base K8S on any cloud.
url: https://charmhub.io/lego-base-k8s/libraries/lego_client
---

# Lego Base K8S

[Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

* [Canonical Telco](https://charmhub.io/publisher/telco-charmers "View all packages from Canonical Telco")

Platform:

22.04

20.04

edge 88

```
juju deploy lego-base-k8s --channel edge
```

[Learn to deploy on juju >](https://juju.is/docs/juju/manage-applications)

[Toggle side navigation](https://charmhub.io/lego-base-k8s/libraries/lego_client#drawer)

## charms.lego\_base\_k8s.v0.lego\_client

* [*Docstrings*Docstrings](https://charmhub.io/lego-base-k8s/libraries/lego_client)
  [*Code*Source code](https://charmhub.io/lego-base-k8s/libraries/lego_client/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.lego_base_k8s.v0.lego_client
    ```

    [Download lego\_client.py](https://charmhub.io/lego-base-k8s/libraries/lego_client/download)
  + *Last updated* 29 Jul 2024
  + *Revision* Library version 0.14

#### lego\_client Library.

This library is designed to enable developers to easily create new charms for the ACME protocol.
This library contains all the logic necessary to get certificates from an ACME server.

##### Getting Started

To get started using the library, you need to fetch the library using `charmcraft`.

```
charmcraft fetch-lib charms.lego_client_operator.v0.lego_client
```

You will also need the following libraries:

```
charmcraft fetch-lib charms.tls_certificates_interface.v3.tls_certificates
charmcraft fetch-lib charms.certificate_transfer_interface.v1.certificate_transfer
charmcraft fetch-lib charms.loki_k8s.v1.loki_push_api
```

You will also need to add the following library to the charm's `requirements.txt` file:

* jsonschema
* cryptography
* cosl

Then, to use the library in an example charm, you can do the following:

```
from charms.lego_client_operator.v0.lego_client import AcmeClient
from ops.main import main
class ExampleAcmeCharm(AcmeClient):
    def __init__(self, *args):
        super().__init__(*args, plugin="namecheap")
        self._server = "https://acme-staging-v02.api.letsencrypt.org/directory"

    def _validate_plugin_config(self) -> str:
        if not self._api_key:
            return "API key was not provided"
        return ""

    @property
    def _plugin_config(self):
        return {}
```

Charms using this library are expected to:

* Inherit from AcmeClient
* Call `super().__init__(*args, plugin="")` with the lego plugin name
* Observe `ConfigChanged` to a method called `_on_config_changed`
* Implement the `_validate_plugin_config` method,
  it should validate the plugin specific configuration,
  returning a string with an error message if the
  plugin specific configuration is invalid, otherwise an empty string.
* Implement the `_plugin_config` property, returning a dictionary of its specific
  configuration. Keys must be capitalized and follow the plugins documentation from
  lego.
* Specify a `certificates` integration in their
  `metadata.yaml` file:

```
provides:
  certificates:
    interface: tls-certificates
  send-ca-cert:
    interface: certificate_transfer
```

* Specify a `logging` integration in their `metadata.yaml` file:

```
requires:
  logging:
    interface: loki_push_api
```

---

Index

* [class AcmeClient](https://charmhub.io/lego-base-k8s/libraries/lego_client#acmeclient)
* + [def \_\_init\_\_(
    self)](https://charmhub.io/lego-base-k8s/libraries/lego_client#acmeclient-__init__)
* + [def validate\_generic\_acme\_config(
    self)](https://charmhub.io/lego-base-k8s/libraries/lego_client#acmeclient-validate_generic_acme_config)
* [def get\_env\_var(
  env\_var
  )](https://charmhub.io/lego-base-k8s/libraries/lego_client#get_env_var)

#### class AcmeClient

Base charm for charms that use the ACME protocol to get certificates.

Description

This charm implements the tls\_certificates interface as a provider.

Methods

AcmeClient.
\_\_init\_\_(

*self*
)

AcmeClient.
validate\_generic\_acme\_config(

*self*
)

Validate generic ACME config.

Returns

#### def get\_env\_var(env\_var: str)

Get the environment variable value.

Arguments

env\_var

Name of the environment variable.

Returns

Value of the environment variable. None if not found.

Description

Looks for all upper-case and all low-case of the `env_var`.
