Skip to content

Commit

Permalink
feat: Add function to retrieve the value of a field from 1Password CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
LobaDK committed May 22, 2024
1 parent 56a80ad commit d7592e4
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions cogs/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from io import BytesIO
from base64 import b64encode
from pathlib import Path
from subprocess import check_output
from shutil import which

from QuantumKat import discord_helper

Expand Down Expand Up @@ -121,6 +123,28 @@ class UnsupportedImageFormatError(Exception):
encoding = encoding_for_model("gpt-4o")


def get_field_from_1password(reference: str) -> str:
"""
Retrieves the value of a field from 1Password and returns it as a string.
Requires the 1Password CLI to be installed and configured.
Args:
reference (str): The reference to the token in 1Password.
Returns:
str: The token retrieved from 1Password.
Raises:
CalledProcessError: If the token cannot be retrieved from 1Password.
EnvironmentError: If the 1Password CLI is not installed.
"""
if which("op") is None:
raise EnvironmentError("The 1Password CLI is not installed. Please install it.")
token = check_output(["op", "read", reference]).decode("utf-8").strip()
return token


def download_file(
url: str,
amount_or_limit: int = None,
Expand Down

0 comments on commit d7592e4

Please sign in to comment.