-
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.
- Loading branch information
Showing
35 changed files
with
147 additions
and
224 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
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
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
2 changes: 1 addition & 1 deletion
2
src/main/java/io/codeka/gaia/modules/repository/TerraformModuleRepository.java
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
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
40 changes: 0 additions & 40 deletions
40
src/main/java/io/codeka/gaia/stacks/service/MandatoryStackVariablesValidator.java
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
src/main/java/io/codeka/gaia/stacks/service/MandatoryStackVariablesValidator.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,28 @@ | ||
package io.codeka.gaia.stacks.service | ||
|
||
import io.codeka.gaia.modules.repository.TerraformModuleRepository | ||
import io.codeka.gaia.stacks.bo.MandatoryStackVariablesValidation | ||
import io.codeka.gaia.stacks.bo.Stack | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
import javax.validation.ConstraintValidator | ||
import javax.validation.ConstraintValidatorContext | ||
|
||
@Service | ||
class MandatoryStackVariablesValidator(@Autowired val moduleRepository: TerraformModuleRepository) | ||
: ConstraintValidator<MandatoryStackVariablesValidation, Stack> { | ||
|
||
override fun isValid(stack: Stack, constraintValidatorContext: ConstraintValidatorContext?): Boolean { | ||
// we do not validate anything if the stacks has no module reference (it will send a BadRequest anyway) | ||
if (stack.moduleId.isNullOrBlank()) { | ||
return true | ||
} | ||
// getting the module, returning true if module cannot be found ! | ||
// this should (let's hope so) never happen ! another validator should handle this case | ||
val module = this.moduleRepository.findByIdOrNull(stack.moduleId) ?: return true | ||
|
||
return module.variables.filter { it.isMandatory } | ||
.all { ! stack.variableValues[it.name].isNullOrBlank() } | ||
} | ||
} |
49 changes: 0 additions & 49 deletions
49
src/main/java/io/codeka/gaia/stacks/service/RegexStackVariablesValidator.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
src/main/java/io/codeka/gaia/stacks/service/RegexStackVariablesValidator.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,40 @@ | ||
package io.codeka.gaia.stacks.service | ||
|
||
import io.codeka.gaia.modules.bo.TerraformVariable | ||
import io.codeka.gaia.modules.repository.TerraformModuleRepository | ||
import io.codeka.gaia.stacks.bo.RegexStackVariablesValidation | ||
import io.codeka.gaia.stacks.bo.Stack | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
import java.util.regex.Pattern | ||
import javax.validation.ConstraintValidator | ||
import javax.validation.ConstraintValidatorContext | ||
|
||
@Service | ||
class RegexStackVariablesValidator(@Autowired val moduleRepository: TerraformModuleRepository) | ||
: ConstraintValidator<RegexStackVariablesValidation, Stack> { | ||
|
||
override fun isValid(stack: Stack, constraintValidatorContext: ConstraintValidatorContext?): Boolean { | ||
// we do not validate anything if the stacks has no module reference (it will send a BadRequest anyway) | ||
if( stack.moduleId.isNullOrBlank()) { | ||
return true | ||
} | ||
// getting the module, returning true if module cannot be found ! | ||
// this should (let's hope so) never happen ! another validator should handle this case | ||
val module = this.moduleRepository.findByIdOrNull(stack.moduleId) ?: return true | ||
|
||
return module.variables | ||
// not checking non regex values | ||
.filter { ! it.validationRegex.isNullOrBlank() } | ||
// not checking blank values (doing it first because Pair want non-null values) | ||
.filter { ! stack.variableValues[it.name].isNullOrBlank() } | ||
// validate the pattern (using non null assert as variable value is not more null here) | ||
.all { it.validateWithPattern(stack.variableValues[it.name]!!) } | ||
} | ||
} | ||
|
||
private fun TerraformVariable.validateWithPattern(value: String): Boolean { | ||
val pattern = Pattern.compile(this.validationRegex) | ||
return pattern.matcher(value).matches() | ||
} |
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,20 @@ | ||
package io.codeka.gaia.teams | ||
|
||
import org.springframework.data.annotation.Id | ||
import org.springframework.data.mongodb.core.mapping.DBRef | ||
|
||
/** | ||
* A Gaia Team, which groups users | ||
*/ | ||
data class Team(val id: String?) | ||
|
||
/** | ||
* a Gaia user, which has granted access to modules | ||
*/ | ||
data class User( | ||
@Id val username: String, | ||
@DBRef val team: Team?) { | ||
|
||
val isAdmin: Boolean | ||
get() = "admin" == this.username | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/main/java/io/codeka/gaia/teams/controller/TeamsRestController.java
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
2 changes: 1 addition & 1 deletion
2
src/main/java/io/codeka/gaia/teams/controller/UsersRestController.java
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
2 changes: 1 addition & 1 deletion
2
src/main/java/io/codeka/gaia/teams/repository/TeamRepository.java
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
2 changes: 1 addition & 1 deletion
2
src/main/java/io/codeka/gaia/teams/repository/UserRepository.java
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.