-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ : create a service for module creation
resolves #206
- Loading branch information
Showing
10 changed files
with
245 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
src/main/java/io/codeka/gaia/registries/config/RegistryConfig.java
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
src/main/java/io/codeka/gaia/registries/config/RegistryConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.codeka.gaia.registries.config | ||
|
||
import io.codeka.gaia.registries.RegistryApi | ||
import io.codeka.gaia.registries.RegistryOAuth2Provider | ||
import io.codeka.gaia.registries.RegistryType | ||
import io.codeka.gaia.registries.SourceRepository | ||
import io.codeka.gaia.registries.github.GitHubOAuth2Provider | ||
import io.codeka.gaia.registries.github.GithubRegistryApi | ||
import io.codeka.gaia.registries.gitlab.GitLabOAuth2Provider | ||
import io.codeka.gaia.registries.gitlab.GitlabRegistryApi | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
/** | ||
* Config for registry management | ||
*/ | ||
@Configuration | ||
open class RegistryConfig { | ||
|
||
@Bean | ||
open fun registryOAuth2Providers(): List<RegistryOAuth2Provider> { | ||
return listOf(GitHubOAuth2Provider(), GitLabOAuth2Provider()) | ||
} | ||
|
||
@Bean | ||
open fun registryApis( | ||
githubRegistryApi: GithubRegistryApi, | ||
gitlabRegistryApi: GitlabRegistryApi): Map<RegistryType, RegistryApi<out SourceRepository>> { | ||
return mapOf(Pair(RegistryType.GITHUB, githubRegistryApi), | ||
Pair(RegistryType.GITLAB, gitlabRegistryApi)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/io/codeka/gaia/registries/service/RegistryService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.codeka.gaia.registries.service | ||
|
||
import io.codeka.gaia.hcl.HclParser | ||
import io.codeka.gaia.modules.bo.ModuleMetadata | ||
import io.codeka.gaia.modules.bo.TerraformModule | ||
import io.codeka.gaia.modules.repository.TerraformCLIRepository | ||
import io.codeka.gaia.modules.repository.TerraformModuleRepository | ||
import io.codeka.gaia.registries.RegistryApi | ||
import io.codeka.gaia.registries.RegistryDetails | ||
import io.codeka.gaia.registries.RegistryType | ||
import io.codeka.gaia.registries.SourceRepository | ||
import io.codeka.gaia.teams.User | ||
import org.springframework.stereotype.Service | ||
import java.util.* | ||
|
||
interface RegistryService { | ||
fun importRepository(projectId: String, registryType: RegistryType, user: User): TerraformModule | ||
} | ||
|
||
@Service | ||
class RegistryServiceImpl( | ||
private val cliRepository: TerraformCLIRepository, | ||
private val hclParser: HclParser, | ||
private val moduleRepository: TerraformModuleRepository, | ||
private val registryApis: Map<RegistryType, RegistryApi<out SourceRepository>> | ||
) : RegistryService { | ||
|
||
override fun importRepository(projectId: String, registryType: RegistryType, user: User) : TerraformModule { | ||
val module = TerraformModule() | ||
module.id = UUID.randomUUID().toString() | ||
|
||
val codeRepository = registryApis[registryType]?.getRepository(user, projectId)!! | ||
|
||
module.gitRepositoryUrl = codeRepository.htmlUrl | ||
module.gitBranch = "master" | ||
module.name = codeRepository.fullName | ||
module.cliVersion = cliRepository.listCLIVersion().first() | ||
|
||
module.registryDetails = RegistryDetails(registryType, codeRepository.id) | ||
module.moduleMetadata = ModuleMetadata(createdBy = user) | ||
|
||
// get variables | ||
val variablesFile = registryApis[registryType]?.getFileContent(user, projectId, "variables.tf")!! | ||
module.variables = hclParser.parseVariables(variablesFile) | ||
|
||
// saving module ! | ||
return moduleRepository.save(module) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.