---
title: Charmhub | Deploy MongoDB using Charmhub - The Open Operator Collection
description: Deploy the latest version of MongoDB on any cloud.
url: https://charmhub.io/mongodb/libraries/mongodb_secrets
---

# MongoDB

[Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")

* [Canonical](https://charmhub.io/publisher/data-platform "View all packages from Canonical")
* [Databases](https://charmhub.io/?filter=databases)

Platform:

24.04

22.04

6/stable 265

```
juju deploy mongodb --channel 6/stable
```

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

[Toggle side navigation](https://charmhub.io/mongodb/libraries/mongodb_secrets#drawer)

## charms.mongodb.v0.mongodb\_secrets

* [*Docstrings*Docstrings](https://charmhub.io/mongodb/libraries/mongodb_secrets)
  [*Code*Source code](https://charmhub.io/mongodb/libraries/mongodb_secrets/source-code)
* + Download

    Fetch library

    ```
    charmcraft fetch-lib charms.mongodb.v0.mongodb_secrets
    ```

    [Download mongodb\_secrets.py](https://charmhub.io/mongodb/libraries/mongodb_secrets/download)
  + *Last updated* 09 Aug 2024
  + *Revision* Library version 0.3

Secrets related helper classes/functions.

---

Index

* [def generate\_secret\_label(
  charm,
  scope
  )](https://charmhub.io/mongodb/libraries/mongodb_secrets#generate_secret_label)
* [class CachedSecret](https://charmhub.io/mongodb/libraries/mongodb_secrets#cachedsecret)
* + [def \_\_init\_\_(
    self,
    charm,
    label,
    secret\_uri)](https://charmhub.io/mongodb/libraries/mongodb_secrets#cachedsecret-__init__)
* + [def add\_secret(
    self,
    content,
    scope)](https://charmhub.io/mongodb/libraries/mongodb_secrets#cachedsecret-add_secret)
* + [def meta(
    self)](https://charmhub.io/mongodb/libraries/mongodb_secrets#cachedsecret-meta)
* + [def get\_content(
    self)](https://charmhub.io/mongodb/libraries/mongodb_secrets#cachedsecret-get_content)
* + [def set\_content(
    self,
    content)](https://charmhub.io/mongodb/libraries/mongodb_secrets#cachedsecret-set_content)
* + [def get\_info(
    self)](https://charmhub.io/mongodb/libraries/mongodb_secrets#cachedsecret-get_info)
* [class SecretCache](https://charmhub.io/mongodb/libraries/mongodb_secrets#secretcache)
* + [def \_\_init\_\_(
    self,
    charm)](https://charmhub.io/mongodb/libraries/mongodb_secrets#secretcache-__init__)
* + [def get(
    self,
    label,
    uri)](https://charmhub.io/mongodb/libraries/mongodb_secrets#secretcache-get)
* + [def add(
    self,
    label,
    content,
    scope)](https://charmhub.io/mongodb/libraries/mongodb_secrets#secretcache-add)

#### def generate\_secret\_label(     charm: CharmBase,     scope: Scopes )

Generate unique group\_mappings for secrets within a relation context.

Description

Defined as a standalone function, as the choice on secret labels definition belongs to the
Application Logic. To be kept separate from classes below, which are simply to provide a
(smart) abstraction layer above Juju Secrets.

#### class CachedSecret

Abstraction layer above direct Juju access with caching.

Description

The data structure is precisely re-using/simulating Juju Secrets behavior, while
also making sure not to fetch a secret multiple times within the same event scope.

Methods

CachedSecret.
\_\_init\_\_(

*self*

,
charm: CharmBase

,
label: str

,
secret\_uri
)

CachedSecret.
add\_secret(

*self*

,
content

,
scope: Scopes
)

Description

Create a new secret. None

CachedSecret.
meta(

*self*
)

Description

Getting cached secret meta-information. None

CachedSecret.
get\_content(

*self*
)

Description

Getting cached secret content. None

CachedSecret.
set\_content(

*self*

,
content
)

Description

Setting cached secret content. None

CachedSecret.
get\_info(

*self*
)

Description

Wrapper function for get the corresponding call on the Secret object if any. None

#### class SecretCache

Description

A data structure storing CachedSecret objects. None

Methods

SecretCache.
\_\_init\_\_(

*self*

,
charm
)

SecretCache.
get(

*self*

,
label: str

,
uri
)

Description

Getting a secret from Juju Secret store or cache. None

SecretCache.
add(

*self*

,
label: str

,
content

,
scope: Scopes
)

Description

Adding a secret to Juju Secret. None
