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

multiple account handling for source-code-analyser #1703

Open
wants to merge 23 commits into
base: master
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
ce664b1
removing 1000000 account check
shivam-rawat-akto Sep 30, 2024
cb54622
removing comments
shivam-rawat-akto Sep 30, 2024
7b78cc5
docker volume
shivam-rawat-akto Sep 30, 2024
d85712e
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Oct 15, 2024
7d3e1ac
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Oct 25, 2024
d99433b
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Oct 28, 2024
6d8680b
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Nov 4, 2024
1f4ceb1
fixing getter and setter for isLastBatch in CodeAnalysisAction
shivam-rawat-akto Nov 5, 2024
206e560
dbactor changes for codeanalysis and handling for multiple accounts g…
shivam-rawat-akto Nov 8, 2024
fc6eefa
mongo based code-analysis
shivam-rawat-akto Nov 13, 2024
8a32a5a
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Dec 9, 2024
1785fcd
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Dec 11, 2024
0ff0911
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Dec 11, 2024
da95368
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Dec 23, 2024
3f9795b
add polling
notshivansh Dec 23, 2024
121c619
Merge pull request #1849 from akto-api-security/feature/sca-3
shivam-rawat-akto Dec 23, 2024
1baac95
Merge remote-tracking branch 'origin/master' into feature/source-code…
shivam-rawat-akto Dec 23, 2024
cfb5fbc
add log
notshivansh Dec 24, 2024
04817be
Merge pull request #1852 from akto-api-security/feature/sca-3
notshivansh Dec 24, 2024
f106ca4
add empty check
notshivansh Dec 24, 2024
bb4f5de
Merge pull request #1854 from akto-api-security/feature/sca-3
notshivansh Dec 24, 2024
0b41745
add logs
notshivansh Dec 24, 2024
74ab345
Merge pull request #1855 from akto-api-security/feature/sca-3
notshivansh Dec 24, 2024
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
35 changes: 2 additions & 33 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,8 @@ jobs:
- name: Convert github branch name to be compatible with docker tag name convention and generate tag name
id: docker_tag
run: echo "IMAGE_TAG=a-$(echo ${{ github.ref_name }} | sed 's/[^a-zA-Z0-9]/-/g')" >> $GITHUB_OUTPUT
- name: Download Akto templates zip and PII files
working-directory: ./apps/dashboard/src/main/resources
run: |
wget -O tests-library-master.zip https://github.com/akto-api-security/tests-library/archive/refs/heads/master.zip
wget -O general.json https://raw.githubusercontent.com/akto-api-security/pii-types/master/general.json
wget -O fintech.json https://raw.githubusercontent.com/akto-api-security/akto/master/pii-types/fintech.json
wget -O filetypes.json https://raw.githubusercontent.com/akto-api-security/akto/master/pii-types/filetypes.json
- name: Prepare Dashboard polaris UI
working-directory: ./apps/dashboard/web/polaris_web
run: npm install && export RELEASE_VERSION=${{steps.docker_tag.outputs.IMAGE_TAG}} && npm run build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY}}
aws-region: ap-south-1

- name: Deploy polaris site to S3 bucket
run: aws s3 sync ./apps/dashboard/web/polaris_web/web/dist s3://dashboard-on-cdn/polaris_web/${{steps.docker_tag.outputs.IMAGE_TAG}}/dist --delete

- run: mvn package -Dakto-image-tag=${{ github.event.inputs.Tag }} -Dakto-build-time=$(eval "date +%s") -Dakto-release-version=${{steps.docker_tag.outputs.IMAGE_TAG}}
- run: mvn package -Dakto-image-tag=${{ github.event.inputs.Tag }} -Dakto-build-time=$(eval "date +%s") -Dakto-release-version=${{steps.docker_tag.outputs.IMAGE_TAG}} -DskipTests=true
- name: DockerHub login
env:
DOCKER_USERNAME: ${{secrets.DOCKER_USERNAME}}
Expand All @@ -69,19 +50,7 @@ jobs:
echo $IMAGE_TAG >> $GITHUB_STEP_SUMMARY
docker buildx create --use
# Build a docker container and push it to DockerHub
cd apps/dashboard
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/$ECR_REPOSITORY-dashboard:$IMAGE_TAG $IMAGE_TAG_DASHBOARD . --push
cd ../testing
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-api-testing:$IMAGE_TAG $IMAGE_TAG_TESTING . --push
cd ../testing-cli
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-api-testing-cli:$IMAGE_TAG $IMAGE_TAG_TESTING_CLI . --push
cd ../billing
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-billing:$IMAGE_TAG . --push
cd ../internal
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-internal:$IMAGE_TAG . --push
cd ../api-threat-detection
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/akto-api-protection:$IMAGE_TAG . --push
cd ../source-code-analyser
cd apps/source-code-analyser
docker buildx build --platform linux/arm64/v8,linux/amd64 -t $ECR_REGISTRY/source-code-analyser:$IMAGE_TAG . --push

- name: Set up JDK 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,12 @@ public void setProjectName(String projectName) {
this.projectName = projectName;
}

public boolean isLastBatch() {
public boolean getIsLastBatch() {
return isLastBatch;
}

public void setLastBatch(boolean lastBatch) {
isLastBatch = lastBatch;
public void setIsLastBatch(boolean isLastBatch) {
this.isLastBatch = isLastBatch;
}

public CodeAnalysisRepo getCodeAnalysisRepo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public BasicDBObject getCodeAnalysisBody(String path) {
requestBody.put("repoName",this.getRepoToBeAnalysed().getRepoName());
requestBody.put("bitbucketHost",BITBUCKET_URL);
requestBody.put("is_bitbucket",true);
requestBody.put("is_aktogpt",false);
return requestBody;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public String getRepoUrl() {

@Override
public BasicDBObject getCodeAnalysisBody(String path) {
if (path == null || StringUtils.isEmpty(GITHUB_ACCESS_TOKEN)) {
if (path == null) {
return null;
}

Expand All @@ -43,6 +43,7 @@ public BasicDBObject getCodeAnalysisBody(String path) {
requestBody.put("orgName",this.getRepoToBeAnalysed().getProjectName());
requestBody.put("repoName",this.getRepoToBeAnalysed().getRepoName());
requestBody.put("is_github",true);
requestBody.put("is_aktogpt",false);
return requestBody;
}

Expand Down
107 changes: 77 additions & 30 deletions apps/source-code-analyser/src/main/java/com/akto/Main.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,55 @@
package com.akto;

import com.akto.dao.AccountsDao;
import com.akto.data_actor.DataActor;
import com.akto.data_actor.DataActorFactory;
import com.akto.dto.CodeAnalysisRepo;
import com.akto.log.LoggerMaker;
import com.akto.util.AccountTask;
import com.mongodb.ConnectionString;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;


public class Main {
private static final LoggerMaker loggerMaker = new LoggerMaker(Main.class, LoggerMaker.LogDb.RUNTIME);
private static final DataActor dataActor = DataActorFactory.fetchInstance();
private static final int SLEEP_TIME = 10 * 1000;
private static final Logger logger = LoggerFactory.getLogger(Main.class);

private static boolean connectToMongo() {

String mongoURI = System.getenv("AKTO_MONGO_CONN");
if (StringUtils.isEmpty(mongoURI)) {
return false;
}
boolean connectedToMongo = false;
boolean calledOnce = false;
do {
try {

if (!calledOnce) {
DaoInit.init(new ConnectionString(mongoURI));
calledOnce = true;
}
AccountsDao.instance.getStats();
connectedToMongo = true;

logger.info("connected to mongo");
} catch (Exception e) {
logger.error("error connecting to mongo", e);
} finally {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
} while (!connectedToMongo);
return connectedToMongo;
}


private static List<CodeAnalysisRepo> fetchReposToSync() {
List<CodeAnalysisRepo> repos = dataActor.findReposToRun();
Expand All @@ -21,39 +59,48 @@ private static List<CodeAnalysisRepo> fetchReposToSync() {
return null;
}

public static void main(String[] args) throws InterruptedException {
while (true) {
if (!BitbucketRepo.doesEnvVariablesExists() && !GithubRepo.doesEnvVariablesExists()) {
loggerMaker.infoAndAddToDb("No tokens found");
Thread.sleep(SLEEP_TIME);
continue;
}
List<CodeAnalysisRepo> repos = fetchReposToSync();
if (repos == null) {
loggerMaker.infoAndAddToDb("No repos to run, skipping");
Thread.sleep(SLEEP_TIME);
continue;
private static void runForRepo(List<CodeAnalysisRepo> repos) {
if (repos == null) {
loggerMaker.infoAndAddToDb("No repos to run, skipping");
return;
}
if (BitbucketRepo.doesEnvVariablesExists()) {
BitbucketRepo.fetchAllProjectKeys();
}
for (CodeAnalysisRepo repo : repos) {
SourceCodeAnalyserRepo sourceCodeAnalyserRepo;
if (repo.getSourceCodeType() == CodeAnalysisRepo.SourceCodeType.BITBUCKET) {
sourceCodeAnalyserRepo = new BitbucketRepo(repo);
} else {
sourceCodeAnalyserRepo = new GithubRepo(repo);
}
if (BitbucketRepo.doesEnvVariablesExists()) {
BitbucketRepo.fetchAllProjectKeys();
}
for (CodeAnalysisRepo repo : repos) {
SourceCodeAnalyserRepo sourceCodeAnalyserRepo;
if (repo.getSourceCodeType() == CodeAnalysisRepo.SourceCodeType.BITBUCKET) {
sourceCodeAnalyserRepo = new BitbucketRepo(repo);
} else {
sourceCodeAnalyserRepo = new GithubRepo(repo);
}
try {
sourceCodeAnalyserRepo.fetchEndpointsUsingAnalyser();
} catch (Exception e) {
loggerMaker.errorAndAddToDb("Error while fetching endpoints:" + e.getMessage());
}
try {
sourceCodeAnalyserRepo.fetchEndpointsUsingAnalyser();
} catch (Exception e) {
loggerMaker.errorAndAddToDb("Error while fetching endpoints:" + e.getMessage());
}
}
}

public static void main(String[] args) throws InterruptedException {
boolean isConnectedToMongo = connectToMongo();//When mongo connection, fetch for all accounts

while (true) {
// if (!BitbucketRepo.doesEnvVariablesExists() && !GithubRepo.doesEnvVariablesExists()) {
// loggerMaker.infoAndAddToDb("No tokens found");
// Thread.sleep(SLEEP_TIME);
// continue;
// }
if (isConnectedToMongo) {
AccountTask.instance.executeTask(t -> {
List<CodeAnalysisRepo> repos = fetchReposToSync();
runForRepo(repos);
}, "initialize-runtime-task");
} else {
List<CodeAnalysisRepo> repos = fetchReposToSync();
runForRepo(repos);
}
Thread.sleep(SLEEP_TIME);
}

}

}
Loading
Loading