Skip to content

Commit 4e0c111

Browse files
author
Glenn Snyder
committed
removing private api endpoints previously used for working with snippets
1 parent 0c57ded commit 4e0c111

File tree

2 files changed

+1
-122
lines changed

2 files changed

+1
-122
lines changed

blackduck/HubRestApi.py

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -597,17 +597,6 @@ def _check_version_compatibility(self):
597597
if int(self.bd_major_version) < 2018:
598598
raise UnsupportedBDVersion("The BD major version {} is less than the minimum required major version {}".format(self.bd_major_version, 2018))
599599

600-
def get_file_bom_entries(self, hub_release_id, limit=100):
601-
self._check_version_compatibility()
602-
paramstring = self.get_limit_paramstring(limit)
603-
# Using internal API - see https://jira.dc1.lan/browse/HUB-18270: Make snippet API calls for ignoring, confirming snippet matches public
604-
url = "{}/v1/releases/{}/file-bom-entries{}".format(self.get_apibase(), hub_release_id)
605-
url += paramstring
606-
logging.debug("GET {}".format(url))
607-
response = self.execute_get(url)
608-
jsondata = response.json()
609-
return jsondata
610-
611600
def get_file_matches_for_bom_component(self, bom_component, limit=1000):
612601
self._check_version_compatibility()
613602
url = self.get_link(bom_component, "matched-files")
@@ -617,116 +606,6 @@ def get_file_matches_for_bom_component(self, bom_component, limit=1000):
617606
jsondata = response.json()
618607
return jsondata
619608

620-
def get_snippet_bom_entries(self, project_id, version_id, reviewed=False, included=False, limit=100, offset=0):
621-
self._check_version_compatibility()
622-
paramstring = "?limit=" + str(limit) + "&offset=" + \
623-
str(offset) + "&filter=bomReviewStatus:" + str(reviewed).lower() + "&filter=bomInclusion:" + str(included).lower()
624-
# Using internal API - see https://jira.dc1.lan/browse/HUB-18270: Make snippet API calls for ignoring, confirming snippet matches public
625-
path = "{}/internal/projects/{}/versions/{}/snippet-bom-entries".format(self.get_apibase(), project_id, version_id)
626-
url = path + paramstring
627-
response = self.execute_get(url)
628-
jsondata = response.json()
629-
return jsondata
630-
631-
def ignore_snippet_bom_entry(self, hub_version_id, snippet_bom_entry):
632-
self._check_version_compatibility()
633-
# Using internal API - see https://jira.dc1.lan/browse/HUB-18270: Make snippet API calls for ignoring, confirming snippet matches public
634-
url = "{}/v1/releases/{}/snippet-bom-entries".format(self.get_apibase(), hub_version_id)
635-
body = self.get_ignore_snippet_json(snippet_bom_entry)
636-
response = self.execute_put(url, body)
637-
jsondata = response.json()
638-
return jsondata
639-
640-
def get_ignore_snippet_json(self, snippet_bom_entry):
641-
self._check_version_compatibility()
642-
for cur_fileSnippetBomComponents in snippet_bom_entry['fileSnippetBomComponents']:
643-
cur_fileSnippetBomComponents['ignored'] = True
644-
return [snippet_bom_entry]
645-
646-
def confirm_snippet_bom_entry(self, hub_version_id, snippet_bom_entry):
647-
self._check_version_compatibility()
648-
# Using internal API - see https://jira.dc1.lan/browse/HUB-18270: Make snippet API calls for ignoring, confirming snippet matches public
649-
url = "{}/v1/releases/{}/snippet-bom-entries".format(self.get_apibase(), hub_version_id)
650-
body = self.get_confirm_snippet_json(snippet_bom_entry)
651-
response = self.execute_put(url, body)
652-
jsondata = response.json()
653-
return jsondata
654-
655-
def get_confirm_snippet_json(self, snippet_bom_entry):
656-
self._check_version_compatibility()
657-
for cur_fileSnippetBomComponents in snippet_bom_entry['fileSnippetBomComponents']:
658-
cur_fileSnippetBomComponents['reviewStatus'] = 'REVIEWED'
659-
cur_fileSnippetBomComponents['ignored'] = False
660-
return [snippet_bom_entry]
661-
662-
def edit_snippet_bom_entry(self, hub_version_id, snippet_bom_entry, new_kb_component):
663-
self._check_version_compatibility()
664-
# Using internal API - see https://jira.dc1.lan/browse/HUB-18270: Make snippet API calls for ignoring, confirming snippet matches public
665-
url = "{}/v1/releases/{}/snippet-bom-entries".format(self.get_apibase(), hub_version_id)
666-
body = self.get_edit_snippet_json(snippet_bom_entry, new_kb_component)
667-
response = self.execute_put(url, body)
668-
jsondata = response.json()
669-
return jsondata
670-
671-
def get_edit_snippet_json(self, snippet_bom_entry, new_kb_component):
672-
self._check_version_compatibility()
673-
assert 'fileSnippetBomComponents' in snippet_bom_entry
674-
assert len(snippet_bom_entry['fileSnippetBomComponents']) == 1, "We can only edit the component info for one snippet match at a time"
675-
676-
# TODO: Handle case where either the component from snippet_bom_entry OR new_kb_component does not have a version?
677-
snippet_component_info = snippet_bom_entry['fileSnippetBomComponents'][0]
678-
snippet_component_info['project']['id'] = new_kb_component['component'].split("/")[-1]
679-
snippet_component_info['release']['id'] = new_kb_component['componentVersion'].split("/")[-1]
680-
return [snippet_bom_entry]
681-
682-
def get_alternate_matches_for_snippet(self, project_id, version_id, snippet_object):
683-
self._check_version_compatibility()
684-
version_bom_entry_id = snippet_object['fileSnippetBomComponents'][0]['versionBomEntryId']
685-
686-
# Using internal API - see https://jira.dc1.lan/browse/HUB-18270: Make snippet API calls for ignoring, confirming snippet matches public
687-
url = "{}/internal/projects/{}/versions/{}/alternate-snippet-matches/{}".format(
688-
self.get_apibase(), project_id, version_id, version_bom_entry_id)
689-
response = self.execute_get(url)
690-
jsondata = response.json()
691-
alternate_matches = list()
692-
for snippet_bom_components_d in jsondata['snippetMatches']:
693-
for snippet_bom_component in snippet_bom_components_d['snippetBomComponents']:
694-
alternate_matches.append(snippet_bom_component)
695-
return alternate_matches
696-
697-
def find_matching_alternative_snippet_match(self, project_id, version_id, snippet_object, kb_component):
698-
# Given a KB component, find the matching alternative snippet match for a given snippet BOM entry
699-
# Returns None if no match was found
700-
kb_component_id = kb_component['component'].split("/")[-1]
701-
# TODO: handle cases where there is no version supplied?
702-
kb_component_version_id = kb_component['componentVersion'].split("/")[-1]
703-
for alternative_match in self.get_alternate_matches_for_snippet(project_id, version_id, snippet_object):
704-
alternative_match_component_id = alternative_match['project']['id']
705-
alternative_match_component_version_id = alternative_match['release']['id']
706-
if kb_component_id == alternative_match_component_id and kb_component_version_id == alternative_match_component_version_id:
707-
return alternative_match
708-
709-
def _generate_new_match_selection(self, original_snippet_match, new_component_match):
710-
# Merge the values from new_component_match into the origingal_snippet_match
711-
# Note: Must do the merge to preserver other key/value pairs in the original_snippet_match (e.g. ignored, reviewStatus, versionBomComponentId)
712-
# TODO: Can there ever be more than one item in fileSnippetBomComponents?
713-
for k in original_snippet_match['fileSnippetBomComponents'][0].keys():
714-
if k in new_component_match:
715-
original_snippet_match['fileSnippetBomComponents'][0][k] = new_component_match[k]
716-
return [original_snippet_match]
717-
718-
def update_snippet_match(self, version_id, current_snippet_match, new_snippet_match_component):
719-
# Update the (snippet) component selection for a given snippet match
720-
# Assumption: new_snippet_match_component is from one of the alternate matches listed for the file snippet match
721-
self._check_version_compatibility()
722-
headers = self.get_headers()
723-
headers['ContentType'] = "application/json"
724-
# Using internal API - see https://jira.dc1.lan/browse/HUB-18270: Make snippet API calls for ignoring, confirming snippet matches public
725-
url = "{}/v1/releases/{}/snippet-bom-entries".format(self.get_apibase(), version_id)
726-
body = self._generate_new_match_selection(current_snippet_match, new_snippet_match_component)
727-
response = self.execute_put(url, body)
728-
jsondata = response.json()
729-
return jsondata
730609

731610
##
732611
#

blackduck/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
VERSION = (0, 0, 35)
1+
VERSION = (0, 0, 36)
22

33
__version__ = '.'.join(map(str, VERSION))

0 commit comments

Comments
 (0)