diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/WebSecurityConfiguration.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/WebSecurityConfiguration.kt index 202fbbb8faf95fcda0f349b480403a32a67eb61f..921cb19f73fc2d0689888c2d40808b872d5e9522 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/WebSecurityConfiguration.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/WebSecurityConfiguration.kt @@ -17,6 +17,7 @@ class SecurityConfiguration { return http { authorizeExchange { authorize("/gitlab/repoChanged", permitAll) + authorize("/gitlab/repoChangedPath", permitAll) } csrf { disable() diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabController.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabController.kt index 829194f0ba84a55f6c5643d6b8c436d7b6e01f86..324a4dfda081c3495399573683073290463356ae 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabController.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabController.kt @@ -11,6 +11,7 @@ enum class Platform { GITHUB, } data class RepositoryChangedDto(val repoId: Long, val platform: Platform) +data class RepositoryChangedPathDto(val path: String, val platform: Platform) @RestController @RequestMapping("/gitlab") class GitlabController(private val gitlabService: GitlabService) { @@ -30,4 +31,17 @@ class GitlabController(private val gitlabService: GitlabService) { } } } + + // TODO: improve duplicate code from repoChanged + @PostMapping("/repoChangedPath") + suspend fun repoChangedPath(@RequestBody repositoryChangedDto: RepositoryChangedPathDto) { + logger.info("Repo changed POST request for path ${repositoryChangedDto.path} on platform ${repositoryChangedDto.platform} received.") + when (repositoryChangedDto.platform) { + Platform.OPEN_CODE -> gitlabService.queryOpenCodeProject(repositoryChangedDto.path) + else -> { + logger.info("Platform currently not supported.") + // TODO: send fitting http response + } + } + } } \ No newline at end of file diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabService.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabService.kt index ec09be77bfc53ce64aeecdf929fd4faaf14e1185..b2e44df2820fa0037054ff0dd1c63196be820972 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabService.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/gitlab/GitlabService.kt @@ -2,7 +2,8 @@ package de.fraunhofer.iem.dataprovider.gitlab import de.fraunhofer.iem.dataprovider.logger.getLogger import de.fraunhofer.iem.dataprovider.taskManager.TaskManager -import de.fraunhofer.iem.dataprovider.taskManager.tasks.GetGitlabProjectTask +import de.fraunhofer.iem.dataprovider.taskManager.tasks.GetGitlabProjectIdTask +import de.fraunhofer.iem.dataprovider.taskManager.tasks.GetGitlabProjectPathTask import org.springframework.stereotype.Service @@ -13,7 +14,11 @@ class GitlabService(private val openCodeGitlabConfiguration: OpenCodeGitlabConfi private val logger = getLogger(javaClass) suspend fun queryOpenCodeProject(repoId: Long) { - taskManager.addTask(GetGitlabProjectTask(repoId = repoId, gitlabConfiguration = openCodeGitlabConfiguration, responseChannel = taskManager::addTask)) + taskManager.addTask(GetGitlabProjectIdTask(repoId = repoId, gitlabConfiguration = openCodeGitlabConfiguration, responseChannel = taskManager::addTask)) + } + + suspend fun queryOpenCodeProject(repoId: String) { + taskManager.addTask(GetGitlabProjectPathTask(repoId = repoId, gitlabConfiguration = openCodeGitlabConfiguration, responseChannel = taskManager::addTask)) } } \ No newline at end of file diff --git a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/GitlabTask.kt b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/GitlabTask.kt index 96ac3b9998174d959a7b6bb9c2f24a452d886e5b..67e1ff8b5fde47cd69588d0a7349af65419a39d1 100644 --- a/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/GitlabTask.kt +++ b/src/main/kotlin/de/fraunhofer/iem/dataprovider/taskManager/tasks/GitlabTask.kt @@ -3,20 +3,32 @@ package de.fraunhofer.iem.dataprovider.taskManager.tasks import de.fraunhofer.iem.dataprovider.gitlab.GitlabConfiguration import org.gitlab4j.api.GitLabApi -class GetGitlabProjectTask( +sealed class GetGitlabProjectTask( override val type: TaskType = TaskType.REPO_CHANGED, - private val repoId: Long, + protected open val repoId: Any, private val gitlabConfiguration: GitlabConfiguration, - private val responseChannel: suspend (task: ITask) -> Unit): Task() { + private val responseChannel: suspend (task: ITask) -> Unit +): Task() { private val gitlabApi: GitLabApi = GitLabApi(gitlabConfiguration.host, gitlabConfiguration.accessToken) override suspend fun execute() { logger.info("Gitlab config ${gitlabConfiguration.host} ${gitlabConfiguration.accessToken}") val project = gitlabApi.projectApi.getProject(repoId) logger.info(project.toString()) - val projectUri = project.sshUrlToRepo + val projectUri = project.httpUrlToRepo val gitProject = GitProject(project.name, projectUri) - logger.info("Retrieved project ${project.path} and URI $projectUri") + logger.info("Retrieved project ${project.path} and url $projectUri") responseChannel(GitTask(this.type, gitProject, responseChannel)) } -} \ No newline at end of file +} + +class GetGitlabProjectPathTask( + override val repoId: String, + private val gitlabConfiguration: GitlabConfiguration, + private val responseChannel: suspend (task: ITask) -> Unit +): GetGitlabProjectTask(repoId = repoId, gitlabConfiguration = gitlabConfiguration, responseChannel = responseChannel ) +class GetGitlabProjectIdTask( + override val repoId: Long, + private val gitlabConfiguration: GitlabConfiguration, + private val responseChannel: suspend (task: ITask) -> Unit +): GetGitlabProjectTask(repoId = repoId, gitlabConfiguration = gitlabConfiguration, responseChannel = responseChannel )