Skip to content

Commit

Permalink
MHR API verify new CI script.
Browse files Browse the repository at this point in the history
Signed-off-by: Doug Lovett <[email protected]>
  • Loading branch information
doug-lovett committed Dec 11, 2024
1 parent dde71c3 commit c512eb1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 475 deletions.
1 change: 0 additions & 1 deletion mhr-api/devops/vaults.gcp.env
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,3 @@ DOC_SERVICE_CONFIG='op://ppr/$APP_ENV/mhr-api/DOC_SERVICE_CONFIG'
GUNICORN_PROCESSES="op://ppr/$APP_ENV/mhr-api/GUNICORN_PROCESSES"
GUNICORN_THREADS="op://ppr/$APP_ENV/mhr-api/GUNICORN_THREADS"
REPORT_VERSION="op://ppr/$APP_ENV/mhr-api/REPORT_VERSION"
REPORT_API_AUDIENCE=op://API/$APP_ENV/report-api-gotenberg/REPORT_API_GOTENBERG_URL"
24 changes: 6 additions & 18 deletions mhr-api/src/mhr_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
from mhr_api.utils.auth import jwt
from mhr_api.utils.logging import logger, setup_logging

setup_logging(
os.path.join(os.path.abspath(os.path.dirname(__file__)), "logging.yaml")
) # important to do this first
setup_logging(os.path.join(os.path.abspath(os.path.dirname(__file__)), "logging.yaml")) # important to do this first


def create_app(service_environment=APP_RUNNING_ENVIRONMENT, **kwargs):
Expand All @@ -49,16 +47,12 @@ def create_app(service_environment=APP_RUNNING_ENVIRONMENT, **kwargs):

db.init_app(app)
Migrate(app, db)
if (
app.config.get("DEPLOYMENT_ENV", "") == "unitTesting"
): # CI only run upgrade for unit testing.
if app.config.get("DEPLOYMENT_ENV", "") == "testing": # CI only run upgrade for unit testing.
logger.info("Running db upgrade.")
with app.app_context():
upgrade(directory="migrations", revision="head", sql=False, tag=None)
# Alembic has it's own logging config, we'll need to restore our logging here.
setup_logging(
os.path.join(os.path.abspath(os.path.dirname(__file__)), "logging.yaml")
)
setup_logging(os.path.join(os.path.abspath(os.path.dirname(__file__)), "logging.yaml"))
logger.info("Finished db upgrade.")
else:
logger.info("Logging, migrate set up.")
Expand Down Expand Up @@ -112,9 +106,7 @@ def setup_test_data():
"""Load unit test data in the dev/local environment. Delete all existing test data as a first step."""
try:
test_path = os.getcwd()
logger.info(
f"Executing DB scripts to create test data from test data dir {test_path}..."
)
logger.info(f"Executing DB scripts to create test data from test data dir {test_path}...")
# execute_script(db.session, os.path.join(test_path, "test_data/postgres_test_reset.sql"))
execute_script(db.session, "test_data/postgres_create_first.sql")
filenames = os.listdir(os.path.join(test_path, "test_data/postgres_data_files"))
Expand All @@ -126,16 +118,12 @@ def setup_test_data():
)
# execute_script(db.session, "test_data/postgres_test_reset_ppr.sql")
execute_script(db.session, "test_data/postgres_create_first_ppr.sql")
filenames = os.listdir(
os.path.join(os.getcwd(), "test_data/postgres_data_files_ppr")
)
filenames = os.listdir(os.path.join(os.getcwd(), "test_data/postgres_data_files_ppr"))
sorted_names = sorted(filenames)
for filename in sorted_names:
execute_script(
db.session,
os.path.join(
os.getcwd(), ("test_data/postgres_data_files_ppr/" + filename)
),
os.path.join(os.getcwd(), ("test_data/postgres_data_files_ppr/" + filename)),
)
except Exception as err: # pylint: disable=broad-except # noqa F841;
logger.error(f"setup_test_data failed: {str(err)}")
Expand Down
40 changes: 10 additions & 30 deletions mhr-api/src/mhr_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ class Config: # pylint: disable=too-few-public-methods
if DB_UNIX_SOCKET := os.getenv("DATABASE_UNIX_SOCKET", None):
SQLALCHEMY_DATABASE_URI = f"postgresql+psycopg2://{DB_USER}:{DB_PASSWORD}@/{DB_NAME}?host={DB_UNIX_SOCKET}"
else:
SQLALCHEMY_DATABASE_URI = (
f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
)
SQLALCHEMY_DATABASE_URI = f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"

# Connection pool settings
DB_MIN_POOL_SIZE = os.getenv("DATABASE_MIN_POOL_SIZE", "2")
Expand Down Expand Up @@ -142,9 +140,7 @@ class Config: # pylint: disable=too-few-public-methods
# ACCOUNT_SVC_TIMEOUT = os.g

# DB Query limits on result set sizes
ACCOUNT_REGISTRATIONS_MAX_RESULTS = os.getenv(
"ACCOUNT_REGISTRATIONS_MAX_RESULTS", "100"
)
ACCOUNT_REGISTRATIONS_MAX_RESULTS = os.getenv("ACCOUNT_REGISTRATIONS_MAX_RESULTS", "100")
ACCOUNT_DRAFTS_MAX_RESULTS = os.getenv("ACCOUNT_DRAFTS_MAX_RESULTS", "1000")
ACCOUNT_SEARCH_MAX_RESULTS = os.getenv("ACCOUNT_SEARCH_MAX_RESULTS", "1000")

Expand All @@ -159,45 +155,31 @@ class Config: # pylint: disable=too-few-public-methods

# Google APIs and cloud storage
GOOGLE_DEFAULT_SA = os.getenv("GOOGLE_DEFAULT_SA")
GCP_CS_SA_SCOPES = os.getenv(
"GCP_CS_SA_SCOPES", "https://www.googleapis.com/auth/cloud-platform"
)
GCP_CS_SA_SCOPES = os.getenv("GCP_CS_SA_SCOPES", "https://www.googleapis.com/auth/cloud-platform")
# Storage of search reports
GCP_CS_BUCKET_ID = os.getenv("GCP_CS_BUCKET_ID", "mhr_search_result_report_dev")
# Storage of registration verification reports
GCP_CS_BUCKET_ID_REGISTRATION = os.getenv(
"GCP_CS_BUCKET_ID_REGISTRATION", "mhr_registration_report_dev"
)
GCP_CS_BUCKET_ID_REGISTRATION = os.getenv("GCP_CS_BUCKET_ID_REGISTRATION", "mhr_registration_report_dev")
# Storage of batch reports
GCP_CS_BUCKET_ID_BATCH = os.getenv("GCP_CS_BUCKET_ID_BATCH", "mhr_batch_report_dev")
# Storage of service agreement terms reports
GCP_CS_BUCKET_ID_TERMS = os.getenv(
"GCP_CS_BUCKET_ID_TERMS", "mhr_service_agreement_dev"
)
GCP_CS_BUCKET_ID_TERMS = os.getenv("GCP_CS_BUCKET_ID_TERMS", "mhr_service_agreement_dev")

# Pub/Sub
GCP_PS_PROJECT_ID = os.getenv("DEPLOYMENT_PROJECT", "eogruh-dev")
GCP_PS_SEARCH_REPORT_TOPIC = os.getenv(
"GCP_PS_SEARCH_REPORT_TOPIC", "mhr-search-report"
)
GCP_PS_REGISTRATION_REPORT_TOPIC = os.getenv(
"GCP_PS_REGISTRATION_REPORT_TOPIC", "mhr-registration-report"
)
GCP_PS_SEARCH_REPORT_TOPIC = os.getenv("GCP_PS_SEARCH_REPORT_TOPIC", "mhr-search-report")
GCP_PS_REGISTRATION_REPORT_TOPIC = os.getenv("GCP_PS_REGISTRATION_REPORT_TOPIC", "mhr-registration-report")

GATEWAY_URL = os.getenv("GATEWAY_URL", "https://bcregistry-dev.apigee.net")
GATEWAY_LTSA_URL = os.getenv(
"GATEWAY_LTSA_URL", "https://bcregistry-test.apigee.net/ltsa/api/v1"
)
GATEWAY_LTSA_URL = os.getenv("GATEWAY_LTSA_URL", "https://bcregistry-test.apigee.net/ltsa/api/v1")
SUBSCRIPTION_API_KEY = os.getenv("SUBSCRIPTION_API_KEY")
GATEWAY_API_KEY = os.getenv("GATEWAY_API_KEY")

# Search results data size threshold for real time reports.
MAX_SIZE_SEARCH_RT: int = int(os.getenv("MAX_SIZE_SEARCH_RT", "200000"))
# Default 2, set to 1 to revert to original report api client
REPORT_VERSION = os.getenv("REPORT_VERSION", "2")
REPORT_API_AUDIENCE = os.getenv(
"REPORT_API_AUDIENCE", "https://gotenberg-p56lvhvsqa-nn.a.run.app"
)
REPORT_API_AUDIENCE = os.getenv("REPORT_API_AUDIENCE", "https://gotenberg-p56lvhvsqa-nn.a.run.app")

NOTIFY_MAN_REG_CONFIG = os.getenv("NOTIFY_MAN_REG_CONFIG")
NOTIFY_LOCATION_CONFIG = os.getenv("NOTIFY_LOCATION_CONFIG")
Expand Down Expand Up @@ -250,9 +232,7 @@ class UnitTestingConfig(Config): # pylint: disable=too-few-public-methods
DB_HOST = os.getenv("DATABASE_TEST_HOST", "")
DB_PORT = os.getenv("DATABASE_TEST_PORT", "5432")
# SQLALCHEMY_DATABASE_URI = f"postgresql+pg8000://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
SQLALCHEMY_DATABASE_URI = (
f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"
)
SQLALCHEMY_DATABASE_URI = f"postgresql://{DB_USER}:{DB_PASSWORD}@{DB_HOST}:{DB_PORT}/{DB_NAME}"

# JWT OIDC settings
# JWT_OIDC_TEST_MODE will set jwt_manager to use
Expand Down
2 changes: 1 addition & 1 deletion mhr-api/src/mhr_api/utils/admin_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from mhr_api.models import MhrRegistration
from mhr_api.models import registration_utils as reg_utils
from mhr_api.models.type_tables import MhrDocumentTypes, MhrNoteStatusTypes, MhrRegistrationTypes
from mhr_api.utils import validator_utils, validator_owner_utils
from mhr_api.utils import validator_owner_utils, validator_utils
from mhr_api.utils.logging import logger

NCAN_DOC_TYPES = " CAU CAUC CAUE NCON NPUB REGC REST " # Set of doc types NCAN can cancel.
Expand Down
Loading

0 comments on commit c512eb1

Please sign in to comment.