Problemas resolvidos
Some checks failed
Creates a docker image for production / Deploy (push) Has been cancelled
Creates a docker image for production / Build the docker image (push) Has been cancelled
Build / Code quality (push) Has been cancelled

This commit is contained in:
2025-02-05 10:04:42 -03:00
parent f3e0e60048
commit 8bcc4e4373
8 changed files with 61 additions and 30 deletions

37
app/openv.py Normal file
View File

@@ -0,0 +1,37 @@
from typing import Optional
from onepasswordconnectsdk.client import Client, new_client_from_environment
from onepasswordconnectsdk.models import Item, Vault
class OnePassword:
connect_client: Client = new_client_from_environment()
vault_title: Optional[str]
item_title: str = 'mines'
vault: Optional[Vault] = None
item: Optional[Item] = None
def __init__(self, scope: str, item_title=None):
if item_title:
self.item_title = item_title
self.vault_title = scope.lower()
def get_vault(self) -> Vault:
if self.vault:
return self.vault
self.vault = self.connect_client.get_vault_by_title(self.vault_title)
return self.vault
def get_item(self) -> Item:
if self.item:
return self.item
vault = self.get_vault()
self.item = self.connect_client.get_item_by_title(self.item_title, vault.id)
return self.item
def get(self, field: str, default_value=None) -> str | None:
item = self.get_item()
for f in item.fields:
if f.label == field:
return f.value
return default_value