Skip to content

Commit 6c8dad2

Browse files
committed
lint
Signed-off-by: Daniel Valdivia <[email protected]>
1 parent 63310da commit 6c8dad2

File tree

4 files changed

+38
-28
lines changed

4 files changed

+38
-28
lines changed

pkg/acl/endpoints_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func TestGetAuthorizedEndpoints(t *testing.T) {
5050
args: args{
5151
[]string{"admin:ServerInfo"},
5252
},
53-
want: 7,
53+
want: 8,
5454
},
5555
{
5656
name: "policies endpoint",
@@ -72,7 +72,7 @@ func TestGetAuthorizedEndpoints(t *testing.T) {
7272
"admin:*",
7373
},
7474
},
75-
want: 21,
75+
want: 22,
7676
},
7777
{
7878
name: "all s3 endpoints",
@@ -91,7 +91,7 @@ func TestGetAuthorizedEndpoints(t *testing.T) {
9191
"s3:*",
9292
},
9393
},
94-
want: 30,
94+
want: 31,
9595
},
9696
{
9797
name: "Console User - default endpoints",

restapi/admin_console.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ func startConsoleLog(ctx context.Context, conn WSConn, client MinioAdmin) error
7474
func serializeConsoleLogInfo(l *madmin.LogInfo) (logInfo madmin.LogInfo) {
7575
logInfo = *l
7676
if logInfo.ConsoleMsg != "" {
77-
if strings.HasPrefix(logInfo.ConsoleMsg, "\n") {
78-
logInfo.ConsoleMsg = strings.TrimPrefix(logInfo.ConsoleMsg, "\n")
79-
}
77+
logInfo.ConsoleMsg = strings.TrimPrefix(logInfo.ConsoleMsg, "\n")
8078
}
8179
if logInfo.Time != "" {
8280
logInfo.Time = getLogTime(logInfo.Time)

restapi/admin_profiling_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,10 @@ func TestStopProfiling(t *testing.T) {
100100
return &ClosingBuffer{bytes.NewBufferString("In memory string eaeae")}, nil
101101
}
102102
function := "stopProfiling()"
103-
readCloserInterface, err := stopProfiling(ctx, adminClient)
103+
_, err := stopProfiling(ctx, adminClient)
104104
if err != nil {
105105
t.Errorf("Failed on %s:, error occurred: %s", function, err.Error())
106106
}
107-
// Check return type of stopProfiling is io.ReadCloser by doing a cast
108-
assert.NotPanics(func() { readCloserInterface.(io.ReadCloser).Close() })
109107
// Test-2 : stopProfiling() Correctly handles errors returned by Minio
110108
// mock function response from stopProfiling()
111109
minioStopProfiling = func() (io.ReadCloser, error) {

restapi/proxy.go

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
5858
}
5959
claims, err := auth.SessionTokenAuthenticate(token)
6060
if err != nil {
61-
log.Println("Unable to validate the session token %s: %v", token, err)
61+
log.Printf("Unable to validate the session token %s: %v\n", token, err)
6262
responseWriter.WriteHeader(401)
6363

6464
return
@@ -79,6 +79,7 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
7979
tenant, err := opClient.TenantGet(req.Context(), namespace, tenantName, metav1.GetOptions{})
8080
if err != nil {
8181
log.Println(err)
82+
responseWriter.WriteHeader(502)
8283
return
8384
}
8485

@@ -89,10 +90,10 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
8990
tenantSchema = "http"
9091
}
9192

92-
tenantUrl := fmt.Sprintf("%s://%s.%s.svc.%s:9443", tenantSchema, tenant.ConsoleCIServiceName(), tenant.Namespace, v2.GetClusterDomain())
93+
tenantURL := fmt.Sprintf("%s://%s.%s.svc.%s:9443", tenantSchema, tenant.ConsoleCIServiceName(), tenant.Namespace, v2.GetClusterDomain())
9394
// for development
94-
//tenantUrl = "http://localhost:9091"
95-
tenantUrl = "https://localhost:9443"
95+
//tenantURL = "http://localhost:9091"
96+
//tenantURL = "https://localhost:9443"
9697

9798
h := sha1.New()
9899
h.Write([]byte(nsTenant))
@@ -101,12 +102,13 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
101102
tenantCookie, err := req.Cookie(tenantCookieName)
102103
if err != nil {
103104
// login to tenantName
104-
loginUrl := fmt.Sprintf("%s/api/v1/login", tenantUrl)
105+
loginURL := fmt.Sprintf("%s/api/v1/login", tenantURL)
105106

106107
// get the tenant credentials
107108
clientSet, err := cluster.K8sClient(STSSessionToken)
108109
if err != nil {
109110
log.Println(err)
111+
responseWriter.WriteHeader(500)
110112
return
111113
}
112114

@@ -123,24 +125,26 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
123125
}
124126
payload, _ := json.Marshal(data)
125127

126-
loginReq, err := http.NewRequest(http.MethodPost, loginUrl, bytes.NewReader(payload))
128+
loginReq, err := http.NewRequest(http.MethodPost, loginURL, bytes.NewReader(payload))
127129
if err != nil {
128130
log.Println(err)
131+
responseWriter.WriteHeader(500)
129132
return
130133
}
131134
loginReq.Header.Add("Content-Type", "application/json")
132135

133-
if err != nil {
134-
log.Println(err)
135-
return
136-
}
137-
138136
tr := &http.Transport{
139137
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
140138
}
141139
client := &http.Client{Transport: tr}
142140

143141
loginResp, err := client.Do(loginReq)
142+
if err != nil {
143+
log.Println(err)
144+
responseWriter.WriteHeader(500)
145+
return
146+
}
147+
144148
for _, c := range loginResp.Cookies() {
145149
if c.Name == "token" {
146150
tenantCookie = c
@@ -159,15 +163,15 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
159163
defer loginResp.Body.Close()
160164
}
161165

162-
origin, _ := url2.Parse(tenantUrl)
163-
targetUrl, _ := url2.Parse(tenantUrl)
166+
origin, _ := url2.Parse(tenantURL)
167+
targetURL, _ := url2.Parse(tenantURL)
164168

165-
targetUrl.Scheme = "http"
169+
targetURL.Scheme = "http"
166170
if tenant.TLS() {
167-
targetUrl.Scheme = "https"
171+
targetURL.Scheme = "https"
168172
}
169-
targetUrl.Host = origin.Host
170-
targetUrl.Path = strings.Replace(req.URL.Path, fmt.Sprintf("/api/proxy/%s/%s", namespace, tenantName), "", -1)
173+
targetURL.Host = origin.Host
174+
targetURL.Path = strings.Replace(req.URL.Path, fmt.Sprintf("/api/proxy/%s/%s", namespace, tenantName), "", -1)
171175

172176
proxiedCookie := &http.Cookie{
173177
Name: "token",
@@ -178,7 +182,7 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
178182
}
179183

180184
proxyCookieJar, _ := cookiejar.New(nil)
181-
proxyCookieJar.SetCookies(targetUrl, []*http.Cookie{proxiedCookie})
185+
proxyCookieJar.SetCookies(targetURL, []*http.Cookie{proxiedCookie})
182186

183187
tr := &http.Transport{
184188
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
@@ -189,13 +193,23 @@ func serveProxy(responseWriter http.ResponseWriter, req *http.Request) {
189193
return http.ErrUseLastResponse
190194
}}
191195

192-
proxRequest, err := http.NewRequest(req.Method, targetUrl.String(), req.Body)
196+
proxRequest, err := http.NewRequest(req.Method, targetURL.String(), req.Body)
197+
if err != nil {
198+
log.Println(err)
199+
responseWriter.WriteHeader(500)
200+
return
201+
}
193202

194203
for _, v := range req.Header.Values("Content-Type") {
195204
proxRequest.Header.Add("Content-Type", v)
196205
}
197206

198207
resp, err := client.Do(proxRequest)
208+
if err != nil {
209+
log.Println(err)
210+
responseWriter.WriteHeader(500)
211+
return
212+
}
199213

200214
for hk, hv := range resp.Header {
201215
if hk != "X-Frame-Options" {

0 commit comments

Comments
 (0)