Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Azure Key Vault settings source #272

Conversation

AndreuCodina
Copy link
Contributor

@AndreuCodina AndreuCodina commented Apr 21, 2024

Add Azure Key Vault settings source.

Doubt: Where should I add the required Python packages (azure-keyvault-secrets==4.8.0 and azure-identity==1.16.0) to use AzureKeyVaultSettingsSource?

This is the infrastructure:

resource "azurerm_resource_group" "pydantic" {
  name     = "pydantic"
  location = "northeurope"
}

resource "azurerm_key_vault" "pydantic" {
  name                          = "kv-pydantic"
  resource_group_name           = "pydantic"
  location                      = "northeurope"
  tenant_id                     = data.azuread_client_config.current.tenant_id
  sku_name                      = "standard"
  soft_delete_retention_days    = 7
  purge_protection_enabled      = false
  enable_rbac_authorization     = true
  public_network_access_enabled = true
}

resource "azurerm_key_vault_secret" "sql_server_password" {
  name         = "SqlServer--Password"
  value        = "SqlServerPassword"
  key_vault_id = azurerm_key_vault.pydantic.id
}

resource "azurerm_key_vault_secret" "my_password" {
  name         = "MyPassword"
  value        = "MyPassword"
  key_vault_id = azurerm_key_vault.pydantic.id
}

Closes #143

@hramezani
Copy link
Member

hramezani commented Apr 21, 2024

Thanks @AndreuCodina for this PR.

Doubt: Where should I add the required Python packages (azure-keyvault-secrets==4.8.0 and azure-identity==1.16.0) to use AzureKeyVaultSettingsSource?

It has to be added to optional dependencies section

Also, I can't see any test added here. You need to add some tests

@AndreuCodina
Copy link
Contributor Author

Thanks @AndreuCodina for this PR.

Doubt: Where should I add the required Python packages (azure-keyvault-secrets==4.8.0 and azure-identity==1.16.0) to use AzureKeyVaultSettingsSource?

It has to be added to optional dependencies section

Also, I can't see any test added here. You need to add some tests

How do I make the imports in code? I've created the function import_azure_key_vault, but I'm getting mypy pydantic_settings pydantic_settings/sources.py:14: error: Cannot find implementation or library stub for module named "azure.core.credentials" [import-not-found]

@hramezani
Copy link
Member

You need to update the requirements by running make refresh-lockfiles command

@AndreuCodina
Copy link
Contributor Author

You need to update the requirements by running make refresh-lockfiles command

$ make refresh-lockfiles
`make: *** No rule to make target 'refresh-lockfiles'.  Stop.`

@hramezani
Copy link
Member

Please refresh your fork. this command was added recently

requirements/linting.txt Outdated Show resolved Hide resolved
requirements/testing.txt Outdated Show resolved Hide resolved
tests/test_sources.py Outdated Show resolved Hide resolved
tests/test_sources.py Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
docs/index.md Outdated Show resolved Hide resolved
@hramezani
Copy link
Member

@AndreuCodina I changed the example in the doc and made it simpler.

Please add AzureKeyVaultSettingsSource to the init and then change the doc example to import AzureKeyVaultSettingsSource from pydantic_settings instead of pydantic_settings.sources

@AndreuCodina
Copy link
Contributor Author

@AndreuCodina I changed the example in the doc and made it simpler.

Please add AzureKeyVaultSettingsSource to the init and then change the doc example to import AzureKeyVaultSettingsSource from pydantic_settings instead of pydantic_settings.sources

Done. I've removed "```python" in the markdown because if not, the tests fail.

docs/index.md Outdated Show resolved Hide resolved
@hramezani
Copy link
Member

@AndreuCodina I changed the example in the doc and made it simpler.
Please add AzureKeyVaultSettingsSource to the init and then change the doc example to import AzureKeyVaultSettingsSource from pydantic_settings instead of pydantic_settings.sources

Done. I've removed "```python" in the markdown because if not, the tests fail.

it fails because of imports in the code. I've fixed it and returned the "```python"

@hramezani hramezani merged commit bcbdd2a into pydantic:main Jul 19, 2024
18 checks passed
@hramezani
Copy link
Member

Thanks @AndreuCodina

@AndreuCodina AndreuCodina deleted the feature/azure-key-vault-source-settings-source branch July 19, 2024 10:39
mr-kamran-ali referenced this pull request in robert-koch-institut/mex-common Aug 8, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [pydantic-settings](https://github.com/pydantic/pydantic-settings)
([changelog](https://github.com/pydantic/pydantic-settings/releases))
| project.dependencies | minor | `==2.3.4` -> `==2.4.0` |

---

### Release Notes

<details>
<summary>pydantic/pydantic-settings (pydantic-settings)</summary>

###
[`v2.4.0`](https://github.com/pydantic/pydantic-settings/releases/tag/v2.4.0)

[Compare
Source](https://github.com/pydantic/pydantic-settings/compare/v2.3.4...v2.4.0)

#### What's Changed

- Fix regex flags accidentally passed as count by
[@&#8203;musicinmybrain](https://github.com/musicinmybrain) in
[https://github.com/pydantic/pydantic-settings/pull/328](https://github.com/pydantic/pydantic-settings/pull/328)
- Deprecate `read_env_file` and move it to `DotEnvSettingsSource` by
[@&#8203;WarpedPixel](https://github.com/WarpedPixel) in
[https://github.com/pydantic/pydantic-settings/pull/318](https://github.com/pydantic/pydantic-settings/pull/318)
- Fix a bug when loading empty yaml file by
[@&#8203;hramezani](https://github.com/hramezani) in
[https://github.com/pydantic/pydantic-settings/pull/330](https://github.com/pydantic/pydantic-settings/pull/330)
- feat: Enable access to the current state in settings sources by
[@&#8203;VictorColomb](https://github.com/VictorColomb) in
[https://github.com/pydantic/pydantic-settings/pull/326](https://github.com/pydantic/pydantic-settings/pull/326)
- Add support for short options. by
[@&#8203;kschwab](https://github.com/kschwab) in
[https://github.com/pydantic/pydantic-settings/pull/339](https://github.com/pydantic/pydantic-settings/pull/339)
- Add Azure Key Vault settings source by
[@&#8203;AndreuCodina](https://github.com/AndreuCodina) in
[https://github.com/pydantic/pydantic-settings/pull/272](https://github.com/pydantic/pydantic-settings/pull/272)
- Add cli_exit_on_error config option by
[@&#8203;kschwab](https://github.com/kschwab) in
[https://github.com/pydantic/pydantic-settings/pull/340](https://github.com/pydantic/pydantic-settings/pull/340)

#### New Contributors

- [@&#8203;musicinmybrain](https://github.com/musicinmybrain) made
their first contribution in
[https://github.com/pydantic/pydantic-settings/pull/328](https://github.com/pydantic/pydantic-settings/pull/328)
- [@&#8203;WarpedPixel](https://github.com/WarpedPixel) made their
first contribution in
[https://github.com/pydantic/pydantic-settings/pull/318](https://github.com/pydantic/pydantic-settings/pull/318)
- [@&#8203;VictorColomb](https://github.com/VictorColomb) made their
first contribution in
[https://github.com/pydantic/pydantic-settings/pull/326](https://github.com/pydantic/pydantic-settings/pull/326)
- [@&#8203;AndreuCodina](https://github.com/AndreuCodina) made their
first contribution in
[https://github.com/pydantic/pydantic-settings/pull/272](https://github.com/pydantic/pydantic-settings/pull/272)

**Full Changelog**:
pydantic/pydantic-settings@v2.3.4...v2.4.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4yMC4xIiwidXBkYXRlZEluVmVyIjoiMzguMjEuNCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft KeyVault fetch support
3 participants