9
9
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
10
10
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/checks"
11
11
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/checks/factory"
12
+ "github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/client_wrapper"
12
13
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/config"
13
14
"github.com/OctopusSolutionsEngineering/OctopusRecommendationEngine/internal/executor"
14
15
"github.com/briandowns/spinner"
@@ -69,14 +70,16 @@ func Entry(octolintConfig *config.OctolintConfig) ([]checks.OctopusCheckResult,
69
70
octolintConfig .Space = spaceId
70
71
}
71
72
72
- client , err := createClient (octolintConfig )
73
+ httpClient , err := createHttpClient (octolintConfig )
73
74
74
75
if err != nil {
75
- return nil , errors .New ("Failed to create the Octopus client_wrapper . Check that the url, api key, and space are correct.\n The error was: " + err .Error ())
76
+ return nil , errors .New ("Failed to create the HTTP client . Check that the url is correct.\n The error was: " + err .Error ())
76
77
}
77
78
78
- if err := setClientHeaders (client , octolintConfig ); err != nil {
79
- return nil , err
79
+ client , err := createClient (httpClient , octolintConfig )
80
+
81
+ if err != nil {
82
+ return nil , errors .New ("Failed to create the Octopus client_wrapper. Check that the url, api key, and space are correct.\n The error was: " + err .Error ())
80
83
}
81
84
82
85
checkFactory := factory .NewOctopusCheckFactory (client , octolintConfig .Url , octolintConfig .Space )
@@ -113,7 +116,7 @@ func Entry(octolintConfig *config.OctolintConfig) ([]checks.OctopusCheckResult,
113
116
return results , nil
114
117
}
115
118
116
- func createClient (octolintConfig * config.OctolintConfig ) (* client.Client , error ) {
119
+ func createClient (httpClient * http. Client , octolintConfig * config.OctolintConfig ) (* client.Client , error ) {
117
120
118
121
parsedUrl , err := getHost (octolintConfig )
119
122
@@ -122,10 +125,10 @@ func createClient(octolintConfig *config.OctolintConfig) (*client.Client, error)
122
125
}
123
126
124
127
if octolintConfig .ApiKey != "" {
125
- return createClientApiKey (parsedUrl , octolintConfig .Space , octolintConfig .ApiKey )
128
+ return createClientApiKey (httpClient , parsedUrl , octolintConfig .Space , octolintConfig .ApiKey )
126
129
}
127
130
128
- return createClientAccessToken (parsedUrl , octolintConfig .Space , octolintConfig .AccessToken )
131
+ return createClientAccessToken (httpClient , parsedUrl , octolintConfig .Space , octolintConfig .AccessToken )
129
132
}
130
133
131
134
func getHost (octolintConfig * config.OctolintConfig ) (* url.URL , error ) {
@@ -136,38 +139,47 @@ func getHost(octolintConfig *config.OctolintConfig) (*url.URL, error) {
136
139
return url .Parse (octolintConfig .Url )
137
140
}
138
141
139
- func setClientHeaders ( client * client. Client , octolintConfig * config.OctolintConfig ) error {
142
+ func createHttpClient ( octolintConfig * config.OctolintConfig ) ( * http. Client , error ) {
140
143
if octolintConfig .UseRedirector {
141
144
parsedUrl , err := url .Parse (octolintConfig .Url )
142
145
143
146
if err != nil {
144
- return err
147
+ return nil , err
148
+ }
149
+
150
+ headers := map [string ]string {
151
+ "X_REDIRECTION_UPSTREAM_HOST" : parsedUrl .Hostname (),
152
+ "X_REDIRECTION_REDIRECTIONS" : octolintConfig .RedirectorRedirections ,
153
+ "X_REDIRECTION_API_KEY" : octolintConfig .RedirecrtorApiKey ,
154
+ "X_REDIRECTION_SERVICE_API_KEY" : octolintConfig .RedirectorServiceApiKey ,
145
155
}
146
156
147
- headers := client .HttpSession ().DefaultHeaders
148
- headers ["X_REDIRECTION_UPSTREAM_HOST" ] = parsedUrl .Hostname ()
149
- headers ["X_REDIRECTION_REDIRECTIONS" ] = octolintConfig .RedirectorRedirections
150
- headers ["X_REDIRECTION_API_KEY" ] = octolintConfig .RedirecrtorApiKey
151
- headers ["X_REDIRECTION_SERVICE_API_KEY" ] = octolintConfig .RedirectorServiceApiKey
157
+ return & http.Client {
158
+ Transport : & client_wrapper.HeaderRoundTripper {
159
+ Transport : http .DefaultTransport ,
160
+ Headers : headers ,
161
+ },
162
+ }, nil
152
163
}
153
164
154
- return nil
165
+ return & http. Client {}, nil
155
166
}
156
167
157
- func createClientApiKey (apiURL * url.URL , spaceId string , apiKey string ) (* client.Client , error ) {
168
+ func createClientApiKey (httpClient * http. Client , apiURL * url.URL , spaceId string , apiKey string ) (* client.Client , error ) {
158
169
apiKeyCredential , err := client .NewApiKey (apiKey )
159
170
if err != nil {
160
171
return nil , err
161
172
}
162
- return client .NewClientWithCredentials (nil , apiURL , apiKeyCredential , spaceId , "" )
173
+
174
+ return client .NewClientWithCredentials (httpClient , apiURL , apiKeyCredential , spaceId , "" )
163
175
}
164
176
165
- func createClientAccessToken (apiURL * url.URL , spaceId string , accessToken string ) (* client.Client , error ) {
177
+ func createClientAccessToken (httpClient * http. Client , apiURL * url.URL , spaceId string , accessToken string ) (* client.Client , error ) {
166
178
accessTokenCredential , err := client .NewAccessToken (accessToken )
167
179
if err != nil {
168
180
return nil , err
169
181
}
170
- return client .NewClientWithCredentials (nil , apiURL , accessTokenCredential , spaceId , "" )
182
+ return client .NewClientWithCredentials (httpClient , apiURL , accessTokenCredential , spaceId , "" )
171
183
}
172
184
173
185
func ErrorExit (message string ) {
0 commit comments