Skip to content

Commit 5e04405

Browse files
authored
27406 - Sandbox cleanup (#3372)
1 parent 6ec1035 commit 5e04405

22 files changed

+334
-638
lines changed

auth-api/devops/vaults.gcp.env

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ ENTITY_SVC_CLIENT_ID="op://keycloak/$APP_ENV/entity-service-account/ENTITY_SERVI
1717
ENTITY_SVC_CLIENT_SECRET="op://keycloak/$APP_ENV/entity-service-account/ENTITY_SERVICE_ACCOUNT_CLIENT_SECRET"
1818
API_GW_CONSUMERS_API_URL="op://API/$APP_ENV/api_gw/API_GW_CONSUMERS_API_URL"
1919
API_GW_KEY="op://API/$APP_ENV/api_gw/API_GW_KEY"
20-
API_GW_NON_PROD_KEY="op://API/$APP_ENV/api_gw/API_GW_NON_PROD_KEY"
2120
API_GW_EMAIL_SUFFIX="op://API/$APP_ENV/api_gw/API_GW_EMAIL_SUFFIX"
2221
API_GW_KC_CLIENT_ID_PATTERN="op://API/$APP_ENV/api_gw/API_GW_KC_CLIENT_ID_PATTERN"
23-
API_GW_CONSUMERS_SANDBOX_API_URL="op://API/$APP_ENV/api_gw/API_GW_CONSUMERS_SANDBOX_API_URL"
2422
BCOL_API_URL="op://API/$APP_ENV/bcol-api/BCOL_API_URL"
2523
BCOL_API_VERSION="op://API/$APP_ENV/bcol-api/BCOL_API_VERSION"
2624
NAMEX_API_URL="op://API/$APP_ENV/namex-api/NAMEX_API_URL"
@@ -30,7 +28,6 @@ NOTIFY_API_VERSION="op://API/$APP_ENV/notify-api/NOTIFY_API_VERSION"
3028
PAY_API_URL="op://API/$APP_ENV/pay-api/PAY_API_URL"
3129
PAY_API_VERSION="op://API/$APP_ENV/pay-api/PAY_API_VERSION"
3230
LEGAL_API_URL="op://API/$APP_ENV/legal-api/LEGAL_API_URL"
33-
LEGAL_SANDBOX_API_URL="op://API/sandbox/legal-api/LEGAL_API_URL"
3431
LEGAL_API_VERSION="op://API/$APP_ENV/legal-api/LEGAL_API_VERSION"
3532
LEGAL_API_VERSION_2="op://API/$APP_ENV/legal-api/LEGAL_API_VERSION_2"
3633
AUDIENCE="op://gcp-queue/$APP_ENV/base/AUDIENCE"
@@ -49,9 +46,7 @@ WEB_APP_URL="op://relationship/$APP_ENV/auth-api/WEB_APP_URL"
4946
MAX_NUMBER_OF_ORGS="op://relationship/$APP_ENV/auth-api/MAX_NUMBER_OF_ORGS"
5047
BCOL_ACCOUNT_LINK_CHECK="op://relationship/$APP_ENV/auth-api/BCOL_ACCOUNT_LINK_CHECK"
5148
NR_SUPPORTED_REQUEST_TYPES="op://relationship/$APP_ENV/auth-api/NR_SUPPORTED_REQUEST_TYPES"
52-
PAY_API_SANDBOX_URL=op://relationship/$APP_ENV/auth-api/PAY_API_SANDBOX_URL
53-
DIRECT_PAY_ENABLED="op://relationship/$APP_ENV/pay-api/DIRECT_PAY_ENABLED"
54-
DISABLE_ACTIVITY_LOGS="op://relationship/$APP_ENV/pay-api/DISABLE_ACTIVITY_LOGS"
5549
AUTH_LD_SDK_KEY="op://launchdarkly/$APP_ENV/auth/AUTH_LD_SDK_KEY"
5650
VPC_CONNECTOR="op://CD/$APP_ENV/auth-api/VPC_CONNECTOR"
5751
ENABLE_403_LOGGING="op://relationship/$APP_ENV/auth-api/ENABLE_403_LOGGING"
52+
ENVIRONMENT_NAME="$APP_ENV"

auth-api/docs/dotenv_template

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ PAYBC_CLIENT_SECRET=test
5757
PAYBC_PORTAL_URL=http://localhost:8080
5858
NOTIFY_API_URL="https://mock-lear-tools.pathfinder.gov.bc.ca/rest/SBC+Notify+API+Reference/2.0.0/api/v1"
5959
LEGAL_API_URL="https://legal-api-dev.pathfinder.gov.bc.ca/api/v1"
60-
LEGAL_SANDBOX_API_URL="https://legal-api-dev.pathfinder.gov.bc.ca/api/v1"
6160

6261

6362

auth-api/env.sample

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ ENTITY_SVC_CLIENT_SECRET=
3131

3232
API_GW_CONSUMERS_API_URL=
3333
API_GW_KEY=
34-
API_GW_NON_PROD_KEY=
3534
API_GW_EMAIL_SUFFIX=
3635
API_GW_KC_CLIENT_ID_PATTERN=
37-
API_GW_CONSUMERS_SANDBOX_API_URL=
3836

3937
BCOL_API_URL="https://bcol-api-dev.apps.silver.devops.gov.bc.ca"
4038
BCOL_API_VERSION="/api/v1"
@@ -45,7 +43,6 @@ NOTIFY_API_VERSION="/api/v1"
4543
PAY_API_URL="https://pay-api-dev.apps.silver.devops.gov.bc.ca"
4644
PAY_API_VERSION="/api/v1"
4745
LEGAL_API_URL="https://legal-api-dev.apps.silver.devops.gov.bc.ca"
48-
LEGAL_SANDBOX_API_URL="https://legal-api-dev.apps.silver.devops.gov.bc.ca"
4946
LEGAL_API_VERSION="/api/v1"
5047
LEGAL_API_VERSION_2"/api/v2"
5148

@@ -68,11 +65,8 @@ WEB_APP_URL=
6865
MAX_NUMBER_OF_ORGS="10000"
6966
BCOL_ACCOUNT_LINK_CHECK="False"
7067
NR_SUPPORTED_REQUEST_TYPES="BC,CR,UL,CC,CP"
71-
PAY_API_SANDBOX_URL="""
72-
DIRECT_PAY_ENABLED="true"
73-
DISABLE_ACTIVITY_LOGS="False"
7468

7569
AUTH_LD_SDK_KEY=
7670

7771
# to test real time connection to GCP infrastructure, e.g. cloud store
78-
GOOGLE_APPLICATION_CREDENTIALS=
72+
GOOGLE_APPLICATION_CREDENTIALS=
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
"""Remove environment column from affiliations
2+
3+
Revision ID: bddf9fe7468c
4+
Revises: 0879befaf0b6
5+
Create Date: 2025-04-29 09:49:31.783306
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from sqlalchemy.dialects import postgresql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = 'bddf9fe7468c'
14+
down_revision = '0879befaf0b6'
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
with op.batch_alter_table('affiliations', schema=None) as batch_op:
21+
batch_op.drop_index('ix_affiliations_environment')
22+
batch_op.drop_column('environment')
23+
24+
with op.batch_alter_table('affiliations_history', schema=None) as batch_op:
25+
batch_op.drop_index('ix_affiliations_history_environment')
26+
batch_op.drop_column('environment')
27+
28+
29+
def downgrade():
30+
with op.batch_alter_table('affiliations_history', schema=None) as batch_op:
31+
batch_op.add_column(sa.Column('environment', sa.VARCHAR(length=20), autoincrement=False, nullable=True))
32+
batch_op.create_index('ix_affiliations_history_environment', ['environment'], unique=False)
33+
34+
with op.batch_alter_table('affiliations', schema=None) as batch_op:
35+
batch_op.add_column(sa.Column('environment', sa.VARCHAR(length=20), autoincrement=False, nullable=True))
36+
batch_op.create_index('ix_affiliations_environment', ['environment'], unique=False)
37+
38+

auth-api/src/auth_api/config.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,11 @@ class _Config: # pylint: disable=too-few-public-methods
131131
PAY_API_URL = os.getenv("PAY_API_URL", "") + os.getenv("PAY_API_VERSION", "")
132132

133133
LEGAL_API_URL = os.getenv("LEGAL_API_URL", "")
134-
LEGAL_SANDBOX_API_URL = os.getenv("LEGAL_SANDBOX_API_URL", "")
135134
LEGAL_API_VERSION = os.getenv("LEGAL_API_VERSION")
136135
LEGAL_API_VERSION_2 = os.getenv("LEGAL_API_VERSION_2", "")
137136

138137
LEAR_AFFILIATION_DETAILS_URL = f"{LEGAL_API_URL + LEGAL_API_VERSION_2}/businesses/search"
139138
NAMEX_AFFILIATION_DETAILS_URL = f"{NAMEX_API_URL}/requests/search"
140-
PAY_API_SANDBOX_URL = os.getenv("PAY_API_SANDBOX_URL")
141139

142140
# PUB/SUB - PUB: account-mailer-dev, auth-event-dev
143141
ACCOUNT_MAILER_TOPIC = os.getenv("ACCOUNT_MAILER_TOPIC", "account-mailer-dev")
@@ -174,17 +172,9 @@ class _Config: # pylint: disable=too-few-public-methods
174172

175173
BCOL_ACCOUNT_LINK_CHECK = os.getenv("BCOL_ACCOUNT_LINK_CHECK", "True").lower() == "true"
176174

177-
# Till direct pay is fully ready , keep this value false
178-
DIRECT_PAY_ENABLED = os.getenv("DIRECT_PAY_ENABLED", "False").lower() == "true"
179-
180-
# Config value to disable activity logs
181-
DISABLE_ACTIVITY_LOGS = os.getenv("DISABLE_ACTIVITY_LOGS", "False").lower() == "true"
182-
183175
# API gateway config
184176
API_GW_CONSUMERS_API_URL = os.getenv("API_GW_CONSUMERS_API_URL", None)
185177
API_GW_KEY = os.getenv("API_GW_KEY", None)
186-
API_GW_CONSUMERS_SANDBOX_API_URL = os.getenv("API_GW_CONSUMERS_SANDBOX_API_URL", None)
187-
API_GW_NON_PROD_KEY = os.getenv("API_GW_NON_PROD_KEY", None)
188178
API_GW_EMAIL_SUFFIX = os.getenv("API_GW_EMAIL_SUFFIX", None)
189179
API_GW_KC_CLIENT_ID_PATTERN = os.getenv("API_GW_KC_CLIENT_ID_PATTERN", "api-key-account-{account_id}")
190180

@@ -199,6 +189,8 @@ class _Config: # pylint: disable=too-few-public-methods
199189
# SANDBOX ONLY - needs to be env variable, beacuse PROD and SANDBOX share the same LD. Untested.
200190
SKIP_STAFF_APPROVAL_BCEID = os.getenv("SKIP_STAFF_APPROVAL_BCEID", "False").lower() == "true"
201191

192+
ENVIRONMENT_NAME = os.getenv("ENVIRONMENT_NAME", "local")
193+
202194

203195
class DevConfig(_Config): # pylint: disable=too-few-public-methods
204196
"""Dev Config."""
@@ -296,13 +288,11 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods
296288
ENTITY_SVC_CLIENT_SECRET = os.getenv("KEYCLOAK_TEST_ADMIN_SECRET")
297289

298290
LEGAL_API_URL = "https://mock-auth-tools.pathfinder.gov.bc.ca/rest/legal-api/2.7"
299-
LEGAL_SANDBOX_API_URL = "https://mock-auth-tools.pathfinder.gov.bc.ca/rest/legal-api/2.7"
300291
LEGAL_API_VERSION_2 = "/api/v1"
301292

302293
NOTIFY_API_URL = "http://localhost:8080/notify-api/api/v1"
303294
BCOL_API_URL = "http://localhost:8080/bcol-api/api/v1"
304295
PAY_API_URL = "http://localhost:8080/pay-api/api/v1"
305-
PAY_API_SANDBOX_URL = "http://localhost:8080/pay-api/api/v1"
306296

307297
# If any value is present in this flag, starts up a keycloak docker
308298
USE_TEST_KEYCLOAK_DOCKER = os.getenv("USE_TEST_KEYCLOAK_DOCKER", None)

auth-api/src/auth_api/models/affiliation.py

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,39 +39,28 @@ class Affiliation(
3939
entity_id = Column(ForeignKey("entities.id"), nullable=False, index=True)
4040
org_id = Column(ForeignKey("orgs.id"), nullable=False)
4141
certified_by_name = Column(String(100), nullable=True)
42-
environment = Column(String(20), nullable=True, index=True)
4342

4443
entity = relationship("Entity", foreign_keys=[entity_id], lazy="select")
4544
org = relationship("Org", foreign_keys=[org_id], lazy="select")
4645

4746
@classmethod
48-
def filter_environment(cls, environment: str):
49-
"""Filter affiliation by environment."""
50-
query = cls.query
51-
if environment:
52-
query = query.filter_by(environment=environment)
53-
else:
54-
query = query.filter(Affiliation.environment.is_(None))
55-
return query
56-
57-
@classmethod
58-
def find_affiliation_by_org_and_entity_ids(cls, org_id: int, entity_id: int, environment) -> Affiliation:
47+
def find_affiliation_by_org_and_entity_ids(cls, org_id: int, entity_id: int) -> Affiliation:
5948
"""Return an affiliation for the provided org and entity ids."""
60-
query = cls.filter_environment(environment).filter_by(org_id=int(org_id or -1), entity_id=int(entity_id or -1))
49+
query = cls.query.filter_by(org_id=int(org_id or -1), entity_id=int(entity_id or -1))
6150
return query.one_or_none()
6251

6352
@classmethod
64-
def find_affiliations_by_entity_id(cls, entity_id: int, environment) -> List[Affiliation]:
53+
def find_affiliations_by_entity_id(cls, entity_id: int) -> List[Affiliation]:
6554
"""Return affiliations for the provided entity id."""
66-
return cls.filter_environment(environment).filter_by(entity_id=int(entity_id or -1)).all()
55+
return cls.query.filter_by(entity_id=int(entity_id or -1)).all()
6756

6857
@classmethod
6958
def find_affiliation_by_ids(cls, org_id: int, affiliation_id: int) -> Affiliation:
7059
"""Return the first Affiliation with the provided ids."""
7160
return cls.query.filter_by(org_id=int(org_id or -1)).filter_by(id=int(affiliation_id or -1)).one_or_none()
7261

7362
@classmethod
74-
def find_affiliations_by_org_id(cls, org_id: int, environment: str) -> List[Affiliation]:
63+
def find_affiliations_by_org_id(cls, org_id: int) -> List[Affiliation]:
7564
"""Return the affiliations with the provided org id."""
7665
query = (
7766
db.session.query(Affiliation)
@@ -83,26 +72,15 @@ def find_affiliations_by_org_id(cls, org_id: int, environment: str) -> List[Affi
8372
)
8473
.filter(Affiliation.org_id == int(org_id or -1))
8574
)
86-
if environment:
87-
query = query.filter(Affiliation.environment == environment)
88-
else:
89-
query = query.filter(Affiliation.environment.is_(None))
9075
return query.order_by(Affiliation.created.desc()).all()
9176

9277
@classmethod
93-
def find_affiliations_by_business_identifier(cls, business_identifier: str, environment: str):
78+
def find_affiliations_by_business_identifier(cls, business_identifier: str):
9479
"""Return the affiliations with the provided business identifier."""
95-
return (
96-
cls.filter_environment(environment)
97-
.join(EntityModel)
98-
.filter(EntityModel.business_identifier == business_identifier)
99-
.all()
100-
)
80+
return cls.query.join(EntityModel).filter(EntityModel.business_identifier == business_identifier).all()
10181

10282
@classmethod
103-
def find_affiliation_by_org_id_and_business_identifier(
104-
cls, org_id: int, business_identifier: str, environment: str
105-
) -> Affiliation:
83+
def find_affiliation_by_org_id_and_business_identifier(cls, org_id: int, business_identifier: str) -> Affiliation:
10684
"""Return the affiliations with the provided org id and business identifier."""
10785
query = (
10886
db.session.query(Affiliation)
@@ -115,8 +93,4 @@ def find_affiliation_by_org_id_and_business_identifier(
11593
.filter(Affiliation.org_id == int(org_id or -1))
11694
.filter(EntityModel.business_identifier == business_identifier)
11795
)
118-
if environment:
119-
query = query.filter(Affiliation.environment == environment)
120-
else:
121-
query = query.filter(Affiliation.environment.is_(None))
12296
return query.first()

auth-api/src/auth_api/models/org.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def find_by_org_type(cls, org_type):
153153
return query.all()
154154

155155
@classmethod
156-
def search_org(cls, search: OrgSearch, environment: str):
156+
def search_org(cls, search: OrgSearch):
157157
"""Find all orgs with the given type."""
158158
query = (
159159
db.session.query(Org)
@@ -193,7 +193,7 @@ def search_org(cls, search: OrgSearch, environment: str):
193193

194194
query = query.filter(member_exists_subquery)
195195

196-
query = cls._search_by_business_identifier(query, search.business_identifier, environment)
196+
query = cls._search_by_business_identifier(query, search.business_identifier)
197197
query = cls._search_for_statuses(query, search.statuses)
198198

199199
query = cls.get_order_by(search, query)
@@ -211,12 +211,12 @@ def get_order_by(cls, search, query):
211211
return query.order_by(Org.created.desc())
212212

213213
@classmethod
214-
def search_orgs_by_business_identifier(cls, business_identifier, environment, excluded_org_types: List[str] = None):
214+
def search_orgs_by_business_identifier(cls, business_identifier, excluded_org_types: List[str] = None):
215215
"""Find all orgs affiliated with provided business identifier."""
216216
query = db.session.query(Org)
217217

218218
query = cls._search_for_statuses(query, [])
219-
query = cls._search_by_business_identifier(query, business_identifier, environment)
219+
query = cls._search_by_business_identifier(query, business_identifier)
220220
if excluded_org_types:
221221
query = query.filter(Org.type_code.notin_(excluded_org_types))
222222

@@ -226,9 +226,9 @@ def search_orgs_by_business_identifier(cls, business_identifier, environment, ex
226226
return items, len(items)
227227

228228
@classmethod
229-
def _search_by_business_identifier(cls, query, business_identifier, environment):
229+
def _search_by_business_identifier(cls, query, business_identifier):
230230
if business_identifier:
231-
affilliations = Affiliation.find_affiliations_by_business_identifier(business_identifier, environment)
231+
affilliations = Affiliation.find_affiliations_by_business_identifier(business_identifier)
232232
affilliation_org_ids = [affilliation.org_id for affilliation in affilliations]
233233
query = query.filter(Org.id.in_(affilliation_org_ids))
234234
return query

auth-api/src/auth_api/resources/v1/affiliation_invitation.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from auth_api.utils.auth import jwt as _jwt
2929
from auth_api.utils.endpoints_enums import EndpointEnum
3030
from auth_api.utils.roles import Role
31-
from auth_api.utils.util import get_request_environment
3231

3332
bp = Blueprint("AFFILIATION_INVITATIONS", __name__, url_prefix=f"{EndpointEnum.API_V1.value}/affiliationInvitations")
3433

@@ -84,7 +83,6 @@ def get_affiliation_invitations():
8483
)
8584
def post_affiliation_invitation():
8685
"""Send a new affiliation invitation using the details in request and saves the affiliation invitation."""
87-
environment = get_request_environment()
8886
origin = request.environ.get("HTTP_ORIGIN", current_app.config.get("WEB_APP_URL"))
8987
request_json = request.get_json()
9088
valid_format, errors = schema_utils.validate(request_json, "affiliation_invitation")
@@ -93,7 +91,7 @@ def post_affiliation_invitation():
9391
try:
9492
user = UserService.find_by_jwt_token()
9593
response, status = (
96-
AffiliationInvitationService.create_affiliation_invitation(request_json, user, origin, environment).as_dict(
94+
AffiliationInvitationService.create_affiliation_invitation(request_json, user, origin).as_dict(
9795
mask_email=True
9896
),
9997
HTTPStatus.CREATED,
@@ -167,7 +165,6 @@ def delete_affiliation_invitation(affiliation_invitation_id):
167165
def accept_affiliation_invitation_token(affiliation_invitation_id, affiliation_invitation_token):
168166
"""Check whether the passed token is valid and add affiliation from the affiliation invitation."""
169167
origin = request.environ.get("HTTP_ORIGIN", current_app.config.get("WEB_APP_URL"))
170-
environment = get_request_environment()
171168

172169
try:
173170
if not (user := UserService.find_by_jwt_token()):
@@ -182,7 +179,7 @@ def accept_affiliation_invitation_token(affiliation_invitation_id, affiliation_i
182179
)
183180
response, status = (
184181
AffiliationInvitationService.accept_affiliation_invitation(
185-
affiliation_invitation_id, user, origin, environment
182+
affiliation_invitation_id, user, origin
186183
).as_dict(mask_email=True),
187184
HTTPStatus.OK,
188185
)
@@ -197,7 +194,6 @@ def accept_affiliation_invitation_token(affiliation_invitation_id, affiliation_i
197194
def patch_affiliation_invitation_authorization(affiliation_invitation_id, authorize_action):
198195
"""Check if user is active part of the Org. Authorize/Refuse Authorization invite if he is."""
199196
origin = request.environ.get("HTTP_ORIGIN", current_app.config.get("WEB_APP_URL"))
200-
env = get_request_environment()
201197

202198
try:
203199
user = UserService.find_by_jwt_token()
@@ -206,7 +202,7 @@ def patch_affiliation_invitation_authorization(affiliation_invitation_id, author
206202
if authorize_action == "accept":
207203
response, status = (
208204
AffiliationInvitationService.accept_affiliation_invitation(
209-
affiliation_invitation_id=affiliation_invitation_id, user=user, origin=origin, environment=env
205+
affiliation_invitation_id=affiliation_invitation_id, user=user, origin=origin
210206
).as_dict(mask_email=True),
211207
HTTPStatus.OK,
212208
)

0 commit comments

Comments
 (0)