From c82782fe9f6e096b6329816a81011afe40d87232 Mon Sep 17 00:00:00 2001 From: Lenin Alevski Date: Wed, 26 Jan 2022 11:53:11 -0600 Subject: [PATCH] Adding support for configuring subnet proxy (#1460) Signed-off-by: Lenin Alevski --- cluster/http_client.go | 2 +- models/subnet_login_m_f_a_request.go | 3 + models/subnet_login_request.go | 3 + models/subnet_register_request.go | 3 + pkg/subnet/utils.go | 3 - .../src/screens/Console/License/types.tsx | 3 + .../src/screens/Console/Support/Register.tsx | 43 ++++++++++++++ restapi/admin_subnet.go | 57 ++++++++++++++----- restapi/embedded_spec.go | 18 ++++++ swagger-console.yml | 6 ++ 10 files changed, 122 insertions(+), 19 deletions(-) diff --git a/cluster/http_client.go b/cluster/http_client.go index 1eca14aca..4d610379d 100644 --- a/cluster/http_client.go +++ b/cluster/http_client.go @@ -47,7 +47,7 @@ func (c *HTTPClient) Post(url, contentType string, body io.Reader) (resp *http.R return c.Client.Post(url, contentType, body) } -// Do implements http.Client.Do() +// Do implement http.Client.Do() func (c *HTTPClient) Do(req *http.Request) (*http.Response, error) { return c.Client.Do(req) } diff --git a/models/subnet_login_m_f_a_request.go b/models/subnet_login_m_f_a_request.go index 936a5f553..042db7cdf 100644 --- a/models/subnet_login_m_f_a_request.go +++ b/models/subnet_login_m_f_a_request.go @@ -44,6 +44,9 @@ type SubnetLoginMFARequest struct { // Required: true Otp *string `json:"otp"` + // proxy + Proxy string `json:"proxy,omitempty"` + // username // Required: true Username *string `json:"username"` diff --git a/models/subnet_login_request.go b/models/subnet_login_request.go index 13f8e0d5d..f111398dd 100644 --- a/models/subnet_login_request.go +++ b/models/subnet_login_request.go @@ -40,6 +40,9 @@ type SubnetLoginRequest struct { // password Password string `json:"password,omitempty"` + // proxy + Proxy string `json:"proxy,omitempty"` + // username Username string `json:"username,omitempty"` } diff --git a/models/subnet_register_request.go b/models/subnet_register_request.go index 4ab3e339d..f49dafc09 100644 --- a/models/subnet_register_request.go +++ b/models/subnet_register_request.go @@ -40,6 +40,9 @@ type SubnetRegisterRequest struct { // Required: true AccountID *string `json:"account_id"` + // proxy + Proxy string `json:"proxy,omitempty"` + // token // Required: true Token *string `json:"token"` diff --git a/pkg/subnet/utils.go b/pkg/subnet/utils.go index fa9796a94..7b509b78a 100644 --- a/pkg/subnet/utils.go +++ b/pkg/subnet/utils.go @@ -69,9 +69,6 @@ func subnetAuthHeaders(authToken string) map[string]string { } func httpDo(client cluster.HTTPClientI, req *http.Request) (*http.Response, error) { - //if globalSubnetProxyURL != nil { - // client.Transport.(*http.Transport).Proxy = http.ProxyURL(globalSubnetProxyURL) - //} return client.Do(req) } diff --git a/portal-ui/src/screens/Console/License/types.tsx b/portal-ui/src/screens/Console/License/types.tsx index 233a756bf..cf816109c 100644 --- a/portal-ui/src/screens/Console/License/types.tsx +++ b/portal-ui/src/screens/Console/License/types.tsx @@ -27,11 +27,13 @@ export interface SubnetLoginRequest { username?: string; password?: string; apiKey?: string; + proxy?: string; } export interface SubnetRegisterRequest { token: string; account_id: string; + proxy?: string; } export interface SubnetOrganization { @@ -54,6 +56,7 @@ export interface SubnetLoginWithMFARequest { username: string; otp: string; mfa_token: string; + proxy?: string; } export interface SubnetRegTokenResponse { diff --git a/portal-ui/src/screens/Console/Support/Register.tsx b/portal-ui/src/screens/Console/Support/Register.tsx index 98d66f420..621531c56 100644 --- a/portal-ui/src/screens/Console/Support/Register.tsx +++ b/portal-ui/src/screens/Console/Support/Register.tsx @@ -29,6 +29,7 @@ import React, { Fragment, useCallback, useEffect, useState } from "react"; import { CopyIcon, UsersIcon } from "../../../icons"; import RemoveRedEyeIcon from "@mui/icons-material/RemoveRedEye"; import VisibilityOffIcon from "@mui/icons-material/VisibilityOff"; +import DnsIcon from "@mui/icons-material/Dns"; import OnlineRegistrationIcon from "../../../icons/OnlineRegistrationIcon"; import OfflineRegistrationIcon from "../../../icons/OfflineRegistrationIcon"; import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper"; @@ -60,6 +61,7 @@ import { setErrorSnackMessage } from "../../../actions"; import HelpBox from "../../../common/HelpBox"; import SettingsIcon from "../../../icons/SettingsIcon"; import RegisterStatus from "./RegisterStatus"; +import FormSwitchWrapper from "../Common/FormComponents/FormSwitchWrapper/FormSwitchWrapper"; interface IRegister { classes: any; @@ -170,6 +172,8 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => { const [clusterRegistered, setClusterRegistered] = useState(false); const [initialLicenseLoading, setInitialLicenseLoading] = useState(true); + const [subnetProxy, setSubnetProxy] = useState(""); + const [displaySubnetProxy, setDisplaySubnetProxy] = useState(false); const clearForm = () => { setSubnetAccessToken(""); @@ -240,6 +244,9 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => { token: token, account_id: account_id, }; + if (displaySubnetProxy) { + request.proxy = subnetProxy; + } api .invoke("POST", "/api/v1/subnet/register", request) .then(() => { @@ -272,6 +279,9 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => { otp: subnetOTP, mfa_token: subnetMFAToken, }; + if (displaySubnetProxy) { + request.proxy = subnetProxy; + } api .invoke("POST", "/api/v1/subnet/login/mfa", request) .then((resp: SubnetLoginResponse) => { @@ -308,6 +318,9 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => { password: subnetPassword, apiKey: license, }; + if (displaySubnetProxy) { + request.proxy = subnetProxy; + } api .invoke("POST", "/api/v1/subnet/login", request) .then((resp: SubnetLoginResponse) => { @@ -604,6 +617,36 @@ const Register = ({ classes, displayErrorMessage }: IRegister) => { a proxy to connect to Subnet.

+ + + + ) => { + setDisplaySubnetProxy(event.target.checked); + }} + /> + + + {displaySubnetProxy && ( + } + id="subnetProxy" + name="subnetProxy" + onChange={( + event: React.ChangeEvent + ) => setSubnetProxy(event.target.value)} + placeholder="https://192.168.1.3:3128" + label="" + value={subnetProxy} + /> + )} + + Alternatively you can try