Skip to content

Commit c52ea56

Browse files
committed
Adding support for configuring subnet proxy
Signed-off-by: Lenin Alevski <[email protected]>
1 parent e626f59 commit c52ea56

File tree

10 files changed

+121
-19
lines changed

10 files changed

+121
-19
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24-
2524
"github.com/go-openapi/runtime/middleware"
2625
"github.com/minio/console/cluster"
2726
"github.com/minio/console/models"
2827
"github.com/minio/console/pkg/subnet"
2928
"github.com/minio/console/restapi/operations"
3029
"github.com/minio/console/restapi/operations/admin_api"
3130
"github.com/minio/madmin-go"
31+
"net/http"
32+
"net/url"
3233
)
3334

3435
func registerSubnetHandlers(api *operations.ConsoleAPI) {
@@ -58,10 +59,7 @@ func registerSubnetHandlers(api *operations.ConsoleAPI) {
5859
})
5960
// Get subnet info
6061
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)
62+
resp, err := GetSubnetInfoResponse(session)
6563
if err != nil {
6664
return admin_api.NewSubnetInfoDefault(int(err.Code)).WithPayload(err)
6765
}
@@ -113,8 +111,9 @@ func SubnetLogin(client cluster.HTTPClientI, username, password string) (string,
113111

114112
func GetSubnetLoginResponse(session *models.Principal, params admin_api.SubnetLoginParams) (*models.SubnetLoginResponse, *models.Error) {
115113
ctx := context.Background()
116-
httpClient := &cluster.HTTPClient{
117-
Client: GetConsoleHTTPClient(),
114+
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
115+
if err != nil {
116+
return nil, prepareError(err)
118117
}
119118
mAdmin, err := NewMinioAdminClient(session)
120119
if err != nil {
@@ -135,7 +134,7 @@ func GetSubnetLoginResponse(session *models.Principal, params admin_api.SubnetLo
135134
username := params.Body.Username
136135
password := params.Body.Password
137136
if username != "" && password != "" {
138-
token, mfa, err := SubnetLogin(httpClient, username, password)
137+
token, mfa, err := SubnetLogin(subnetHTTPClient, username, password)
139138
if err != nil {
140139
return nil, prepareError(err)
141140
}
@@ -172,11 +171,34 @@ func SubnetLoginWithMFA(client cluster.HTTPClientI, username, mfaToken, otp stri
172171
return nil, errors.New("something went wrong")
173172
}
174173

174+
// GetSubnetHTTPClient will return a client with proxy if configured, otherwise will return the default console http client
175+
func GetSubnetHTTPClient(proxy string) (*cluster.HTTPClient, error) {
176+
var subnetHTTPClient *http.Client
177+
if proxy != "" {
178+
transport := prepareSTSClientTransport(false)
179+
subnetHTTPClient = &http.Client{
180+
Transport: transport,
181+
}
182+
subnetProxyURL, err := url.Parse(proxy)
183+
if err != nil {
184+
return nil, err
185+
}
186+
subnetHTTPClient.Transport.(*http.Transport).Proxy = http.ProxyURL(subnetProxyURL)
187+
} else {
188+
subnetHTTPClient = GetConsoleHTTPClient()
189+
}
190+
clientI := &cluster.HTTPClient{
191+
Client: subnetHTTPClient,
192+
}
193+
return clientI, nil
194+
}
195+
175196
func GetSubnetLoginWithMFAResponse(params admin_api.SubnetLoginMFAParams) (*models.SubnetLoginResponse, *models.Error) {
176-
client := &cluster.HTTPClient{
177-
Client: GetConsoleHTTPClient(),
197+
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
198+
if err != nil {
199+
return nil, prepareError(err)
178200
}
179-
resp, err := SubnetLoginWithMFA(client, *params.Body.Username, *params.Body.MfaToken, *params.Body.Otp)
201+
resp, err := SubnetLoginWithMFA(subnetHTTPClient, *params.Body.Username, *params.Body.MfaToken, *params.Body.Otp)
180202
if err != nil {
181203
return nil, prepareError(err)
182204
}
@@ -231,17 +253,18 @@ func GetSubnetRegisterResponse(session *models.Principal, params admin_api.Subne
231253
return prepareError(err)
232254
}
233255
adminClient := AdminClient{Client: mAdmin}
234-
client := &cluster.HTTPClient{
235-
Client: GetConsoleHTTPClient(),
256+
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
257+
if err != nil {
258+
return prepareError(err)
236259
}
237-
err = GetSubnetRegister(ctx, adminClient, client, params)
260+
err = GetSubnetRegister(ctx, adminClient, subnetHTTPClient, params)
238261
if err != nil {
239262
return prepareError(err)
240263
}
241264
return nil
242265
}
243266

244-
func GetSubnetInfoResponse(session *models.Principal, client cluster.HTTPClientI) (*models.License, *models.Error) {
267+
func GetSubnetInfoResponse(session *models.Principal) (*models.License, *models.Error) {
245268
ctx := context.Background()
246269
mAdmin, err := NewMinioAdminClient(session)
247270
if err != nil {
@@ -255,6 +278,9 @@ func GetSubnetInfoResponse(session *models.Principal, client cluster.HTTPClientI
255278
if subnetTokens.APIKey == "" {
256279
return nil, prepareError(errLicenseNotFound)
257280
}
281+
client := &cluster.HTTPClient{
282+
Client: GetConsoleHTTPClient(),
283+
}
258284
licenseInfo, err := subnet.ParseLicense(client, subnetTokens.License)
259285
if err != nil {
260286
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)