-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor sync functions into separate files
Signed-off-by: Hans Wernetti <[email protected]>
- Loading branch information
Showing
5 changed files
with
130 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
from typing import Any | ||
from typing import Dict | ||
|
||
import neo4j | ||
import requests | ||
|
||
from cartography.client.core.tx import load | ||
from cartography.models.semgrep.deployment import SemgrepDeploymentSchema | ||
from cartography.stats import get_stats_client | ||
from cartography.util import timeit | ||
|
||
logger = logging.getLogger(__name__) | ||
stat_handler = get_stats_client(__name__) | ||
_TIMEOUT = (60, 60) | ||
|
||
|
||
@timeit | ||
def get_deployment(semgrep_app_token: str) -> Dict[str, Any]: | ||
""" | ||
Gets the deployment associated with the passed Semgrep App token. | ||
param: semgrep_app_token: The Semgrep App token to use for authentication. | ||
""" | ||
deployment = {} | ||
deployment_url = "https://semgrep.dev/api/v1/deployments" | ||
headers = { | ||
"Content-Type": "application/json", | ||
"Authorization": f"Bearer {semgrep_app_token}", | ||
} | ||
response = requests.get(deployment_url, headers=headers, timeout=_TIMEOUT) | ||
response.raise_for_status() | ||
|
||
data = response.json() | ||
deployment["id"] = data["deployments"][0]["id"] | ||
deployment["name"] = data["deployments"][0]["name"] | ||
deployment["slug"] = data["deployments"][0]["slug"] | ||
|
||
return deployment | ||
|
||
|
||
@timeit | ||
def load_semgrep_deployment( | ||
neo4j_session: neo4j.Session, deployment: Dict[str, Any], update_tag: int, | ||
) -> None: | ||
logger.info(f"Loading Semgrep deployment info {deployment} into the graph...") | ||
load( | ||
neo4j_session, | ||
SemgrepDeploymentSchema(), | ||
[deployment], | ||
lastupdated=update_tag, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters