https://github.com/Infisical/infisical-python
pip install infisical-python
Rust 설치: Rust와 Cargo를 사용하여 확장 기능을 컴파일한다. 만약에 아래와 같은 에러가 발생한다면
Collecting infisical-python
Using cached infisical_python-2.1.6.tar.gz (38 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... error
error: subprocess-exited-with-error
× Preparing metadata (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [6 lines of output]
Checking for Rust toolchain....
Cargo, the Rust package manager, is not installed or is not on PATH.
This package requires Rust and Cargo to compile extensions. Install it through
the system's package manager or via <https://rustup.rs/>
[end of output]
...
다음 명령어를 사용하여 Rust를 설치해주어야 한다.
curl --proto '=https' --tlsv1.2 -sSf <https://sh.rustup.rs> | sh
source "$HOME/.cargo/env"
client 에는 site url과 token이 들어간다. site url은 기본으로 infisical에서 제공하는 서버인 https://app.infisical.com 주소가 들어가있고 self hosted server를 이용한다면 바꿔줘야 한다.
import os
from infisical_client import ClientSettings, InfisicalClient
INFISICAL_API_URL = os.getenv("INFISICAL_API_URL")
INFISICAL_TOKEN = os.getenv("INFISICAL_TOKEN")
client = InfisicalClient(ClientSettings(site_url=INFISICAL_API_URL, access_token=INFISICAL_TOKEN))
<aside> 💡 만약 infisical 서버에 등록되지 않은 시크릿이 없을 경우 로컬에 있는 환경 변수를 가져옴!
</aside>
하나만 GET
from infisical_client import GetSecretOptions
secret = client.getSecret(options=GetSecretOptions(environment="prod", project_id=PROJECT_ID, secret_name="SLACK_TOKEN"))
value = secret.secret_value # get its value
모두 GET
secrets = client.listSecrets(options=ListSecretsOptions(environment="prod", project_id=PROJECT_ID, path="/"))