diff --git a/README.md b/README.md index c0a48b9..2da192a 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,94 @@ Settings management using Pydantic and Amazon Web Services. -## Installation +## 💽 Installation Install using `pip install -U pydantic-settings-aws`. + +## 📜 Example + +You can create and manage your own secrets manager client or leave it to pydantic-settings-aws. + +If you want to leave to pydantic-settings-aws to deal with boto3, you can either pass your credential information or leave it to boto3 to figure it out. + +To check how boto3 will look for your configurations, check [Configuring credentials](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#configuring-credentials). + +### With secrets manager client + +```python +import boto3 +from pydantic_settings_aws import SecretsManagerBaseSettings + + +client = boto3.client("secretsmanager") + + +class AWSSecretsSettings(SecretsManagerBaseSettings): + model_config = SettingsConfigDict( + secrets_name="my/secret", + secrets_client=client + ) + + username: str + password: str + name: str | None = None + +my_settings = AWSSecretsSettings() +``` + +And your secrets manager should be: + +```json +{ + "username": "admin", + "password": "admin", + "name": "John" +} +``` + +### 🙋🏾‍♂️ With profile name + +```python +class AWSSecretsSettings(SecretsManagerBaseSettings): + model_config = SettingsConfigDict( + secrets_name="my/secret", + aws_region="us-east-1", + aws_profile="dev" + ) + + username: str + password: str +``` + +### 🔑 With access key + +```python +class AWSSecretsSettings(SecretsManagerBaseSettings): + model_config = SettingsConfigDict( + secrets_name="my/secret", + aws_region="us-east-1", + aws_access_key_id="aws_access_key_id", + aws_secret_access_key="aws_secret_access_key", + aws_session_token="aws_session_token" + ) + + username: str + password: str +``` + + +### 🔒 With AWS IAM Identity Center (SSO) + +```shell +aws sso login --profile my-profile +``` + +```python +class AWSSecretsSettings(SecretsManagerBaseSettings): + model_config = SettingsConfigDict( + secrets_name="my/secret" + ) + + username: str + password: str +``` diff --git a/tests/aws_test.py b/tests/aws_test.py index c0c1aba..bd908e0 100644 --- a/tests/aws_test.py +++ b/tests/aws_test.py @@ -2,8 +2,8 @@ from unittest import mock import pytest - from pydantic import ValidationError + from pydantic_settings_aws import aws from .aws_mocks import (