@@ -3,13 +3,14 @@ package org.gitanimals.render.infra
3
3
import org.gitanimals.core.auth.InternalAuthRequestInterceptor
4
4
import org.gitanimals.core.filter.MDCFilter
5
5
import org.gitanimals.rank.infra.HttpClientErrorHandler
6
- import org.gitanimals.render.app.GithubOpenApi
6
+ import org.gitanimals.render.app.GithubRestApi
7
7
import org.gitanimals.render.app.IdentityApi
8
8
import org.slf4j.MDC
9
9
import org.springframework.beans.factory.annotation.Value
10
10
import org.springframework.context.annotation.Bean
11
11
import org.springframework.context.annotation.Configuration
12
12
import org.springframework.context.annotation.Profile
13
+ import org.springframework.http.HttpHeaders
13
14
import org.springframework.web.client.RestClient
14
15
import org.springframework.web.client.support.RestClientAdapter
15
16
import org.springframework.web.service.invoker.HttpServiceProxyFactory
@@ -18,6 +19,7 @@ import org.springframework.web.service.invoker.HttpServiceProxyFactory
18
19
@Profile(" !test" )
19
20
class RenderHttpClientConfigurer (
20
21
@Value(" \$ {internal.secret}" ) private val internalSecret : String ,
22
+ @Value(" \$ {github.token}" ) private val token : String ,
21
23
private val internalAuthRequestInterceptor : InternalAuthRequestInterceptor ,
22
24
) {
23
25
@@ -45,18 +47,22 @@ class RenderHttpClientConfigurer(
45
47
}
46
48
47
49
@Bean
48
- fun renderGithubOpenApiHttpClient (): GithubOpenApi {
50
+ fun renderGithubRestApiHttpClient (): GithubRestApi {
49
51
val restClient = RestClient
50
52
.builder()
51
53
.defaultStatusHandler(renderHttpClientErrorHandler())
54
+ .requestInterceptor { request, body, execution ->
55
+ request.headers.add(HttpHeaders .AUTHORIZATION , token)
56
+ execution.execute(request, body)
57
+ }
52
58
.baseUrl(" https://api.github.com" )
53
59
.build()
54
60
55
61
val httpServiceProxyFactory = HttpServiceProxyFactory
56
62
.builderFor(RestClientAdapter .create(restClient))
57
63
.build()
58
64
59
- return httpServiceProxyFactory.createClient(GithubOpenApi ::class .java)
65
+ return httpServiceProxyFactory.createClient(GithubRestApi ::class .java)
60
66
}
61
67
62
68
@Bean
@@ -88,7 +94,7 @@ class RenderTestHttpClientConfigurer {
88
94
}
89
95
90
96
@Bean
91
- fun renderGithubOpenApiHttpClient (): GithubOpenApi {
97
+ fun renderGithubRestApiHttpClient (): GithubRestApi {
92
98
val restClient = RestClient
93
99
.builder()
94
100
.defaultStatusHandler(renderHttpClientErrorHandler())
@@ -99,7 +105,7 @@ class RenderTestHttpClientConfigurer {
99
105
.builderFor(RestClientAdapter .create(restClient))
100
106
.build()
101
107
102
- return httpServiceProxyFactory.createClient(GithubOpenApi ::class .java)
108
+ return httpServiceProxyFactory.createClient(GithubRestApi ::class .java)
103
109
}
104
110
105
111
@Bean
0 commit comments