Skip to content

Commit

Permalink
Merge pull request #1195 from Privado-Inc/dev
Browse files Browse the repository at this point in the history
Release PR
  • Loading branch information
khemrajrathore authored Jun 26, 2024
2 parents 68323e9 + 81b6fc1 commit 6e763f4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ abstract class BaseProcessor(
statsRecorder.initiateNewStage("Run oss data flow")
applyDataflowAndPostProcessingPasses(cpg)
statsRecorder.endLastStage()

statsRecorder.setSupressSubstagesFlag(false)
applyTaggingAndExport(cpg) match
case Left(err) =>
Expand Down Expand Up @@ -109,14 +108,12 @@ abstract class BaseProcessor(

def applyDataflowAndPostProcessingPasses(cpg: Cpg): Unit = {
logger.info("Applying data flow overlay")
statsRecorder.initiateNewStage("Run oss data flow")
val context = new LayerCreatorContext(cpg)
val options = new OssDataFlowOptions()
new OssDataFlow(options).run(context)
if (privadoInput.enableLambdaFlows)
new ExperimentalLambdaDataFlowSupportPass(cpg).createAndApply()
logger.info("=====================")
statsRecorder.endLastStage()
}

/** Wrapper method which takes care of applying tagging and export
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class GoProcessor(
statsRecorder.initiateNewStage("Applying default overlays")
applyDefaultOverlays(cpg)
statsRecorder.endLastStage()
statsRecorder.setSupressSubstagesFlag(false)
cpg
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import io.shiftleft.codepropertygraph.generated.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.{AstNode, Call, TypeDecl}
import io.shiftleft.semanticcpg.language.*
import overflowdb.BatchedUpdate.DiffGraphBuilder
import scala.util.Try

import scala.collection.mutable
import scala.collection.mutable.ListBuffer
Expand Down Expand Up @@ -106,16 +107,10 @@ class FeignAPI(cpg: Cpg, ruleCache: RuleCache) {
cpg.typeDecl
.where(_.annotation.name(FEIGN_CLIENT))
.foreach(typeDecl => {
val classAnnotations = typeDecl.annotation.name(FEIGN_CLIENT).l
val annotationCode = classAnnotations.code.headOption
.getOrElse("")
// Logic to exact the value present in `url = "value"`
val urlParameterPattern = ".*url\\s{0,3}=\\s{0,3}(\".*\").*(,)?".r
val apiLiteral = annotationCode match {
case urlParameterPattern(urlParameter) =>
urlParameter
case _ => ""
}
val apiLiteral = Try(
typeDecl.annotation.name(FEIGN_CLIENT).parameterAssign.where(_.parameter.code("url")).value.code.head
).toOption.getOrElse("")
if (apiLiteral.isEmpty)
typeDeclWithoutUrl.append(typeDecl)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class PythonProcessor(
statsRecorder.initiateNewStage("Applying default overlays")
applyDefaultOverlays(cpg)
statsRecorder.endLastStage()
statsRecorder.setSupressSubstagesFlag(false)
cpg
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package ai.privado.languageEngine.java.tagger.sink

import ai.privado.tagger.sink.api.APIValidator
import ai.privado.testfixtures.JavaFrontendTestSuite
import io.shiftleft.semanticcpg.language._

class FeignAPITest extends JavaFrontendTestSuite with APIValidator {

"Feign api tagger" should {
"be able to tag api call with correct url (Case 1)" in {

val cpg = code(
"""
|import dto.ResponseOnboardingDTO;
|import org.springframework.cloud.openfeign.FeignClient;
|import org.springframework.data.domain.Pageable;
|import org.springframework.format.annotation.DateTimeFormat;
|import org.springframework.http.MediaType;
|import org.springframework.web.bind.annotation.GetMapping;
|import org.springframework.web.bind.annotation.PathVariable;
|import org.springframework.web.bind.annotation.RequestParam;
|import org.springframework.web.bind.annotation.ResponseBody;
|
|import java.time.LocalDateTime;
|
|@FeignClient(
| name = "${rest-client.onboarding.serviceCode}",
| url = "${rest-client.onboarding.uri}")
|public interface OnboardingRestClient {
|
| @GetMapping(
| value = "/idpay/onboarding/{initiativeId}",
| produces = MediaType.APPLICATION_JSON_VALUE)
| @ResponseBody
| ResponseOnboardingDTO getOnboarding(
| @PathVariable("initiativeId") String initiativeId,
| Pageable pageable,
| @RequestParam(required = false) String userId,
| @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime startDate,
| @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME) LocalDateTime endDate,
| @RequestParam(required = false) String status);
|
|}
|""".stripMargin,
"OnboardingRestClient.java"
).moreCode("""
|import dto.ResponseOnboardingDTO;
|import org.springframework.data.domain.Pageable;
|import org.springframework.stereotype.Service;
|
|import java.time.LocalDateTime;
|
|@Service
|public class OnboardingRestConnectorImpl implements OnboardingRestConnector {
|
| private final OnboardingRestClient onboardingRestClient;
|
| public OnboardingRestConnectorImpl(
| OnboardingRestClient onboardingRestClient) {
| this.onboardingRestClient = onboardingRestClient;
| }
|
| @Override
| public ResponseOnboardingDTO getOnboarding(String initiativeId, Pageable pageable, String userId,
| LocalDateTime startDate, LocalDateTime endDate, String status) {
| return onboardingRestClient.getOnboarding(initiativeId,pageable,userId,startDate,endDate,status);
| }
|}
|""".stripMargin)

val List(apiCall) = cpg.call("getOnboarding").l
assertAPISinkCall(apiCall)
assertAPIEndpointURL(apiCall, "rest-client_onboarding_uri")
}
}

}

0 comments on commit 6e763f4

Please sign in to comment.