Skip to content
Snippets Groups Projects
Verified Commit 8ed4966c authored by Jan-Niclas Strüwer's avatar Jan-Niclas Strüwer
Browse files

Added functionality to handle private gits

parent 9573e29e
No related branches found
No related tags found
No related merge requests found
Pipeline #23186 canceled
...@@ -55,6 +55,11 @@ spec: ...@@ -55,6 +55,11 @@ spec:
secretKeyRef: secretKeyRef:
name: backendapisecrets name: backendapisecrets
key: oc_api_key key: oc_api_key
- name: OC_USER
valueFrom:
secretKeyRef:
name: backendapisecrets
key: oc_user
- name: API_KEY - name: API_KEY
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
......
...@@ -12,12 +12,19 @@ data class OpenCodeGitlabApiProperties( ...@@ -12,12 +12,19 @@ data class OpenCodeGitlabApiProperties(
@field:NotBlank @field:NotBlank
val host: String, val host: String,
@field:NotBlank @field:NotBlank
val accessToken: String val accessToken: String,
val analyzePrivateRepos: Boolean = false,
val userName: String?
) { ) {
@PostConstruct @PostConstruct
fun postConstruct() { fun postConstruct() {
// There is no try catch block around the operations on purpose! // There is no try catch block around the operations on purpose!
// We want to throw here if this operations fail. // We want to throw here if this operations fail.
URL(host).toURI() URL(host).toURI()
if (analyzePrivateRepos && userName.isNullOrEmpty()) {
throw Exception("To analyze private repositories a username must be set")
}
} }
} }
...@@ -15,6 +15,7 @@ import kotlinx.coroutines.future.await ...@@ -15,6 +15,7 @@ import kotlinx.coroutines.future.await
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
import java.io.File import java.io.File
import java.nio.file.Files.isExecutable import java.nio.file.Files.isExecutable
...@@ -128,10 +129,17 @@ class OccmdService( ...@@ -128,10 +129,17 @@ class OccmdService(
} }
private suspend fun cloneGit(repoUrl: String, outDir: File) { private suspend fun cloneGit(repoUrl: String, outDir: File) {
val git: Git = Git.cloneRepository() val gitRequest = Git.cloneRepository()
.setCloneSubmodules(true)
.setURI(repoUrl) .setURI(repoUrl)
.setDirectory(outDir) .setDirectory(outDir)
.call() if (gitlabApiProperties.analyzePrivateRepos) {
gitRequest.setCredentialsProvider(
UsernamePasswordCredentialsProvider(gitlabApiProperties.userName, gitlabApiProperties.accessToken)
)
}
val git = gitRequest.call()
git.close() git.close()
} }
} }
spring.config.import=optional:classpath:.env[.properties] spring.config.import=optional:classpath:.env[.properties]
# Config for the OpencoDE platform # Config for the OpencoDE platform
# Token can be an empty string to access public repositories only # Token can be an empty string to access public repositories only
opencode.host=https://gitlab.opencode.de/ opencode.host=https://gitlab.dev.o4oe.de/
opencode.access-token=${OC_GL_APIKEY:} opencode.access-token=${OC_GL_APIKEY:}
opencode.analyze-private-repos=true
opencode.user-name=${OC_USER:}
# Tool APIs # Tool APIs
opencode.api.base-path=https://sl.dev.o4oe.de/api/v1/project/ opencode.api.base-path=https://sl.dev.o4oe.de/api/v1/project/
opencode.api.ort=/cve-result opencode.api.ort=/cve-result
...@@ -41,5 +43,5 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.CockroachDialect ...@@ -41,5 +43,5 @@ spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.CockroachDialect
spring.datasource.url=${DB_URL:} spring.datasource.url=${DB_URL:}
spring.datasource.username=${DB_USER:} spring.datasource.username=${DB_USER:}
spring.datasource.password=${DB_PW:} spring.datasource.password=${DB_PW:}
projects.project-ids=1108 projects.project-ids=159
#, 888, 438, 1189, 820, 788, 400, 1052 #, 888, 438, 1189, 820, 788, 400, 1052
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.