-
Notifications
You must be signed in to change notification settings - Fork 9
Adiciona endpoint que recebe dados de coleção do core. #341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a48e6ed
8e58d74
937ae43
e00eb70
74a57c6
90d2e49
305993d
625dc7f
0488045
bae1b77
7409146
89cef51
3238cc0
45b5db8
89248b9
81e47d1
5d60f66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,3 +80,4 @@ opac/webapp/media/images/*.* | |
|
|
||
| # nodejs/gulp/etc | ||
| node_modules/ | ||
| data | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| -----BEGIN PUBLIC KEY----- | ||
| MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAg2CAMS9xU5wlcIgD+lHv | ||
| HjmeehX1FjB0T3oJl2e5XEnI7OvqrtQTnp8Y9PQd8tjUICgeFr17mzvHDHgwBhRd | ||
| A0h0oZp0EJTr7DdsBGleV5yjLpFl8rTW8DHwWrrj0Lz91Ym527qpiosyuoBKhFRV | ||
| bN9P5ZepUyYKVzEuxPAIb2R2NBde6Ggf5p7y3RtYDRZsK0tzy2KlQree2u8Dau6a | ||
| 8uS7F66h9lxg8gz6iNe2zz1OFQL1efgR4pxMYryVH58Qo3VPcgCTbf1YUoXmvnaR | ||
| iXK/otcp3RemJtsz8u5gAi81Rk71co6YRGcUF9C+IyGjx+N4qzX4iC+CY/TsuBPm | ||
| xwIDAQAB | ||
| -----END PUBLIC KEY----- |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -690,3 +690,12 @@ | |||||||||||||||||||||||||||||||||||||||||||
| ANALYTICS_AGENT_DARKVISITORS_ENABLED = os.environ.get('OPAC_ANALYTICS_AGENT_DARKVISITORS_ENABLED', 'False').lower() in ('true', '1', 't', 'yes', 'y') | ||||||||||||||||||||||||||||||||||||||||||||
| ANALYTICS_AGENT_DARKVISITORS_PROJECT_KEY = os.environ.get("OPAC_ANALYTICS_AGENT_DARKVISITORS_PROJECT_KEY") | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| # JWT PARA ENDPOINT CORE TO COLLECTION | ||||||||||||||||||||||||||||||||||||||||||||
| JWT_PUBLIC_KEY_PATH = os.environ.get("JWT_PUBLIC_KEY_PATH", default="/app/jwt_public.pem") | ||||||||||||||||||||||||||||||||||||||||||||
| with open(JWT_PUBLIC_KEY_PATH, "rb") as f: | ||||||||||||||||||||||||||||||||||||||||||||
| JWT_PUBLIC_KEY_PEM = f.read() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+695
to
+697
|
||||||||||||||||||||||||||||||||||||||||||||
| with open(JWT_PUBLIC_KEY_PATH, "rb") as f: | |
| JWT_PUBLIC_KEY_PEM = f.read() | |
| def get_jwt_public_key_pem(): | |
| """ | |
| Reads the JWT public key from the configured path. | |
| Returns the key contents as bytes. | |
| Raises FileNotFoundError with a clear message if the file is missing. | |
| """ | |
| try: | |
| with open(JWT_PUBLIC_KEY_PATH, "rb") as f: | |
| return f.read() | |
| except FileNotFoundError: | |
| raise FileNotFoundError( | |
| f"JWT public key file not found at '{JWT_PUBLIC_KEY_PATH}'. " | |
| "Please ensure the file exists and the path is correct." | |
| ) | |
| except Exception as e: | |
| raise RuntimeError( | |
| f"An error occurred while reading the JWT public key file at '{JWT_PUBLIC_KEY_PATH}': {e}" | |
| ) |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,11 +6,9 @@ | |||||||||
| ou outras camadas superiores, evitando assim que as camadas superiores | ||||||||||
| acessem diretamente a camada inferior de modelos. | ||||||||||
| """ | ||||||||||
| import logging | ||||||||||
| import io | ||||||||||
| import logging | ||||||||||
| import re | ||||||||||
| import requests | ||||||||||
| from bs4 import BeautifulSoup | ||||||||||
| from collections import OrderedDict | ||||||||||
| from datetime import datetime | ||||||||||
| from uuid import uuid4 | ||||||||||
|
|
@@ -24,26 +22,18 @@ | |||||||||
| from flask_mongoengine import Pagination | ||||||||||
| from legendarium.formatter import descriptive_very_short_format | ||||||||||
| from mongoengine import Q | ||||||||||
| from mongoengine.errors import InvalidQueryError | ||||||||||
| from opac_schema.v1.models import ( | ||||||||||
| Article, | ||||||||||
| Collection, | ||||||||||
| Issue, | ||||||||||
| Journal, | ||||||||||
| News, | ||||||||||
| Pages, | ||||||||||
| PressRelease, | ||||||||||
| Sponsor, | ||||||||||
| LastIssue, | ||||||||||
| ) | ||||||||||
| from opac_schema.v1.models import (Article, Collection, Issue, Journal, | ||||||||||
| LastIssue, News, Pages, PressRelease, | ||||||||||
| Sponsor) | ||||||||||
| from scieloh5m5 import h5m5 | ||||||||||
| from slugify import slugify | ||||||||||
| from webapp import dbsql | ||||||||||
|
|
||||||||||
| from .choices import INDEX_NAME, JOURNAL_STATUS, STUDY_AREAS | ||||||||||
| from .factory import ArticleFactory, IssueFactory, JournalFactory | ||||||||||
| from .models import User | ||||||||||
| from .factory import JournalFactory, IssueFactory, ArticleFactory | ||||||||||
| from .utils import utils | ||||||||||
| from .utils.handler_with_logo import handler_with_logo | ||||||||||
|
|
||||||||||
| HIGHLIGHTED_TYPES = ( | ||||||||||
| "article-commentary", | ||||||||||
|
|
@@ -174,6 +164,143 @@ def get_collection_tweets(): | |||||||||
| return [] | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def extract_collection_names(json_data): | ||||||||||
| data ={} | ||||||||||
| for name in json_data.get("collection_names"): | ||||||||||
| if name.get("language"): | ||||||||||
| lang = name.get("language").get("code2") | ||||||||||
| data[lang] = name.get("text") | ||||||||||
| return data | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def set_attributtes_logos(collection, logos, name_logos=["home_logo", "logo_menu", "header_logo"], langs=["pt", "en", "es"]): | ||||||||||
| """ | ||||||||||
| Atribuí os logos do modelo collection. (home_logo, logo_menu, header_logo) | ||||||||||
| Ex: | ||||||||||
|
Comment on lines
+178
to
+179
|
||||||||||
| Atribuí os logos do modelo collection. (home_logo, logo_menu, header_logo) | |
| Ex: | |
| Assigns the logos to the collection model. (home_logo, logo_menu, header_logo) | |
| Example: |
Copilot
AI
Oct 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import statement should be at the top of the file, not inside a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@samuelveigarangel isso pode fazer parte do dado registrado no core. Assim evita processamento excessivo e a ordem é garantida na origem.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,22 @@ | ||||||
| import logging | ||||||
| from functools import wraps | ||||||
|
|
||||||
| from flask import g, jsonify | ||||||
| from jwt import PyJWTError | ||||||
|
|
||||||
| from .helper import get_bearer_token, verify_jwt | ||||||
|
|
||||||
|
|
||||||
| def require_jwt(f): | ||||||
| @wraps(f) | ||||||
| def wrapper(*args, **kwargs): | ||||||
| token = get_bearer_token() | ||||||
| if not token: | ||||||
| return jsonify({"detail": "Missing Bearer token"}), 401 | ||||||
| try: | ||||||
| g.jwt = verify_jwt(token) | ||||||
| except PyJWTError as e: | ||||||
| logging.error("Erro na validação JWT:", str(e)) | ||||||
|
||||||
| logging.error("Erro na validação JWT:", str(e)) | |
| logging.error("Error validating JWT:", str(e)) |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,4 @@ | ||||||||||||||||||||||||||||||||
| import logging | ||||||||||||||||||||||||||||||||
| import datetime | ||||||||||||||||||||||||||||||||
| from functools import wraps | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
@@ -68,3 +69,35 @@ def auth(): | |||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||
| 401, | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def get_bearer_token(): | ||||||||||||||||||||||||||||||||
| auth = request.headers.get("Authorization", "") | ||||||||||||||||||||||||||||||||
| if auth.startswith("Bearer "): | ||||||||||||||||||||||||||||||||
| return auth[len("Bearer "):] | ||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def get_jwt_public_key(): | ||||||||||||||||||||||||||||||||
| public_key = current_app.config["JWT_PUBLIC_KEY_PATH"] | ||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||
| with open(public_key, "rb") as f: | ||||||||||||||||||||||||||||||||
| return f.read() | ||||||||||||||||||||||||||||||||
| except (FileNotFoundError, PermissionError, OSError) as e: | ||||||||||||||||||||||||||||||||
| logging.error(f"Error reading public key: {e}") | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| def verify_jwt(token): | ||||||||||||||||||||||||||||||||
| public_key = get_jwt_public_key() | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if not public_key: | ||||||||||||||||||||||||||||||||
| return None | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return jwt.decode( | ||||||||||||||||||||||||||||||||
| token, | ||||||||||||||||||||||||||||||||
| public_key, | ||||||||||||||||||||||||||||||||
| algorithms=[current_app.config["JWT_ALG"]], | ||||||||||||||||||||||||||||||||
| audience=current_app.config["JWT_AUD"], | ||||||||||||||||||||||||||||||||
| issuer=current_app.config["JWT_ISS"], | ||||||||||||||||||||||||||||||||
| # options={"require": ["exp", "iat", "nbf", "iss", "aud"]}, | ||||||||||||||||||||||||||||||||
|
Comment on lines
+95
to
+101
|
||||||||||||||||||||||||||||||||
| return jwt.decode( | |
| token, | |
| public_key, | |
| algorithms=[current_app.config["JWT_ALG"]], | |
| audience=current_app.config["JWT_AUD"], | |
| issuer=current_app.config["JWT_ISS"], | |
| # options={"require": ["exp", "iat", "nbf", "iss", "aud"]}, | |
| # Enforce presence of standard claims for robust JWT validation | |
| return jwt.decode( | |
| token, | |
| public_key, | |
| algorithms=[current_app.config["JWT_ALG"]], | |
| audience=current_app.config["JWT_AUD"], | |
| issuer=current_app.config["JWT_ISS"], | |
| options={"require": ["exp", "iat", "nbf", "iss", "aud"]}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File operations at module level should include proper error handling. If the JWT public key file doesn't exist or is unreadable, this will cause the application to fail during import.