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

Match a local system with remote system in CSAM integration #263

Open
wants to merge 23 commits into
base: develop-aspen
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6e5d68f
Integrating API data into new Aspen Summary page
gregelin May 24, 2022
455579c
Display Aspen description output safe with html
gregelin May 24, 2022
dba72a0
Fix Aspen CSAM purpose field
gregelin May 24, 2022
063f4e2
Truncate Aspen summary system purpose text
gregelin May 24, 2022
5f43ea2
Code linting
gregelin May 25, 2022
196cf26
Refactor retrieving integrations data DRY
gregelin May 25, 2022
791f9e0
Replace lorem static txt in system_events
gregelin May 25, 2022
1462ed2
Merge branch 'develop-aspen' into develop-aspen-dynamic
gregelin May 25, 2022
fea5919
Merge branch 'develop-aspen' into develop-aspen-dynamic
gregelin May 25, 2022
a6a87bd
Small fixes to csam integration
gregelin May 26, 2022
c6e8441
Display each integrations base_url on Aspen integrations page
gregelin May 26, 2022
0d60ab2
Start adding Aspen Components, POA&Ms pages
gregelin May 26, 2022
8d71cea
Continuing to build out Aspen summary pages
gregelin May 26, 2022
e17de42
Components Aspen summary page working
gregelin May 26, 2022
1b7bef3
Added Selected Controls Aspen summary page
gregelin May 26, 2022
02cef45
Style links in Aspen summary horoz nav
gregelin May 26, 2022
abab8d4
Truncating component descriptions to avoid line overlap
gregelin May 26, 2022
482996d
Display system projects on Aspen summary page
gregelin May 29, 2022
688a07f
Merge branch 'develop-aspen' into develop-aspen-dynamic
gregelin May 31, 2022
41ac00c
Improvements to OIDC authentication and role management (#254)
gregelin Jun 1, 2022
74717b3
Add match_system_from_remote method to csam integration
gregelin Jun 1, 2022
fa795e9
Fix SSO admin role assignment.
gregelin Jun 1, 2022
0f61f39
Sync with develop-aspen 06-17-22
gregelin Jun 18, 2022
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
5 changes: 3 additions & 2 deletions controls/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,8 @@ def system_summary_1_aspen(request, system_id):
context = {
"system": system_summary,
#"project": project,
"project": projects,
"projects": projects,
"project": project,
"system_events": system_events,
# "deployments": deployments,
"display_urls": project_context(project)
Expand Down Expand Up @@ -4103,7 +4104,7 @@ def system_summary_aspen(request, system_id):

context = {
"system": system_summary,
#"project": project,
"project": project,
"projects": projects,
"system_events": system_events,
# "deployments": deployments,
Expand Down
1 change: 1 addition & 0 deletions integrations/csam/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

url(r"^local/system/(?P<system_id>.*)$", views.get_paired_remote_system_info_using_local_system_id, name=f'{INTEGRATION_NAME}_csam_system_info'),

url(r"^match_system_from_remote/(?P<remote_system_id>.*)$", views.match_system_from_remote, name='match_system_from_remote'),
url(r"^create_system_from_remote/$", views.create_system_from_remote, name=f'{INTEGRATION_NAME}_create_system_from_remote'),
url(r"^create_system_from_remote/(?P<remote_system_id>.*)$", views.create_system_from_remote, name=f'{INTEGRATION_NAME}_create_system_from_remote'),

Expand Down
48 changes: 47 additions & 1 deletion integrations/csam/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ def get_system_info(request, system_id=2):

def get_paired_remote_system_info_using_local_system_id(request, system_id=2):
"""Retrieve the system information from CSAM"""

system = get_object_or_404(System, pk=system_id)
# try:
# # system = System.objects.get(pk=system_id)
Expand Down Expand Up @@ -280,6 +279,53 @@ def match_system_from_remote(request, remote_system_id):

print("Match a system in GovReady-Q based on info from integrated service")

communication = set_integration()
csam_system_id = int(remote_system_id)
endpoint = f'/v1/systems/{csam_system_id}'
# is there local information?
ep, created = Endpoint.objects.get_or_create(
integration=INTEGRATION,
endpoint_path=endpoint
)
# TODO: Refresh data if empty
if created:
# Cache not available
data = communication.get_response(endpoint)
# Cache remote data locally in database
ep.data = data
ep.save()
else:
# Cache available
cached = True
pass
# Check if remote_system_name matches name of a system in GovReady-Q
if System.objects.filter(Q(root_element__name=ep.data['name'])).exists():
#name matches
matched_systems = System.objects.filter(Q(root_element__name=ep.data['name']))
if len(matched_systems) == 1:
matched_system = matched_systems[0]
if matched_system.info == {}:
matched_system.info = {"csam_system_id": csam_system_id }
matched_system.save()
msg = f"Matched existing System {matched_system.id} in GovReady based on CSAM system name {ep.data['name']}."
else:
msg = f"System {matched_system.id} in GovReady already matched to CSAM system id for \"{ep.data['name']}\"."
else:
msg = f"More than one system in GovReady matched to CSAM system name \"{ep.data['name']}\"."
else:
msg = f"No system in GovReady matched to CSAM system name \"{ep.data['name']}\"."
return HttpResponse(
f"<html><body><p>{msg}</p>"
f"<p>now: {datetime.now()}</p>"
f"<p>Returned data:</p>"
f"<pre>{json.dumps(ep.data,indent=4)}</pre>"
f"</body></html>")

def create_system_from_remote(request, remote_system_id):
"""Create a system in GovReady-Q based on info from integrated service"""

print("Create a system in GovReady-Q based on info from integrated service")

communication = set_integration()
csam_system_id = int(remote_system_id)
endpoint = f'/v1/systems/{csam_system_id}'
Expand Down