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

View File

@@ -1,16 +1,18 @@
import os
from pathlib import Path
import sentry_sdk
from sentry_sdk.integrations.django import DjangoIntegration
from .utils import get_op_config
from app.openv import OnePassword
op_config = get_op_config()
SCOPE = os.environ['SCOPE']
OP_ITEM_TITLE = os.environ.get('OP_ITEM_TITLE', 'mines')
SCOPE = op_config['settings.SCOPE']
op_env = OnePassword(SCOPE, OP_ITEM_TITLE)
sentry_sdk.init(
dsn=op_config['settings.SENTRY_DSN'],
dsn=op_env.get('settings.SENTRY_DSN'),
integrations=[DjangoIntegration()],
environment=SCOPE,
send_default_pii=False,
@@ -21,12 +23,12 @@ sentry_sdk.init(
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = op_config['settings.SECRET_KEY']
SECRET_KEY = op_env.get('settings.SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = op_config.get('settings.DEBUG', '0') in ['1', 'true']
DEBUG = op_env.get('settings.DEBUG', '0') in ['1', 'true']
ALLOWED_HOSTS = op_config.get('settings.ALLOWED_HOSTS', '127.0.0.1,localhost').split(',')
ALLOWED_HOSTS = op_env.get('settings.ALLOWED_HOSTS', '127.0.0.1,localhost').split(',')
# Application definition
INSTALLED_APPS = [
@@ -82,11 +84,11 @@ AUTH_USER_MODEL = 'core.User'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': op_config['database.name'],
'USER': op_config['database.user'],
'PASSWORD': op_config['database.password'],
'HOST': op_config['database.host'],
'PORT': op_config['database.port'],
'NAME': op_env.get('database.name'),
'USER': op_env.get('database.user'),
'PASSWORD': op_env.get('database.password'),
'HOST': op_env.get('database.host'),
'PORT': op_env.get('database.port'),
'OPTIONS': {'charset': 'utf8mb4'},
}
}
@@ -108,7 +110,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = True