Skip to content

Commit

Permalink
add - dummy collection point for monolith subproject (#882)
Browse files Browse the repository at this point in the history
* add - dummy collection point for monolith subproject

* fix - PR

* fix PR
  • Loading branch information
khemrajrathore authored Dec 15, 2023
1 parent b893baa commit be60743
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions src/main/scala/ai/privado/exporter/CollectionExporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,44 @@ class CollectionExporter(cpg: Cpg, ruleCache: RuleCache, repoItemTagName: Option
/** Processes collection points and return final output
*/
def getCollections: List[CollectionModel] = {
getCollectionsByMethods ++ getCollectionsByTemplateDom ++ getCollectionsByAndroidXmlFieldIds
getCollectionsByMethods ++ getCollectionsByTemplateDom ++ getCollectionsByAndroidXmlFieldIds ++ getDummyCollection
}

def getCollectionsByTemplateDom: List[CollectionModel] = {
/** Get dummy collection in case of monolith subProject/repoItem for showing PA
* @return
*/
private def getDummyCollection: List[CollectionModel] = {
if (repoItemTagName.isDefined) {
val fileName = cpg.file
.where(_.tag.nameExact(Constants.monolithRepoItem).valueExact(repoItemTagName.get))
.name
.headOption
.getOrElse(Constants.default)
List(
CollectionModel(
Constants.default,
Constants.default,
false,
List(
CollectionOccurrenceDetailModel(
Constants.default,
List(
CollectionOccurrenceModel(
Constants.default,
Constants.default,
Constants.defaultLineNumber,
Constants.defaultLineNumber,
fileName,
Constants.default
)
)
)
)
)
)
} else List()
}
private def getCollectionsByTemplateDom: List[CollectionModel] = {
val collectionMapByCollectionId = ExporterUtility
.filterNodeBasedOnRepoItemTagName(
cpg.templateDom
Expand All @@ -68,7 +102,7 @@ class CollectionExporter(cpg: Cpg, ruleCache: RuleCache, repoItemTagName: Option
.toList
}

def getCollectionsByAndroidXmlFieldIds: List[CollectionModel] = {
private def getCollectionsByAndroidXmlFieldIds: List[CollectionModel] = {
val collectionMapByCollectionId = ExporterUtility
.filterNodeBasedOnRepoItemTagName(
cpg.fieldAccess.astChildren.isFieldIdentifier
Expand Down Expand Up @@ -150,7 +184,7 @@ class CollectionExporter(cpg: Cpg, ruleCache: RuleCache, repoItemTagName: Option
)
}

def getCollectionsByMethods: List[CollectionModel] = {
private def getCollectionsByMethods: List[CollectionModel] = {
val collectionMapByCollectionId = ExporterUtility
.filterNodeBasedOnRepoItemTagName(
cpg.method
Expand Down Expand Up @@ -245,7 +279,7 @@ class CollectionExporter(cpg: Cpg, ruleCache: RuleCache, repoItemTagName: Option
)
}

def processByParameterId(
private def processByParameterId(
parameterId: String,
methodParameterOccurrences: List[MethodParameterIn]
): CollectionOccurrenceDetailModel = {
Expand All @@ -264,7 +298,7 @@ class CollectionExporter(cpg: Cpg, ruleCache: RuleCache, repoItemTagName: Option
)
}

def getCollectionOccurrenceModel(
private def getCollectionOccurrenceModel(
methodNode: Traversal[Method],
pathElement: DataFlowSubCategoryPathExcerptModel
): Some[CollectionOccurrenceModel] = {
Expand All @@ -281,7 +315,7 @@ class CollectionExporter(cpg: Cpg, ruleCache: RuleCache, repoItemTagName: Option

}

def processByTemplatedDomId(
private def processByTemplatedDomId(
templatedDomId: String,
methodLocalOccurrences: List[TemplateDom]
): CollectionOccurrenceDetailModel = {
Expand Down

0 comments on commit be60743

Please sign in to comment.