Adding support for configuring subnet proxy (#1460)
Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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"`
|
||||
}
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<boolean>(false);
|
||||
const [initialLicenseLoading, setInitialLicenseLoading] =
|
||||
useState<boolean>(true);
|
||||
const [subnetProxy, setSubnetProxy] = useState<string>("");
|
||||
const [displaySubnetProxy, setDisplaySubnetProxy] = useState<boolean>(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.
|
||||
<br />
|
||||
<br />
|
||||
<Grid container>
|
||||
<Grid item xs={12} className={clsx(classes.actionsTray)}>
|
||||
<FormSwitchWrapper
|
||||
value="enableProxy"
|
||||
id="enableProxy"
|
||||
name="enableProxy"
|
||||
checked={displaySubnetProxy}
|
||||
onChange={(
|
||||
event: React.ChangeEvent<HTMLInputElement>
|
||||
) => {
|
||||
setDisplaySubnetProxy(event.target.checked);
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={6} className={clsx(classes.actionsTray)}>
|
||||
{displaySubnetProxy && (
|
||||
<InputBoxWrapper
|
||||
overlayIcon={<DnsIcon />}
|
||||
id="subnetProxy"
|
||||
name="subnetProxy"
|
||||
onChange={(
|
||||
event: React.ChangeEvent<HTMLInputElement>
|
||||
) => setSubnetProxy(event.target.value)}
|
||||
placeholder="https://192.168.1.3:3128"
|
||||
label=""
|
||||
value={subnetProxy}
|
||||
/>
|
||||
)}
|
||||
</Grid>
|
||||
</Grid>
|
||||
Alternatively you can try <OfflineRegistrationBackIcon />
|
||||
<Link
|
||||
className={classes.link}
|
||||
|
||||
@@ -21,6 +21,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/minio/console/cluster"
|
||||
@@ -58,10 +60,7 @@ func registerSubnetHandlers(api *operations.ConsoleAPI) {
|
||||
})
|
||||
// Get subnet info
|
||||
api.AdminAPISubnetInfoHandler = admin_api.SubnetInfoHandlerFunc(func(params admin_api.SubnetInfoParams, session *models.Principal) middleware.Responder {
|
||||
client := &cluster.HTTPClient{
|
||||
Client: GetConsoleHTTPClient(),
|
||||
}
|
||||
resp, err := GetSubnetInfoResponse(session, client)
|
||||
resp, err := GetSubnetInfoResponse(session)
|
||||
if err != nil {
|
||||
return admin_api.NewSubnetInfoDefault(int(err.Code)).WithPayload(err)
|
||||
}
|
||||
@@ -113,8 +112,9 @@ func SubnetLogin(client cluster.HTTPClientI, username, password string) (string,
|
||||
|
||||
func GetSubnetLoginResponse(session *models.Principal, params admin_api.SubnetLoginParams) (*models.SubnetLoginResponse, *models.Error) {
|
||||
ctx := context.Background()
|
||||
httpClient := &cluster.HTTPClient{
|
||||
Client: GetConsoleHTTPClient(),
|
||||
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
mAdmin, err := NewMinioAdminClient(session)
|
||||
if err != nil {
|
||||
@@ -135,7 +135,7 @@ func GetSubnetLoginResponse(session *models.Principal, params admin_api.SubnetLo
|
||||
username := params.Body.Username
|
||||
password := params.Body.Password
|
||||
if username != "" && password != "" {
|
||||
token, mfa, err := SubnetLogin(httpClient, username, password)
|
||||
token, mfa, err := SubnetLogin(subnetHTTPClient, username, password)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
@@ -172,11 +172,34 @@ func SubnetLoginWithMFA(client cluster.HTTPClientI, username, mfaToken, otp stri
|
||||
return nil, errors.New("something went wrong")
|
||||
}
|
||||
|
||||
func GetSubnetLoginWithMFAResponse(params admin_api.SubnetLoginMFAParams) (*models.SubnetLoginResponse, *models.Error) {
|
||||
client := &cluster.HTTPClient{
|
||||
Client: GetConsoleHTTPClient(),
|
||||
// GetSubnetHTTPClient will return a client with proxy if configured, otherwise will return the default console http client
|
||||
func GetSubnetHTTPClient(proxy string) (*cluster.HTTPClient, error) {
|
||||
var subnetHTTPClient *http.Client
|
||||
if proxy != "" {
|
||||
transport := prepareSTSClientTransport(false)
|
||||
subnetHTTPClient = &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
subnetProxyURL, err := url.Parse(proxy)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
subnetHTTPClient.Transport.(*http.Transport).Proxy = http.ProxyURL(subnetProxyURL)
|
||||
} else {
|
||||
subnetHTTPClient = GetConsoleHTTPClient()
|
||||
}
|
||||
resp, err := SubnetLoginWithMFA(client, *params.Body.Username, *params.Body.MfaToken, *params.Body.Otp)
|
||||
clientI := &cluster.HTTPClient{
|
||||
Client: subnetHTTPClient,
|
||||
}
|
||||
return clientI, nil
|
||||
}
|
||||
|
||||
func GetSubnetLoginWithMFAResponse(params admin_api.SubnetLoginMFAParams) (*models.SubnetLoginResponse, *models.Error) {
|
||||
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
resp, err := SubnetLoginWithMFA(subnetHTTPClient, *params.Body.Username, *params.Body.MfaToken, *params.Body.Otp)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
}
|
||||
@@ -231,17 +254,18 @@ func GetSubnetRegisterResponse(session *models.Principal, params admin_api.Subne
|
||||
return prepareError(err)
|
||||
}
|
||||
adminClient := AdminClient{Client: mAdmin}
|
||||
client := &cluster.HTTPClient{
|
||||
Client: GetConsoleHTTPClient(),
|
||||
subnetHTTPClient, err := GetSubnetHTTPClient(params.Body.Proxy)
|
||||
if err != nil {
|
||||
return prepareError(err)
|
||||
}
|
||||
err = GetSubnetRegister(ctx, adminClient, client, params)
|
||||
err = GetSubnetRegister(ctx, adminClient, subnetHTTPClient, params)
|
||||
if err != nil {
|
||||
return prepareError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetSubnetInfoResponse(session *models.Principal, client cluster.HTTPClientI) (*models.License, *models.Error) {
|
||||
func GetSubnetInfoResponse(session *models.Principal) (*models.License, *models.Error) {
|
||||
ctx := context.Background()
|
||||
mAdmin, err := NewMinioAdminClient(session)
|
||||
if err != nil {
|
||||
@@ -255,6 +279,9 @@ func GetSubnetInfoResponse(session *models.Principal, client cluster.HTTPClientI
|
||||
if subnetTokens.APIKey == "" {
|
||||
return nil, prepareError(errLicenseNotFound)
|
||||
}
|
||||
client := &cluster.HTTPClient{
|
||||
Client: GetConsoleHTTPClient(),
|
||||
}
|
||||
licenseInfo, err := subnet.ParseLicense(client, subnetTokens.License)
|
||||
if err != nil {
|
||||
return nil, prepareError(err)
|
||||
|
||||
@@ -5688,6 +5688,9 @@ func init() {
|
||||
"otp": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -5702,6 +5705,9 @@ func init() {
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -5760,6 +5766,9 @@ func init() {
|
||||
"account_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -11875,6 +11884,9 @@ func init() {
|
||||
"otp": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -11889,6 +11901,9 @@ func init() {
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy": {
|
||||
"type": "string"
|
||||
},
|
||||
"username": {
|
||||
"type": "string"
|
||||
}
|
||||
@@ -11947,6 +11962,9 @@ func init() {
|
||||
"account_id": {
|
||||
"type": "string"
|
||||
},
|
||||
"proxy": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
}
|
||||
|
||||
@@ -4113,6 +4113,8 @@ definitions:
|
||||
subnetLoginRequest:
|
||||
type: object
|
||||
properties:
|
||||
proxy:
|
||||
type: string
|
||||
username:
|
||||
type: string
|
||||
password:
|
||||
@@ -4127,6 +4129,8 @@ definitions:
|
||||
- otp
|
||||
- mfa_token
|
||||
properties:
|
||||
proxy:
|
||||
type: string
|
||||
username:
|
||||
type: string
|
||||
otp:
|
||||
@@ -4140,6 +4144,8 @@ definitions:
|
||||
- token
|
||||
- account_id
|
||||
properties:
|
||||
proxy:
|
||||
type: string
|
||||
token:
|
||||
type: string
|
||||
account_id:
|
||||
|
||||
Reference in New Issue
Block a user