Skip to content
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

project scaffold changes #6

Merged
merged 55 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
d751c9f
initial auth scaffold and what sam needs to begin with
trevoratindustrio Apr 26, 2024
fcce981
adding basic account page
Apr 26, 2024
3344e9a
changing page name to account-select
Apr 26, 2024
b8b079e
Merge branch 'main' into sam/account-page
Apr 26, 2024
f504ff3
Merge pull request #3 from turb0c0w/trevor/auth
trevoratindustrio Apr 26, 2024
291afc4
running lint fix
Apr 26, 2024
ff64706
resolving merge conflicts
Apr 26, 2024
bbb3cde
adding header and menu
Apr 26, 2024
e1913d2
adding nav changes
Apr 26, 2024
d8251b9
removing dupe account page
Apr 26, 2024
72df0f6
adding integration
Apr 26, 2024
25f644d
formatting
Apr 26, 2024
3120692
fixing layout
Apr 26, 2024
f562ad3
Merge pull request #4 from turb0c0w/sam/account-page
samIndustrio Apr 26, 2024
6d716ab
adding button styling
Apr 26, 2024
9a853af
adding fixes for warning console
Apr 26, 2024
c762041
adding styling fixes
Apr 26, 2024
a6d3157
fixing footer height
Apr 26, 2024
2b0db88
adding responsiveness
Apr 26, 2024
cc0ae5b
adding responsive styling
Apr 26, 2024
b5b8696
adding correct address
Apr 26, 2024
66b0613
Merge pull request #5 from turb0c0w/sam/account-page
samIndustrio Apr 26, 2024
cf3f9f6
adding alt text and meta tag
Apr 26, 2024
9a13103
hiding logged out menu on mobile
Apr 26, 2024
0e9ff7f
adding please log in message
Apr 26, 2024
6278486
Merge pull request #6 from turb0c0w/sam/account-page
samIndustrio Apr 26, 2024
e4c2370
functionally complete, cleanup, pre-tests
trevoratindustrio Apr 27, 2024
7aba1e3
unit tests getting there
trevoratindustrio Apr 27, 2024
bc22cc8
e2e simplify for initial use
trevoratindustrio Apr 28, 2024
004ca63
bit more cleanup, ready to actually test
trevoratindustrio Apr 28, 2024
a67dcce
small unit change
trevoratindustrio Apr 29, 2024
fb43808
Merge pull request #7 from turb0c0w/trevor/cleanupandtests
trevoratindustrio Apr 29, 2024
9e8d984
adding mock login data
Apr 29, 2024
5c6b53e
adding conditional
Apr 29, 2024
c9b848a
Merge pull request #8 from turb0c0w/sam/mock-login
samIndustrio Apr 29, 2024
1b7e697
quick fix for test data for ux review
trevoratindustrio Apr 29, 2024
a459665
Merge pull request #9 from turb0c0w/trevor/testfix
trevoratindustrio Apr 29, 2024
17932a8
re-enable auth and linting cleanup
trevoratindustrio Apr 29, 2024
05eb57f
Merge pull request #10 from turb0c0w/trevor/reauth
trevoratindustrio Apr 29, 2024
3f59fab
fixing tests
Apr 29, 2024
8cd96d3
api lint cleanup
turb0c0w Apr 28, 2024
006fd7c
improve code coverage
turb0c0w Apr 28, 2024
7ac7e18
fix api ci working dir
turb0c0w Apr 30, 2024
0310ec5
isort and black changes
turb0c0w Apr 30, 2024
e36815f
add missing init
turb0c0w Apr 30, 2024
ec162a1
change postgres port for pytest ci
turb0c0w Apr 30, 2024
7ac77ff
adding vitest config
Apr 30, 2024
af81577
removing launch darkly
Apr 30, 2024
fdcf333
fixing linting
Apr 30, 2024
1b3c63d
Merge branch 'main' into sam/account-tests
samIndustrio Apr 30, 2024
4fc4b53
fixing linting
Apr 30, 2024
48c41da
fixing linting
Apr 30, 2024
77d098e
replacing accounts data
Apr 30, 2024
dacbf03
remove pytest.ini to not break pyproject.toml addopts
turb0c0w Apr 30, 2024
d045a52
Merge pull request #11 from turb0c0w/sam/account-tests
samIndustrio Apr 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/strr-api-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ name: STRR API CI
on:
pull_request:
paths:
- "api/**"
- "strr-api/**"
workflow_dispatch:

defaults:
run:
shell: bash
working-directory: ./api
working-directory: ./strr-api

jobs:
strr-api-ci:
uses: bcgov/bcregistry-sre/.github/workflows/backend-ci.yaml@main
with:
app_name: "strr-api"
working_directory: "./api"
working_directory: "./strr-api"
codecov_flag: "strrapi"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,5 @@ htmlcov/
**/bods_csvs/*

run.sh
lint.sh
unit-tests.sh
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
- db

db:
image: postgres:latest
image: postgres:16
restart: unless-stopped
volumes:
- postgres-data:/var/lib/postgresql/data
Expand Down
4 changes: 2 additions & 2 deletions strr-api/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ APP_SETTINGS=dev
DATABASE_USERNAME=postgres
DATABASE_PASSWORD=postgres
DATABASE_NAME=postgres
DATABASE_HOST=localhost
DATABASE_PORT=15432
DATABASE_HOST=db
DATABASE_PORT=5432

## TEST DB
DATABASE_TEST_USERNAME=postgres
Expand Down
Empty file added strr-api/__init__.py
Empty file.
8 changes: 4 additions & 4 deletions strr-api/gunicorn_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

import os

workers = int(os.environ.get('GUNICORN_PROCESSES', '1')) # pylint: disable=invalid-name
threads = int(os.environ.get('GUNICORN_THREADS', '1')) # pylint: disable=invalid-name
workers = int(os.environ.get("GUNICORN_PROCESSES", "1")) # pylint: disable=invalid-name
threads = int(os.environ.get("GUNICORN_THREADS", "1")) # pylint: disable=invalid-name

forwarded_allow_ips = '*' # pylint: disable=invalid-name
secure_scheme_headers = {'X-Forwarded-Proto': 'https'} # pylint: disable=invalid-name
forwarded_allow_ips = "*" # pylint: disable=invalid-name
secure_scheme_headers = {"X-Forwarded-Proto": "https"} # pylint: disable=invalid-name
64 changes: 53 additions & 11 deletions strr-api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions strr-api/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "strr-api"
version = "0.2.1"
version = "0.0.1"
description = ""
authors = ["thorwolpert <[email protected]>"]
license = "BSD 3-Clause"
Expand All @@ -18,13 +18,14 @@ sql-versioning = { git = "https://github.com/bcgov/lear.git", subdirectory = "py
sentry-sdk = "^1.24.0"
flask-babel = "^4.0.0"
flask-cors = "^4.0.0"
flask-jwt-oidc = "^0.3.0"
flask-jwt-oidc = "0.6.0"
gunicorn = "^21.2.0"
jsonschema = {extras = ["format"], version = "^4.20.0"}
pycountry = "^23.12.11"
psycopg2-binary = "^2.9.9"
flask-restx = "^1.3.0"
pytest-env = "^1.1.3"
coloredlogs = "^15.0.1"

[tool.poetry.group.test.dependencies]
freezegun = "^1.2.2"
Expand Down
7 changes: 0 additions & 7 deletions strr-api/pytest.ini

This file was deleted.

46 changes: 33 additions & 13 deletions strr-api/src/strr_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,69 +35,89 @@

This module is the API for the Legal Entity system.
"""
import logging
import logging.config
import os

import coloredlogs
import sentry_sdk
from flask import Flask
from flask_cors import CORS
from flask_migrate import Migrate, upgrade
from sentry_sdk.integrations.flask import FlaskIntegration
from flask import Flask

from .common.auth import jwt
from .common.flags import Flags
from .common.run_version import get_run_version
from .config import Config, Production
from .logging import set_log_level_by_flag, setup_logging
from .models import db
from .resources import register_endpoints
from .services import strr_entity, strr_pay
from .services import strr_pay
from .translations import babel

setup_logging(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.conf')) # important to do this first
# logging.config.fileConfig(fname=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'logging.conf'))
logging.basicConfig(level=logging.DEBUG)
coloredlogs.install()
logger = logging.getLogger("api")


def create_app(environment: Config = Production, **kwargs) -> Flask:
"""Return a configured Flask App using the Factory method."""
app = Flask(__name__)
CORS(app)
app.config.from_object(environment)
app.logger.setLevel(logging.DEBUG)

# Configure Sentry
if dsn := app.config.get('SENTRY_DSN', None):
if dsn := app.config.get("SENTRY_DSN", None):
sentry_sdk.init(
dsn=dsn,
integrations=[FlaskIntegration()],
release=f'strr-api@{get_run_version()}',
release=f"strr-api@{get_run_version()}",
send_default_pii=False,
environment=app.config.get('POD_NAMESPACE', 'unknown')
environment=app.config.get("POD_NAMESPACE", "unknown"),
)

db.init_app(app)

if not app.config.get("TESTING", False):
Migrate(app, db)
logger.info("Running migration upgrade.")
with app.app_context():
upgrade(directory="migrations", revision="head", sql=False, tag=None)

strr_pay.init_app(app)
strr_entity.init_app(app)
# td is testData instance passed in to support testing
td = kwargs.get('ld_test_data', None)
td = kwargs.get("ld_test_data", None)
Flags().init_app(app, td)
babel.init_app(app)
register_endpoints(app)
setup_jwt_manager(app, jwt)

@app.before_request
def before_request(): # pylint: disable=unused-variable
set_log_level_by_flag()
flag_name = os.getenv("OPS_LOGGER_LEVEL_FLAG", None)
if flag_name:
flag_value = Flags.value(flag_name)
if (level_name := logging.getLevelName(logging.getLogger().level)) and flag_value != level_name:
logger.error("Logger level is %s, setting to %s", level_name, flag_value)
logging.getLogger().setLevel(level=flag_value)

@app.after_request
def add_version(response): # pylint: disable=unused-variable
version = get_run_version()
response.headers['API'] = f'strr-api/{version}'
response.headers["API"] = f"strr-api/{version}"
return response

return app


def setup_jwt_manager(app, jwt_manager):
"""Use flask app to configure the JWTManager to work for a particular Realm."""

def get_roles(a_dict):
return a_dict['realm_access']['roles'] # pragma: no cover
app.config['JWT_ROLE_CALLBACK'] = get_roles
return a_dict["realm_access"]["roles"] # pragma: no cover

app.config["JWT_ROLE_CALLBACK"] = get_roles

jwt_manager.init_app(app)
1 change: 0 additions & 1 deletion strr-api/src/strr_api/common/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@
"""Bring in the common JWT Manager."""
from flask_jwt_oidc import JwtManager


jwt = JwtManager() # pylint: disable=invalid-name; lower case name as used by convention in most Flask apps
3 changes: 1 addition & 2 deletions strr-api/src/strr_api/common/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
# POSSIBILITY OF SUCH DAMAGE.
"""Enum Utilities."""
from enum import auto # noqa: F401 pylint: disable=W0611
from enum import Enum
from enum import EnumMeta
from enum import Enum, EnumMeta
from typing import Optional


Expand Down
3 changes: 1 addition & 2 deletions strr-api/src/strr_api/common/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
from werkzeug.exceptions import HTTPException
from werkzeug.routing import RoutingException


logger = logging.getLogger(__name__)
logger = logging.getLogger("api")


def init_app(app):
Expand Down
Loading
Loading