-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
54 lines (39 loc) · 1.23 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
This simple app can be used to emulate AWS Secrets Manager Layer for AWS Lambdas.
"""
import json
from dotenv import dotenv_values
from fastapi import FastAPI, Header
from typing import Any
app = FastAPI()
def dotenv_to_dict() -> dict[str, Any]:
"""Responsible for loading a .env file into a dictionary"""
return dotenv_values("./config/.env")
@app.get("/secretsmanager/get")
def get_secret(
secretId: str,
secrets_token: str = Header(None, alias="X-Aws-Parameters-Secrets-Token"),
) -> dict[str, Any]:
"""
Get route for access to local Secrets Manager.
Parameters
----------
secretId : str
secrets_token : str
Header:
Alias : X-Aws-Parameters-Secrets-Token.
Returns
-------
secretString: dict[str, Any]
Return a json with a jsonstring body.
Examples
--------
>>> secrets=$(curl localhost:2773/secretsmanager/get?secretId=my-secret -H '{"X-Aws-Parameters-Secrets-Token": ""}')
>>> secrets
'{"SecretString": "{\"user\":\"admin\",\"password\":\"EXAMPLE\"}"}'
"""
secrets = dotenv_to_dict()
return {"SecretString": json.dumps(secrets)}
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=2773)