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

Proof of Concept TDP Based Kibana Auth #2775

Merged
merged 152 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
f8a4d54
Added formating for header and autofit columns
raftmsohani Oct 19, 2023
29fd04c
Formatted the headers
raftmsohani Oct 20, 2023
699245c
added year/month to the columns
raftmsohani Oct 20, 2023
5310946
Added contants - translation column
raftmsohani Oct 23, 2023
0269728
added friendly names to T1 and T2
raftmsohani Oct 25, 2023
ac120a6
added friendly name to m1 and m2
raftmsohani Oct 26, 2023
a7c1207
added friendly name to m3
raftmsohani Oct 26, 2023
d460fe2
added friendly_name to t3
raftmsohani Oct 27, 2023
2bb6622
added friendly_name to t4 and t5
raftmsohani Oct 27, 2023
c90ce75
added friendly_name to t7
raftmsohani Oct 27, 2023
9dfd6f8
correct missing friendly_name
raftmsohani Oct 27, 2023
90aea2f
correction on failing tests
raftmsohani Oct 27, 2023
8f210cd
addedfriendly name to excel report
raftmsohani Oct 30, 2023
a093aa0
linting
raftmsohani Oct 30, 2023
8ea36c6
linting
raftmsohani Oct 30, 2023
85da10b
linting
raftmsohani Oct 30, 2023
ac95c41
delete contants.py
raftmsohani Oct 30, 2023
d75ba04
added test for json field in error model
raftmsohani Oct 30, 2023
ea5aa30
linting
raftmsohani Oct 31, 2023
b4d0549
linting
raftmsohani Oct 31, 2023
8ce83ce
linting
raftmsohani Oct 31, 2023
c75bb7e
2599-added friendly name to postparsing validators
raftmsohani Nov 1, 2023
0ec8f16
refining the validator tests
raftmsohani Nov 7, 2023
359dae0
added returning fields names to validators
raftmsohani Nov 8, 2023
8ed0b4a
added friendly_name to error field
raftmsohani Nov 13, 2023
c57a2d5
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 14, 2023
812a2dd
linting
raftmsohani Nov 14, 2023
96634b2
corrections on views/tests
raftmsohani Nov 14, 2023
0be491f
corrections for fields
raftmsohani Nov 15, 2023
02ce7d0
failing test corrected
raftmsohani Nov 15, 2023
aa8a534
failing test corrected
raftmsohani Nov 15, 2023
19926ea
correcting test failures
raftmsohani Nov 15, 2023
6b7c86e
linting
raftmsohani Nov 16, 2023
94ef180
corrected the excel fiel generator
raftmsohani Nov 16, 2023
b6eee03
removed excessive space in validator
raftmsohani Nov 20, 2023
49dc398
linting
raftmsohani Nov 20, 2023
b0fd38a
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 20, 2023
700a965
listing
raftmsohani Nov 20, 2023
8aae444
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 21, 2023
9636854
added m6
raftmsohani Nov 21, 2023
5c2e819
lint
raftmsohani Nov 21, 2023
763c09b
corrected new line break
raftmsohani Nov 22, 2023
3e73dbc
refactored validator logic
raftmsohani Nov 22, 2023
e1c9c9a
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 25, 2023
dcc1dca
linting and correction on t1
raftmsohani Nov 25, 2023
741b442
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 25, 2023
28c9636
friendly_name correction from comments
raftmsohani Nov 25, 2023
091e716
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
raftmsohani Nov 25, 2023
3e19f2d
friendly_name correction
raftmsohani Nov 25, 2023
c2501f8
corrected failing test for m5
raftmsohani Nov 25, 2023
b04df52
refactor the field_json creation DRY
raftmsohani Nov 27, 2023
206696a
- Added Kibana config
elipe17 Nov 29, 2023
ad17b56
friendly_name corrections
raftmsohani Nov 30, 2023
efc15bd
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Nov 30, 2023
86e3024
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
elipe17 Dec 4, 2023
25eb85e
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Dec 4, 2023
d2d443d
linting and cleaning errors
raftmsohani Dec 4, 2023
573a056
linting
raftmsohani Dec 4, 2023
b1be7bb
correction on friendly_names
raftmsohani Dec 4, 2023
cad9173
corrected friendly_name for test_util
raftmsohani Dec 4, 2023
aa6a5ad
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Dec 4, 2023
4bce93d
correction child care - number of months
raftmsohani Dec 4, 2023
d29ed8e
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
raftmsohani Dec 4, 2023
bd29c09
fixed a few more typos and some spacing. (#2767)
George-Hudson Dec 5, 2023
657379d
- Added basic security to Kibana/Elastic
elipe17 Dec 5, 2023
eb59146
- Remove debug code
elipe17 Dec 5, 2023
ae41efd
- change provider name
elipe17 Dec 5, 2023
100d647
- Updating settings to reference environment variables
elipe17 Dec 5, 2023
beda306
Merge branch 'develop' into 2599-error-report-corrections-impact-wpr-…
raftmsohani Dec 6, 2023
13cd218
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Dec 6, 2023
1536749
- Add elastic dependency
elipe17 Dec 6, 2023
bde9160
- Fix network issue
elipe17 Dec 6, 2023
0316025
- Added bulk creation of elastic indices
elipe17 Dec 6, 2023
acfb697
- Updated schemas to reference model based off of elastic document
elipe17 Dec 7, 2023
522ca38
- Remove password auth from elastic/kibana
elipe17 Dec 7, 2023
a62a345
- Remove password auth
elipe17 Dec 7, 2023
6dd34a0
- Fix tests
elipe17 Dec 7, 2023
1809129
- Fix lint
elipe17 Dec 7, 2023
640db6e
- remove debug print
elipe17 Dec 7, 2023
96e48d0
Merge branch '2599-error-report-corrections-impact-wpr-metrics' of ht…
elipe17 Dec 7, 2023
5f0fddf
Merge branch '1858-kibana-ofa-access' of https://github.com/raft-tech…
elipe17 Dec 7, 2023
556221b
Changes for fully local development
Nov 29, 2023
32a4671
Reorganized front end logic on REACT_APP_DEVAUTH env var
Dec 5, 2023
7fd7b4d
Reorganized backend logic on REACT_APP_DEVAUTH env var
Dec 5, 2023
15d4019
- Added proof on concept for tdp based kibana auth
elipe17 Dec 8, 2023
c806553
- Fixing type issue
elipe17 Dec 8, 2023
6ffbee8
added is_superuser and is_staff attrs to dev user
Dec 8, 2023
1e11ac8
- Add group check
elipe17 Dec 9, 2023
4057007
- Add frontend group check for kibana
elipe17 Dec 9, 2023
37f6975
- fix lint
elipe17 Dec 9, 2023
ccee755
- Fix lint errors
elipe17 Dec 9, 2023
00007c6
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
elipe17 Dec 9, 2023
2efe22c
- Fix doc strings
elipe17 Dec 9, 2023
34e6be6
- Adding authenticated permission
elipe17 Dec 12, 2023
86aae24
- Renaming variables to clarify things
elipe17 Dec 13, 2023
01bfd0b
- fix lint
elipe17 Dec 13, 2023
edde9d4
Revert "- Remove password auth from elastic/kibana"
elipe17 Dec 13, 2023
e066b50
- Setting up anonymous users with kibana_admin privileges
elipe17 Dec 13, 2023
3acf5e7
- Adding password to settings in cloud.gov
elipe17 Dec 13, 2023
478ea50
- remove incorrect auth
elipe17 Dec 13, 2023
5638153
- Add elastic profile
elipe17 Dec 13, 2023
1497d4a
DevAuth feature redesign inspired by Cypress
Dec 14, 2023
2febdcd
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
Dec 14, 2023
97a0cf6
Fixed CustomAuthentication.authenticate return val for login.py use case
Dec 14, 2023
2b9b46f
Fixed CustomAuthentication.authenticate logging for login.py use case
Dec 14, 2023
c18383f
Removed unneeded permissions import
Dec 14, 2023
7fc2a09
Updates to REACT_APP_DEVAUTH env var settings
Dec 14, 2023
900efa8
- debugging env vars
elipe17 Dec 14, 2023
784530e
- Testing what settings are used
elipe17 Dec 14, 2023
d9dbcfe
Revert "- debugging env vars"
elipe17 Dec 14, 2023
b3ec595
Revert "- Testing what settings are used"
elipe17 Dec 14, 2023
8cea014
- debugging env vars again
elipe17 Dec 14, 2023
61ac063
- Switching to container networking
elipe17 Dec 15, 2023
4bf8957
Restored support for CustomAuthentication.authenticate username keyword
Dec 15, 2023
761e4eb
Modified CustomAuthentication.authenticate comment to satisfy flake8
Dec 15, 2023
4693d17
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
elipe17 Dec 16, 2023
1aeb315
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Dec 18, 2023
a284856
commit
elipe17 Dec 18, 2023
b8d7577
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
elipe17 Dec 18, 2023
30ee5ed
asdfgvasd
elipe17 Dec 18, 2023
1f9f32d
Revert "Modified CustomAuthentication.authenticate comment to satisfy…
elipe17 Dec 19, 2023
eacffe9
Revert "Restored support for CustomAuthentication.authenticate userna…
elipe17 Dec 19, 2023
71615d2
Revert "Updates to REACT_APP_DEVAUTH env var settings"
elipe17 Dec 19, 2023
bd6edd1
Revert "Removed unneeded permissions import"
elipe17 Dec 19, 2023
65b32ce
Revert "Fixed CustomAuthentication.authenticate logging for login.py …
elipe17 Dec 19, 2023
c49365f
Revert "Fixed CustomAuthentication.authenticate return val for login.…
elipe17 Dec 19, 2023
7bb7522
Revert "DevAuth feature redesign inspired by Cypress"
elipe17 Dec 19, 2023
af2d342
Revert "commit"
elipe17 Dec 19, 2023
d88a329
Revert "added is_superuser and is_staff attrs to dev user"
elipe17 Dec 19, 2023
247347c
Revert "Reorganized backend logic on REACT_APP_DEVAUTH env var"
elipe17 Dec 19, 2023
8205b43
Revert "Reorganized front end logic on REACT_APP_DEVAUTH env var"
elipe17 Dec 19, 2023
e32cb0d
Revert "Changes for fully local development"
elipe17 Dec 19, 2023
26455b4
asdf
elipe17 Dec 19, 2023
e9e0d78
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
elipe17 Dec 19, 2023
702c547
- Adding integration tests for elastic bulk doc creation
elipe17 Dec 20, 2023
6c97446
Revert "asdf"
elipe17 Dec 20, 2023
ffb1993
- fix lint
elipe17 Dec 20, 2023
8026eae
fasdf
elipe17 Dec 20, 2023
6ae551f
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Jan 9, 2024
2ed9d25
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Jan 9, 2024
f1b8a8b
- Added usage of document to tribal
elipe17 Jan 10, 2024
a658806
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
elipe17 Jan 10, 2024
8d24f72
Merge branch 'develop' into elastic-bulk-doc-creation
andrew-jameson Jan 12, 2024
f206b24
- Updated based on feedback
elipe17 Jan 17, 2024
715ced8
- Fixing error
elipe17 Jan 17, 2024
3fdb9db
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Jan 17, 2024
a10383d
Merge branch 'elastic-bulk-doc-creation' of https://github.com/raft-t…
elipe17 Jan 17, 2024
3b02261
- Updating frontend to only allow access to kibana sitemap if the use…
elipe17 Jan 18, 2024
9a43a53
Merge branch 'develop' of https://github.com/raft-tech/TANF-app into …
elipe17 Jan 18, 2024
4c4f4e2
- fix lint
elipe17 Jan 18, 2024
a18db6e
Merge branch 'develop' into 1858-kibana-ofa-access
andrew-jameson Jan 22, 2024
6577cd2
Merge branch 'develop' into 1858-kibana-ofa-access
andrew-jameson Feb 12, 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
2 changes: 2 additions & 0 deletions tdrs-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Copy this file to `.env` and replace variables as needed
#

#REACT_APP_DEVAUTH=1

# ##
# Required environment variables
# These must be defined or the application will encounter fatal errors
Expand Down
2 changes: 1 addition & 1 deletion tdrs-backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ django-elasticsearch-dsl = "==7.3"
django-elasticsearch-dsl-drf = "==0.22.5"
requests-aws4auth = "==1.1.2"
cerberus = "==1.3.4"
xlsxwriter = "==3.0.1"
xlsxwriter = "==3.1.9"
sendgrid = "==6.10.0"

[requires]
Expand Down
719 changes: 387 additions & 332 deletions tdrs-backend/Pipfile.lock

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion tdrs-backend/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,25 @@ services:
# Copy in the Localstack setup script to configure any buckets needed
- ../scripts/localstack-setup.sh:/docker-entrypoint-initaws.d/localstack-setup.sh

kibana:
image: elastic/kibana:7.17.10
ports:
- 5601:5601
environment:
- xpack.security.encryptionKey="something_at_least_32_characters"
- xpack.security.session.idleTimeout="1h"
- xpack.security.session.lifespan="30d"
volumes:
- ./kibana.yml:/usr/share/kibana/config/kibana.yml
depends_on:
- elastic

elastic:
image: elasticsearch:7.17.6
environment:
- discovery.type=single-node
- xpack.security.enabled=false
- logger.discovery.level=debug
- xpack.security.enabled=false
ports:
- 9200:9200
- 9300:9300
Expand Down Expand Up @@ -88,6 +101,7 @@ services:
- CYPRESS_TOKEN
- DJANGO_DEBUG
- SENDGRID_API_KEY
- BYPASS_KIBANA_AUTH
volumes:
- .:/tdpapp
image: tdp
Expand Down
2 changes: 2 additions & 0 deletions tdrs-backend/kibana.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elasticsearch.hosts: ["http://elastic:9200"]
server.host: kibana
3 changes: 3 additions & 0 deletions tdrs-backend/tdpservice/data_files/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,15 @@ class DataFileViewSet(ModelViewSet):

def create(self, request, *args, **kwargs):
"""Override create to upload in case of successful scan."""
logger.debug(f"{self.__class__.__name__}: {request}")
response = super().create(request, *args, **kwargs)

# only if file is passed the virus scan and created successfully will we perform side-effects:
# * Send to parsing
# * Upload to ACF-TITAN
# * Send email to user

logger.debug(f"{self.__class__.__name__}: status: {response.status_code}")
if response.status_code == status.HTTP_201_CREATED or response.status_code == status.HTTP_200_OK:
user = request.user
data_file_id = response.data.get('id')
Expand Down Expand Up @@ -109,6 +111,7 @@ def create(self, request, *args, **kwargs):
if len(recipients) > 0:
send_data_submitted_email(list(recipients), data_file, email_context, subject)

logger.debug(f"{self.__class__.__name__}: return val: {response}")
return response

def get_s3_versioning_id(self, file_name, prefix):
Expand Down
30 changes: 25 additions & 5 deletions tdrs-backend/tdpservice/parsers/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@
class Field:
"""Provides a mapping between a field name and its position."""

def __init__(self, item, name, type, startIndex, endIndex, required=True, validators=[]):
def __init__(
self,
item,
name,
friendly_name,
type,
startIndex,
endIndex,
required=True,
validators=[],
):
self.item = item
self.name = name
self.friendly_name = friendly_name
self.type = type
self.startIndex = startIndex
self.endIndex = endIndex
Expand All @@ -36,25 +47,34 @@ def parse_value(self, line):
return None

match self.type:
case 'number':
case "number":
try:
value = int(value)
return value
except ValueError:
logger.error(f"Error parsing field value: {value} to integer.")
return None
case 'string':
case "string":
return value
case _:
logger.warn(f"Unknown field type: {self.type}.")
return None


class TransformField(Field):
"""Represents a field that requires some transformation before serializing."""

def __init__(self, transform_func, item, name, type, startIndex, endIndex, required=True,
def __init__(self, transform_func, item, name, friendly_name, type, startIndex, endIndex, required=True,
validators=[], **kwargs):
super().__init__(item, name, type, startIndex, endIndex, required, validators)
super().__init__(
item=item,
name=name,
type=type,
friendly_name=friendly_name,
startIndex=startIndex,
endIndex=endIndex,
required=required,
validators=validators)
self.transform_func = transform_func
self.kwargs = kwargs

Expand Down
1 change: 0 additions & 1 deletion tdrs-backend/tdpservice/parsers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class Status(models.TextChoices):
def get_status(self):
"""Set and return the status field based on errors and models associated with datafile."""
errors = ParserError.objects.filter(file=self.datafile)
[print(error) for error in errors]

# excluding row-level pre-checks and trailer pre-checks.
precheck_errors = errors.filter(error_type=ParserErrorCategoryChoices.PRE_CHECK)\
Expand Down
30 changes: 18 additions & 12 deletions tdrs-backend/tdpservice/parsers/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,27 @@ def parse_datafile(datafile):

return errors


def bulk_create_records(unsaved_records, line_number, header_count, batch_size=10000, flush=False):
"""Bulk create passed in records."""
if (line_number % batch_size == 0 and header_count > 0) or flush:
logger.debug("Bulk creating records.")
try:
num_created = 0
num_expected = 0
for model, records in unsaved_records.items():
num_expected += len(records)
num_created += len(model.objects.bulk_create(records))
if num_created != num_expected:
logger.error(f"Bulk create only created {num_created}/{num_expected}!")
num_records_created = 0
num_expected_records = 0
num_documents_created = 0
for document, records in unsaved_records.items():
num_expected_records += len(records)
created_objs = document.Django.model.objects.bulk_create(records)
num_documents_created += document.update(created_objs)[0]
num_records_created += len(created_objs)
if num_records_created != num_expected_records:
logger.error(f"Bulk Django record creation only created {num_records_created}/{num_expected_records}!")
elif num_documents_created != num_expected_records:
logger.error(f"Bulk Elastic document creation only created {num_documents_created}/" +
f"{num_expected_records}!")
else:
logger.info(f"Created {num_created}/{num_expected} records.")
return num_created == num_expected, {}
logger.info(f"Created {num_records_created}/{num_expected_records} records.")
return num_records_created == num_expected_records and num_documents_created == num_expected_records, {}
except DatabaseError as e:
logger.error(f"Encountered error while creating datafile records: {e}")
return False, unsaved_records
Expand Down Expand Up @@ -107,7 +112,8 @@ def evaluate_trailer(datafile, trailer_count, multiple_trailer_errors, is_last_l
def rollback_records(unsaved_records, datafile):
"""Delete created records in the event of a failure."""
logger.info("Rolling back created records.")
for model in unsaved_records:
for document in unsaved_records:
model = document.Django.model
num_deleted, models = model.objects.filter(datafile=datafile).delete()
logger.debug(f"Deleted {num_deleted} records of type: {model}.")

Expand Down Expand Up @@ -198,7 +204,7 @@ def parse_datafile_lines(datafile, program_type, section, is_encrypted):
if record:
s = schema_manager.schemas[i]
record.datafile = datafile
unsaved_records.setdefault(s.model, []).append(record)
unsaved_records.setdefault(s.document, []).append(record)

all_created, unsaved_records = bulk_create_records(unsaved_records, line_number, header_count,)
unsaved_parser_errors, num_errors = bulk_create_errors(unsaved_parser_errors, num_errors)
Expand Down
14 changes: 8 additions & 6 deletions tdrs-backend/tdpservice/parsers/row_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class RowSchema:

def __init__(
self,
model=dict,
document,
preparsing_validators=[],
postparsing_validators=[],
fields=[],
quiet_preparser_errors=False
quiet_preparser_errors=False,
):
self.model = model
self.document = document
self.preparsing_validators = preparsing_validators
self.postparsing_validators = postparsing_validators
self.fields = fields
Expand Down Expand Up @@ -90,7 +90,7 @@ def run_preparsing_validators(self, line, generate_error):

def parse_line(self, line):
"""Create a model for the line based on the schema."""
record = self.model()
record = self.document.Django.model() if self.document is not None else dict()

for field in self.fields:
value = field.parse_value(line)
Expand Down Expand Up @@ -151,16 +151,18 @@ def run_postparsing_validators(self, instance, generate_error):
errors = []

for validator in self.postparsing_validators:
validator_is_valid, validator_error = validator(instance)
validator_is_valid, validator_error, field_names = validator(instance)
is_valid = False if not validator_is_valid else is_valid
if validator_error:
# get field from field name
fields = [self.get_field_by_name(name) for name in field_names]
errors.append(
generate_error(
schema=self,
error_category=ParserErrorCategoryChoices.VALUE_CONSISTENCY,
error_message=validator_error,
record=instance,
field=None
field=fields,
)
)

Expand Down
Loading
Loading