-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ingsis-group-6/dev
Merging developed service
- Loading branch information
Showing
50 changed files
with
1,601 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
build | ||
.idea | ||
.gradle | ||
.gradle | ||
.env | ||
.envrc | ||
gradle.properties |
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
FROM gradle:7.6.1-jdk17 | ||
COPY . /home/gradle/src | ||
WORKDIR /home/gradle/src | ||
|
||
ARG USERNAME | ||
ENV USERNAME ${USERNAME} | ||
|
||
ARG TOKEN | ||
ENV TOKEN ${TOKEN} | ||
|
||
|
||
RUN gradle build | ||
EXPOSE 8080 | ||
EXPOSE 8081 | ||
ENTRYPOINT ["java","-jar","/home/gradle/src/build/libs/snippet-manager-0.0.1-SNAPSHOT.jar"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
version: '3' | ||
|
||
services: | ||
snippet-manager-api: | ||
container_name: "snippet-manager-api" | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
DB_USER: sa | ||
DB_PASSWORD: password | ||
DB_NAME: compose-db | ||
DB_HOST: snippet_manager_db | ||
DB_PORT: 5432 | ||
|
||
snippet_manager_db: | ||
container_name: snippet_manager_db | ||
image: postgres:12 | ||
db: | ||
image: postgres:alpine | ||
ports: | ||
- "5432:5432" | ||
- "5433:5433" | ||
environment: | ||
POSTGRES_USER: sa | ||
POSTGRES_PASSWORD: password | ||
POSTGRES_DB: compose-db | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: db | ||
command: -p 5433 | ||
|
||
# datadog: | ||
# image: datadog/agent | ||
# container_name: "datadog-dev-env-manager" | ||
# environment: | ||
# - DD_API_KEY=${DD_API_KEY} | ||
# - DD_SITE=us5.datadoghq.com | ||
# - DD_LOGS_ENABLED=true | ||
# - DD_APM_ENABLED=true | ||
# volumes: | ||
# - /var/run/docker.sock:/var/run/docker.sock | ||
# - /proc/:/host/proc/:ro | ||
# - /sys/fs/cgroup:/host/sys/fs/cgroup:ro | ||
|
||
# redis: | ||
# image: redis | ||
# ports: | ||
# - "6379:6379" | ||
|
||
# app: | ||
# build: | ||
# context: . | ||
# dockerfile: Dockerfile | ||
# ports: | ||
# - "8081:8081" | ||
# environment: | ||
# DD_API_KEY: ${DD_API_KEY} | ||
# DB_HOST: db | ||
# DB_PORT: 5433 | ||
# DB_NAME: db | ||
# DB_USER: postgres | ||
# DB_PASSWORD: postgres | ||
# SHARE_URI: "http://localhost:8080/share" | ||
# REDIS_STREAM_KEY: ingsis | ||
# REDIS_HOST: localhost | ||
# REDIS_PORT: 6379 | ||
# REDIS_STREAM_GROUP_LINT: lint-manager | ||
# labels: | ||
# com.datadoghq.ad.logs: '[{"source": "java", "service": "manager-api-dev", "log_processing_rules": [{"type": "multi_line", "name": "log_start_with_date", "pattern" : "\\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])"}]}]' | ||
|
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,2 @@ | ||
gpr.user=ricardolopezb | ||
gpr.key=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 |
32 changes: 5 additions & 27 deletions
32
src/main/kotlin/ingsis/snippetmanager/SnippetManagerApplication.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 |
---|---|---|
@@ -1,38 +1,16 @@ | ||
package ingsis.snippetmanager | ||
|
||
import ingsis.snippetmanager.snippet.Snippet | ||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.runApplication | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.time.LocalDate | ||
import org.springframework.metrics.export.datadog.EnableDatadogMetrics | ||
|
||
@SpringBootApplication | ||
@RestController | ||
class SnippetManagerApplication{ | ||
|
||
@GetMapping("/") | ||
fun url(): String { | ||
return "Go to /hello or /snippets"; | ||
} | ||
@GetMapping("/hello") | ||
fun hello(): List<String> { | ||
return listOf("Hello", " World, ", "this is Numa", "!"); | ||
} | ||
@SpringBootApplication | ||
@EnableDatadogMetrics | ||
class SnippetManagerApplication | ||
|
||
@GetMapping("/snippets") | ||
fun snippets():List<Snippet>{ | ||
return listOf( | ||
Snippet(1, "Contenido 1", LocalDate.now()), | ||
Snippet(2, "Contenido 2", LocalDate.now()), | ||
Snippet(3, "Contenido 3", LocalDate.now()), | ||
Snippet(4, "Contenido 4", LocalDate.now()), | ||
); | ||
} | ||
} | ||
fun main(args: Array<String>) { | ||
runApplication<SnippetManagerApplication>(*args) | ||
runApplication<SnippetManagerApplication>(*args) | ||
} | ||
|
||
|
||
|
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/ingsis/snippetmanager/auth/AudienceValidator.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,16 @@ | ||
package ingsis.snippetmanager.auth | ||
|
||
import org.springframework.security.oauth2.core.OAuth2Error | ||
import org.springframework.security.oauth2.core.OAuth2TokenValidator | ||
import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult | ||
import org.springframework.security.oauth2.jwt.Jwt | ||
|
||
|
||
internal class AudienceValidator(private val audience: String) : OAuth2TokenValidator<Jwt> { | ||
override fun validate(jwt: Jwt): OAuth2TokenValidatorResult { | ||
val error = OAuth2Error("invalid_token", "The required audience is missing", null) | ||
return if (jwt.audience.contains(audience)) { | ||
OAuth2TokenValidatorResult.success() | ||
} else OAuth2TokenValidatorResult.failure(error) | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/kotlin/ingsis/snippetmanager/auth/SecurityConfig.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,58 @@ | ||
package ingsis.snippetmanager.auth | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.oauth2.core.DelegatingOAuth2TokenValidator; | ||
import org.springframework.security.oauth2.core.OAuth2TokenValidator; | ||
import org.springframework.security.oauth2.jwt.*; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
|
||
|
||
@EnableWebSecurity | ||
class SecurityConfig { | ||
@Value("\${auth0.audience}") | ||
private val audience: String? = null | ||
|
||
@Value("\${spring.security.oauth2.resourceserver.jwt.issuer-uri}") | ||
private val issuer: String? = null | ||
@Bean | ||
@Throws(Exception::class) | ||
fun filterChain(http: HttpSecurity): SecurityFilterChain { | ||
/* | ||
This is where we configure the security required for our endpoints and setup our app to serve as | ||
an OAuth2 Resource Server, using JWT validation. | ||
*/ | ||
|
||
http.authorizeRequests() | ||
.mvcMatchers("/snippet").authenticated() | ||
.mvcMatchers("/snippet/**").authenticated() | ||
.mvcMatchers("/health").authenticated() | ||
.mvcMatchers("/health/**").authenticated() | ||
.mvcMatchers("/test").authenticated() | ||
.mvcMatchers("/test/**").authenticated() | ||
.mvcMatchers("/rule").authenticated() | ||
.mvcMatchers("/rule/**").authenticated() | ||
.mvcMatchers("/error").authenticated() | ||
.mvcMatchers("/error/**").authenticated() | ||
.and().cors() | ||
.and().csrf().disable() | ||
.oauth2ResourceServer().jwt(); | ||
return http.build(); | ||
} | ||
|
||
@Bean | ||
fun jwtDecoder(): JwtDecoder { | ||
/* | ||
By default, Spring Security does not validate the "aud" claim of the token, to ensure that this token is | ||
indeed intended for our app. Adding our own validator is easy to do: | ||
*/ | ||
val jwtDecoder = JwtDecoders.fromOidcIssuerLocation<JwtDecoder>(issuer) as NimbusJwtDecoder | ||
val audienceValidator: OAuth2TokenValidator<Jwt> = AudienceValidator(audience!!) | ||
val withIssuer: OAuth2TokenValidator<Jwt> = JwtValidators.createDefaultWithIssuer(issuer) | ||
val withAudience: OAuth2TokenValidator<Jwt> = DelegatingOAuth2TokenValidator(withIssuer, audienceValidator) | ||
jwtDecoder.setJwtValidator(withAudience) | ||
return jwtDecoder | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...in/ingsis/snippetmanager/domains/rule/adapter/LintResultStatusToComplianceStateAdapter.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,17 @@ | ||
package ingsis.snippetmanager.domains.rule.adapter | ||
|
||
import ingsis.snippetmanager.domains.rule.model.ComplianceState | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.stereotype.Component | ||
import snippet.events.lint.LintResultStatus | ||
|
||
@Component | ||
class LintResultStatusToComplianceStateAdapter { | ||
fun toComplianceState(lintResultStatus: LintResultStatus): ComplianceState { | ||
return when (lintResultStatus) { | ||
LintResultStatus.COMPLIANT -> ComplianceState.COMPLIANT | ||
LintResultStatus.NON_COMPLIANT -> ComplianceState.NON_COMPLIANT | ||
LintResultStatus.PENDING -> ComplianceState.PENDING | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/main/kotlin/ingsis/snippetmanager/domains/rule/controller/FormatterRulesController.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,34 @@ | ||
package ingsis.snippetmanager.domains.rule.controller | ||
|
||
import ingsis.snippetmanager.domains.rule.dto.FormatterRulesDTO | ||
import ingsis.snippetmanager.domains.rule.service.FormatterRulesService | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.CrossOrigin | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PutMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RestController | ||
import java.security.Principal | ||
|
||
@RestController | ||
@CrossOrigin("*") | ||
class FormatterRulesController{ | ||
|
||
@Autowired | ||
private var ruleService: FormatterRulesService | ||
|
||
constructor(ruleService: FormatterRulesService){ | ||
this.ruleService = ruleService | ||
} | ||
|
||
@GetMapping("/rule/formatter") | ||
fun getFormatterRulesByUserId(principal: Principal): ResponseEntity<FormatterRulesDTO>{ | ||
return ResponseEntity.ok(ruleService.getFormatterRulesByUserId(principal.name)) | ||
} | ||
|
||
@PutMapping("/rule/formatter") | ||
fun updateFormatterRules(@RequestBody formatterRules: FormatterRulesDTO, principal: Principal): ResponseEntity<FormatterRulesDTO>{ | ||
return ResponseEntity.ok(ruleService.updateFormatterRules(formatterRules, principal.name)) | ||
} | ||
} |
Oops, something went wrong.