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
provider "github" { | |
owner = "terraform-github-article" | |
} | |
terraform { | |
required_providers { | |
github = { | |
version = "~> 4.6" | |
} | |
} |
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
plugins { | |
kotlin("jvm") version "1.3.72" | |
id("com.github.johnrengelman.shadow") version "4.0.4" | |
id("org.unbroken-dome.test-sets") version "3.0.1" | |
application | |
} | |
group = "com.brunapereira" | |
version = "1.0-SNAPSHOT" |
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
@RestControllerAdvice | |
@Order(0) | |
class VendasExceptionHandler { | |
@ResponseStatus(BAD_REQUEST) | |
@ExceptionHandler(ProductNotFound::class) | |
fun onProductNotFound(e: ProductNotFound): ApiError { | |
log.error("error=product not found", e) | |
return ApiError(code = "PRODUCT_NOT_FOUND", message = e.message ?: "") | |
} |
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
@RestControllerAdvice | |
class ExceptionHandler { | |
@ResponseStatus(INTERNAL_SERVER_ERROR) [1] | |
@ExceptionHandler(Exception::class) | |
fun onException(exception: Exception): ApiError { | |
log.error("error=general message=${exception.message}", exception) | |
return ApiError("INTERNAL_SERVER_ERROR", exception.message ?: "") | |
} |
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
class ClientBuilder { | |
private var failOnUnknownProperty: Boolean = false | |
private var namingStrategy: PropertyNamingStrategy = PropertyNamingStrategy.LOWER_CAMEL_CASE | |
private var headers: MutableMap<String, String> = mutableMapOf() | |
private lateinit var baseUrl: String | |
fun withFailOnUnknownProperty(failOnUnknown: Boolean): ClientBuilder { | |
this.failOnUnknownProperty = failOnUnknown | |
return this | |
} |
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
get( | |
url = "/login", | |
responseClass = Token::class, | |
queryParameters = mapOf("admin", "true") | |
) | |
get( | |
url = "/login", | |
responseClass = Token::class, | |
headers = mapOf("Accept-Version", "v1") |
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
abstract class MicroserviceGateway { | |
abstract var webClient: WebClient | |
// outros métodos HTTP | |
fun <ResponseT : Any> get( | |
url: String, | |
responseClass: KClass<ResponseT>, | |
queryParameters: Map<String, String> = emptyMap(), | |
headers: Map<String, String> = emptyMap() |
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
@Component | |
@ConfigurationProperties("service.authentication") | |
class AuthenticationProperties { | |
final lateinit var baseUrl: String | |
final lateinit var username: String | |
final lateinit var password: String | |
} |
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
@Component | |
class AuthenticationGateway(private val properties: AuthenticationProperties [1]) : MicroserviceGateway() [2] { | |
override var webClient: WebClient = ClientBuilder() [3] | |
.withBaseUrl(properties.baseUrl) | |
.withFailOnUnknownProperty(false) | |
.withNamingStrategy(PropertyNamingStrategy.SNAKE_CASE) | |
.build() | |
fun authenticate(): AuthenticationToken [4] { | |
val request = |
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
@Configuration | |
class SwaggerResourceConfig { | |
@Primary | |
@Bean | |
fun swaggerResourcesProvider(defaultResourcesProvider: InMemorySwaggerResourcesProvider): SwaggerResourcesProvider { | |
return SwaggerResourcesProvider { | |
val resource = SwaggerResource() | |
resource.name = "Open API" | |
resource.swaggerVersion = "2.9.2" |