Skip to content

Commit c82782f

Browse files
authored
Adding support for configuring subnet proxy (#1460)
Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
1 parent e626f59 commit c82782f

File tree

10 files changed

+121
-18
lines changed

10 files changed

+121
-18
lines changed

cluster/http_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (c *HTTPClient) Post(url, contentType string, body io.Reader) (resp *http.R
4747
return c.Client.Post(url, contentType, body)
4848
}
4949

50-
// Do implements http.Client.Do()
50+
// Do implement http.Client.Do()
5151
func (c *HTTPClient) Do(req *http.Request) (*http.Response, error) {
5252
return c.Client.Do(req)
5353
}

models/subnet_login_m_f_a_request.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/subnet_login_request.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

models/subnet_register_request.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/subnet/utils.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ func subnetAuthHeaders(authToken string) map[string]string {
6969
}
7070

7171
func httpDo(client cluster.HTTPClientI, req *http.Request) (*http.Response, error) {
72-
//if globalSubnetProxyURL != nil {
73-
// client.Transport.(*http.Transport).Proxy = http.ProxyURL(globalSubnetProxyURL)
74-
//}
7572
return client.Do(req)
7673
}
7774

portal-ui/src/screens/Console/License/types.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ export interface SubnetLoginRequest {
2727
username?: string;
2828
password?: string;
2929
apiKey?: string;
30+
proxy?: string;
3031
}
3132

3233
export interface SubnetRegisterRequest {
3334
token: string;
3435
account_id: string;
36+
proxy?: string;
3537
}
3638

3739
export interface SubnetOrganization {
@@ -54,6 +56,7 @@ export interface SubnetLoginWithMFARequest {
5456
username: string;
5557
otp: string;
5658
mfa_token: string;
59+
proxy?: string;
5760
}
5861

5962
export interface SubnetRegTokenResponse {

portal-ui/src/screens/Console/Support/Register.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import React, { Fragment, useCallback, useEffect, useState } from "react";
2929
import { CopyIcon, UsersIcon } from "../../../icons";
3030
import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye";
3131
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
32+
import DnsIcon from "@mui/icons-material/Dns";
3233
import OnlineRegistrationIcon from "../../../icons/OnlineRegistrationIcon";
3334
import OfflineRegistrationIcon from "../../../icons/OfflineRegistrationIcon";
3435
import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper";
@@ -60,6 +61,7 @@ import { setErrorSnackMessage } from "../../../actions";
6061
import HelpBox from "../../../common/HelpBox";
6162
import SettingsIcon from "../../../icons/SettingsIcon";
6263
import RegisterStatus from "./RegisterStatus";
64+
import FormSwitchWrapper from "../Common/FormComponents/FormSwitchWrapper/FormSwitchWrapper";
6365

6466
interface IRegister {
6567
classes: any;
@@ -170,6 +172,8 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => {
170172
const [clusterRegistered, setClusterRegistered] = useState<boolean>(false);
171173
const [initialLicenseLoading, setInitialLicenseLoading] =
172174
useState<boolean>(true);
175+
const [subnetProxy, setSubnetProxy] = useState<string>("");
176+
const [displaySubnetProxy, setDisplaySubnetProxy] = useState<boolean>(false);
173177

174178
const clearForm = () => {
175179
setSubnetAccessToken("");
@@ -240,6 +244,9 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => {
240244
token: token,
241245
account_id: account_id,
242246
};
247+
if (displaySubnetProxy) {
248+
request.proxy = subnetProxy;
249+
}
243250
api
244251
.invoke("POST", "/api/v1/subnet/register", request)
245252
.then(() => {
@@ -272,6 +279,9 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => {
272279
otp: subnetOTP,
273280
mfa_token: subnetMFAToken,
274281
};
282+
if (displaySubnetProxy) {
283+
request.proxy = subnetProxy;
284+
}
275285
api
276286
.invoke("POST", "/api/v1/subnet/login/mfa", request)
277287
.then((resp: SubnetLoginResponse) => {
@@ -308,6 +318,9 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => {
308318
password: subnetPassword,
309319
apiKey: license,
310320
};
321+
if (displaySubnetProxy) {
322+
request.proxy = subnetProxy;
323+
}
311324
api
312325
.invoke("POST", "/api/v1/subnet/login", request)
313326
.then((resp: SubnetLoginResponse) => {
@@ -604,6 +617,36 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => {
604617
a proxy to connect to Subnet.
605618
<br />
606619
<br />
620+
<Grid container>
621+
<Grid item xs={12} className={clsx(classes.actionsTray)}>
622+
<FormSwitchWrapper
623+
value="enableProxy"
624+
id="enableProxy"
625+
name="enableProxy"
626+
checked={displaySubnetProxy}
627+
onChange={(
628+
event: React.ChangeEvent<HTMLInputElement>
629+
) => {
630+
setDisplaySubnetProxy(event.target.checked);
631+
}}
632+
/>
633+
</Grid>
634+
<Grid item xs={6} className={clsx(classes.actionsTray)}>
635+
{displaySubnetProxy && (
636+
<InputBoxWrapper
637+
overlayIcon={<DnsIcon />}
638+
id="subnetProxy"
639+
name="subnetProxy"
640+
onChange={(
641+
event: React.ChangeEvent<HTMLInputElement>
642+
) => setSubnetProxy(event.target.value)}
643+
placeholder="https://192.168.1.3:3128"
644+
label=""
645+
value={subnetProxy}
646+
/>
647+
)}
648+
</Grid>
649+
</Grid>
607650
Alternatively you can try <OfflineRegistrationBackIcon />
608651
<Link
609652
className={classes.link}

restapi/admin_subnet.go

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24+
"net/http"
25+
"net/url"
2426

2527
"github.com/go-openapi/runtime/middleware"
2628
"github.com/minio/console/cluster"
@@ -58,10 +60,7 @@ func registerSubnetHandlers(api *operations.ConsoleAPI) {
5860
})
5961
// Get subnet info
6062
api.AdminAPISubnetInfoHandler = admin_api.SubnetInfoHandlerFunc(func(params admin_api.SubnetInfoParams, session *models.Principal) middleware.Responder {
61-
client := &cluster.HTTPClient{
62-
Client: GetConsoleHTTPClient(),
63-
}
64-
resp, err := GetSubnetInfoResponse(session, client)
63+
resp, err := GetSubnetInfoResponse(session)
6564
if err != nil {
6665
return admin_api.NewSubnetInfoDefault(int(err.Code)).WithPayload(err)
6766
}
@@ -113,8 +112,9 @@ func SubnetLogin(client cluster.HTTPClientI, username, password string) (string,
113112

114113
func GetSubnetLoginResponse(session *models.Principal, params admin_api.SubnetLoginParams) (*models.SubnetLoginResponse, *models.Error) {
115114
ctx := context.Background()
116-
httpClient := &cluster.HTTPClient{
117-
Client: GetConsoleHTTPClient(),
115+
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
116+
if err != nil {
117+
return nil, prepareError(err)
118118
}
119119
mAdmin, err := NewMinioAdminClient(session)
120120
if err != nil {
@@ -135,7 +135,7 @@ func GetSubnetLoginResponse(session *models.Principal, params admin_api.SubnetLo
135135
username := params.Body.Username
136136
password := params.Body.Password
137137
if username != "" && password != "" {
138-
token, mfa, err := SubnetLogin(httpClient, username, password)
138+
token, mfa, err := SubnetLogin(subnetHTTPClient, username, password)
139139
if err != nil {
140140
return nil, prepareError(err)
141141
}
@@ -172,11 +172,34 @@ func SubnetLoginWithMFA(client cluster.HTTPClientI, username, mfaToken, otp stri
172172
return nil, errors.New("something went wrong")
173173
}
174174

175+
// GetSubnetHTTPClient will return a client with proxy if configured, otherwise will return the default console http client
176+
func GetSubnetHTTPClient(proxy string) (*cluster.HTTPClient, error) {
177+
var subnetHTTPClient *http.Client
178+
if proxy != "" {
179+
transport := prepareSTSClientTransport(false)
180+
subnetHTTPClient = &http.Client{
181+
Transport: transport,
182+
}
183+
subnetProxyURL, err := url.Parse(proxy)
184+
if err != nil {
185+
return nil, err
186+
}
187+
subnetHTTPClient.Transport.(*http.Transport).Proxy = http.ProxyURL(subnetProxyURL)
188+
} else {
189+
subnetHTTPClient = GetConsoleHTTPClient()
190+
}
191+
clientI := &cluster.HTTPClient{
192+
Client: subnetHTTPClient,
193+
}
194+
return clientI, nil
195+
}
196+
175197
func GetSubnetLoginWithMFAResponse(params admin_api.SubnetLoginMFAParams) (*models.SubnetLoginResponse, *models.Error) {
176-
client := &cluster.HTTPClient{
177-
Client: GetConsoleHTTPClient(),
198+
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
199+
if err != nil {
200+
return nil, prepareError(err)
178201
}
179-
resp, err := SubnetLoginWithMFA(client, *params.Body.Username, *params.Body.MfaToken, *params.Body.Otp)
202+
resp, err := SubnetLoginWithMFA(subnetHTTPClient, *params.Body.Username, *params.Body.MfaToken, *params.Body.Otp)
180203
if err != nil {
181204
return nil, prepareError(err)
182205
}
@@ -231,17 +254,18 @@ func GetSubnetRegisterResponse(session *models.Principal, params admin_api.Subne
231254
return prepareError(err)
232255
}
233256
adminClient := AdminClient{Client: mAdmin}
234-
client := &cluster.HTTPClient{
235-
Client: GetConsoleHTTPClient(),
257+
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
258+
if err != nil {
259+
return prepareError(err)
236260
}
237-
err = GetSubnetRegister(ctx, adminClient, client, params)
261+
err = GetSubnetRegister(ctx, adminClient, subnetHTTPClient, params)
238262
if err != nil {
239263
return prepareError(err)
240264
}
241265
return nil
242266
}
243267

244-
func GetSubnetInfoResponse(session *models.Principal, client cluster.HTTPClientI) (*models.License, *models.Error) {
268+
func GetSubnetInfoResponse(session *models.Principal) (*models.License, *models.Error) {
245269
ctx := context.Background()
246270
mAdmin, err := NewMinioAdminClient(session)
247271
if err != nil {
@@ -255,6 +279,9 @@ func GetSubnetInfoResponse(session *models.Principal, client cluster.HTTPClientI
255279
if subnetTokens.APIKey == "" {
256280
return nil, prepareError(errLicenseNotFound)
257281
}
282+
client := &cluster.HTTPClient{
283+
Client: GetConsoleHTTPClient(),
284+
}
258285
licenseInfo, err := subnet.ParseLicense(client, subnetTokens.License)
259286
if err != nil {
260287
return nil, prepareError(err)

restapi/embedded_spec.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

swagger-console.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,8 @@ definitions:
41134113
subnetLoginRequest:
41144114
type: object
41154115
properties:
4116+
proxy:
4117+
type: string
41164118
username:
41174119
type: string
41184120
password:
@@ -4127,6 +4129,8 @@ definitions:
41274129
- otp
41284130
- mfa_token
41294131
properties:
4132+
proxy:
4133+
type: string
41304134
username:
41314135
type: string
41324136
otp:
@@ -4140,6 +4144,8 @@ definitions:
41404144
- token
41414145
- account_id
41424146
properties:
4147+
proxy:
4148+
type: string
41434149
token:
41444150
type: string
41454151
account_id:

0 commit comments

Comments
 (0)