Bring trace, watch, heal and logs back to user console UI (#491)

This commit is contained in:
Cesar N
2020-12-09 17:10:39 -06:00
committed by GitHub
parent 2d6f949359
commit a4ad341a18
39 changed files with 585 additions and 1305 deletions

7
go.sum
View File

@@ -755,14 +755,13 @@ github.com/minio/minio v0.0.0-20201203235615-de9b64834eda h1:ZE7O7pA+8zTJZVOuZrI
github.com/minio/minio v0.0.0-20201203235615-de9b64834eda/go.mod h1:+wH6R6AjgNDUvMBb24p/e7zn8VU+ChUAXy4uhopGxQA= github.com/minio/minio v0.0.0-20201203235615-de9b64834eda/go.mod h1:+wH6R6AjgNDUvMBb24p/e7zn8VU+ChUAXy4uhopGxQA=
github.com/minio/minio-go/v7 v7.0.6 h1:9czXaG0LEZ9s74smSqy0rm034MxngQoP6HTTuSc5GEs= github.com/minio/minio-go/v7 v7.0.6 h1:9czXaG0LEZ9s74smSqy0rm034MxngQoP6HTTuSc5GEs=
github.com/minio/minio-go/v7 v7.0.6/go.mod h1:HcIuq+11d/3MfavIPZiswSzfQ1VJ2Lwxp/XLtW46IWQ= github.com/minio/minio-go/v7 v7.0.6/go.mod h1:HcIuq+11d/3MfavIPZiswSzfQ1VJ2Lwxp/XLtW46IWQ=
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/minio/simdjson-go v0.1.5-0.20200303142138-b17fe061ea37/go.mod h1:oKURrZZEBtqObgJrSjN1Ln2n9MJj2icuBTkeJzZnvSI=
github.com/minio/simdjson-go v0.1.5/go.mod h1:oKURrZZEBtqObgJrSjN1Ln2n9MJj2icuBTkeJzZnvSI=
github.com/minio/operator v0.0.0-20201204220226-9901d1d0766c h1:2QpnenH2gieq5yVh6sZYylXKCoBgwKkxcgqkLr/fq9M= github.com/minio/operator v0.0.0-20201204220226-9901d1d0766c h1:2QpnenH2gieq5yVh6sZYylXKCoBgwKkxcgqkLr/fq9M=
github.com/minio/operator v0.0.0-20201204220226-9901d1d0766c/go.mod h1:Xnb44PIBZF/JCN4uXEEzf9vFwhnB9zXsQgVKU7GThiM= github.com/minio/operator v0.0.0-20201204220226-9901d1d0766c/go.mod h1:Xnb44PIBZF/JCN4uXEEzf9vFwhnB9zXsQgVKU7GThiM=
github.com/minio/selfupdate v0.3.1 h1:BWEFSNnrZVMUWXbXIgLDNDjbejkmpAmZvy/nCz1HlEs= github.com/minio/selfupdate v0.3.1 h1:BWEFSNnrZVMUWXbXIgLDNDjbejkmpAmZvy/nCz1HlEs=
github.com/minio/selfupdate v0.3.1/go.mod h1:b8ThJzzH7u2MkF6PcIra7KaXO9Khf6alWPvMSyTDCFM= github.com/minio/selfupdate v0.3.1/go.mod h1:b8ThJzzH7u2MkF6PcIra7KaXO9Khf6alWPvMSyTDCFM=
github.com/minio/sha256-simd v0.1.1 h1:5QHSlgo3nt5yKOJrC7W8w7X+NFl8cMPZm96iu8kKUJU=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/minio/simdjson-go v0.1.5/go.mod h1:oKURrZZEBtqObgJrSjN1Ln2n9MJj2icuBTkeJzZnvSI=
github.com/minio/sio v0.2.1 h1:NjzKiIMSMcHediVQR0AFVx2tp7Wxh9tKPfDI3kH7aHQ= github.com/minio/sio v0.2.1 h1:NjzKiIMSMcHediVQR0AFVx2tp7Wxh9tKPfDI3kH7aHQ=
github.com/minio/sio v0.2.1/go.mod h1:8b0yPp2avGThviy/+OCJBI6OMpvxoUuiLvE6F1lebhw= github.com/minio/sio v0.2.1/go.mod h1:8b0yPp2avGThviy/+OCJBI6OMpvxoUuiLvE6F1lebhw=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=

View File

@@ -40,6 +40,10 @@ var (
objectBrowserBucket = "/object-browser/:bucket" objectBrowserBucket = "/object-browser/:bucket"
mainObjectBrowser = "/object-browser" mainObjectBrowser = "/object-browser"
license = "/license" license = "/license"
watch = "/watch"
heal = "/heal"
trace = "/trace"
logs = "/logs"
) )
type ConfigurationActionSet struct { type ConfigurationActionSet struct {
@@ -200,6 +204,46 @@ var licenseActionSet = ConfigurationActionSet{
actions: iampolicy.NewActionSet(), actions: iampolicy.NewActionSet(),
} }
// watchActionSet contains the list of admin actions required for this endpoint to work
var watchActionSet = ConfigurationActionSet{
actionTypes: iampolicy.NewActionSet(
iampolicy.AllAdminActions,
),
actions: iampolicy.NewActionSet(
iampolicy.ListenBucketNotificationAction,
),
}
// healActionSet contains the list of admin actions required for this endpoint to work
var healActionSet = ConfigurationActionSet{
actionTypes: iampolicy.NewActionSet(
iampolicy.AllAdminActions,
),
actions: iampolicy.NewActionSet(
iampolicy.HealAdminAction,
),
}
// logsActionSet contains the list of admin actions required for this endpoint to work
var logsActionSet = ConfigurationActionSet{
actionTypes: iampolicy.NewActionSet(
iampolicy.AllAdminActions,
),
actions: iampolicy.NewActionSet(
iampolicy.ConsoleLogAdminAction,
),
}
// traceActionSet contains the list of admin actions required for this endpoint to work
var traceActionSet = ConfigurationActionSet{
actionTypes: iampolicy.NewActionSet(
iampolicy.AllAdminActions,
),
actions: iampolicy.NewActionSet(
iampolicy.TraceAdminAction,
),
}
// endpointRules contains the mapping between endpoints and ActionSets, additional rules can be added here // endpointRules contains the mapping between endpoints and ActionSets, additional rules can be added here
var endpointRules = map[string]ConfigurationActionSet{ var endpointRules = map[string]ConfigurationActionSet{
configuration: configurationActionSet, configuration: configurationActionSet,
@@ -218,6 +262,10 @@ var endpointRules = map[string]ConfigurationActionSet{
mainObjectBrowser: objectBrowserActionSet, mainObjectBrowser: objectBrowserActionSet,
objectBrowserBucket: objectBrowserActionSet, objectBrowserBucket: objectBrowserActionSet,
license: licenseActionSet, license: licenseActionSet,
watch: watchActionSet,
heal: healActionSet,
trace: traceActionSet,
logs: logsActionSet,
} }
// operatorRules contains the mapping between endpoints and ActionSets for operator only mode // operatorRules contains the mapping between endpoints and ActionSets for operator only mode

View File

@@ -72,7 +72,7 @@ func TestGetAuthorizedEndpoints(t *testing.T) {
"admin:*", "admin:*",
}, },
}, },
want: 13, want: 17,
}, },
{ {
name: "all s3 endpoints", name: "all s3 endpoints",
@@ -91,7 +91,7 @@ func TestGetAuthorizedEndpoints(t *testing.T) {
"s3:*", "s3:*",
}, },
}, },
want: 16, want: 20,
}, },
{ {
name: "Console User - default endpoints", name: "Console User - default endpoints",

File diff suppressed because one or more lines are too long

View File

@@ -47,6 +47,10 @@ import TenantDetails from "./Tenants/TenantDetails/TenantDetails";
import ObjectBrowser from "./ObjectBrowser/ObjectBrowser"; import ObjectBrowser from "./ObjectBrowser/ObjectBrowser";
import ObjectRouting from "./Buckets/ListBuckets/Objects/ListObjects/ObjectRouting"; import ObjectRouting from "./Buckets/ListBuckets/Objects/ListObjects/ObjectRouting";
import License from "./License/License"; import License from "./License/License";
import Trace from "./Trace/Trace";
import Logs from "./Logs/Logs";
import Heal from "./Heal/Heal";
import Watch from "./Watch/Watch";
const drawerWidth = 245; const drawerWidth = 245;
@@ -216,6 +220,10 @@ const Console = ({
component: ObjectRouting, component: ObjectRouting,
path: "/object-browser/:bucket/*", path: "/object-browser/:bucket/*",
}, },
{
component: Watch,
path: "/watch",
},
{ {
component: Users, component: Users,
path: "/users", path: "/users",
@@ -228,6 +236,18 @@ const Console = ({
component: Policies, component: Policies,
path: "/policies", path: "/policies",
}, },
{
component: Heal,
path: "/heal",
},
{
component: Trace,
path: "/trace",
},
{
component: Logs,
path: "/logs",
},
{ {
component: ListNotificationEndpoints, component: ListNotificationEndpoints,
path: "/notification-endpoints", path: "/notification-endpoints",

View File

@@ -3,18 +3,19 @@ import React, { useEffect, useState } from "react";
import { Button, Grid, TextField, InputBase } from "@material-ui/core"; import { Button, Grid, TextField, InputBase } from "@material-ui/core";
import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket"; import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket";
import { createStyles, Theme, withStyles } from "@material-ui/core/styles"; import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import { wsProtocol } from "../../../../../utils/wsUtils"; import { wsProtocol } from "../../../utils/wsUtils";
import api from "../../../../../common/api"; import api from "../../../common/api";
import { FormControl, MenuItem, Select } from "@material-ui/core"; import { FormControl, MenuItem, Select } from "@material-ui/core";
import { BucketList, Bucket } from "../Watch/types"; import { BucketList, Bucket } from "../Watch/types";
import { HealStatus, colorH } from "./types"; import { HealStatus, colorH } from "./types";
import { niceBytes } from "../../../../../common/utils"; import { niceBytes } from "../../../common/utils";
import { import {
actionsTray, actionsTray,
containerForHeader, containerForHeader,
searchField, searchField,
} from "../../../Common/FormComponents/common/styleLibrary"; } from "../Common/FormComponents/common/styleLibrary";
import CheckboxWrapper from "../../../Common/FormComponents/CheckboxWrapper/CheckboxWrapper"; import CheckboxWrapper from "../Common/FormComponents/CheckboxWrapper/CheckboxWrapper";
import PageHeader from "../Common/PageHeader/PageHeader";
const styles = (theme: Theme) => const styles = (theme: Theme) =>
createStyles({ createStyles({
@@ -59,8 +60,6 @@ const styles = (theme: Theme) =>
interface IHeal { interface IHeal {
classes: any; classes: any;
namespace: string;
tenant: string;
} }
const SelectStyled = withStyles((theme: Theme) => const SelectStyled = withStyles((theme: Theme) =>
@@ -85,7 +84,7 @@ const SelectStyled = withStyles((theme: Theme) =>
}) })
)(InputBase); )(InputBase);
const Heal = ({ classes, namespace, tenant }: IHeal) => { const Heal = ({ classes }: IHeal) => {
const [start, setStart] = useState(false); const [start, setStart] = useState(false);
const [bucketName, setBucketName] = useState(""); const [bucketName, setBucketName] = useState("");
const [bucketList, setBucketList] = useState<Bucket[]>([]); const [bucketList, setBucketList] = useState<Bucket[]>([]);
@@ -105,7 +104,7 @@ const Heal = ({ classes, namespace, tenant }: IHeal) => {
const fetchBucketList = () => { const fetchBucketList = () => {
api api
.invoke("GET", `/api/v1/operator/${namespace}/${tenant}/buckets`) .invoke("GET", `/api/v1/buckets`)
.then((res: BucketList) => { .then((res: BucketList) => {
let buckets: Bucket[] = []; let buckets: Bucket[] = [];
if (res.buckets !== null) { if (res.buckets !== null) {
@@ -152,7 +151,7 @@ const Heal = ({ classes, namespace, tenant }: IHeal) => {
const wsProt = wsProtocol(url.protocol); const wsProt = wsProtocol(url.protocol);
const c = new W3CWebSocket( const c = new W3CWebSocket(
`${wsProt}://${url.hostname}:${port}/ws/heal/${namespace}/${tenant}/${bucketName}?prefix=${prefix}&recursive=${recursive}&force-start=${forceStart}&force-stop=${forceStop}` `${wsProt}://${url.hostname}:${port}/ws/heal/${bucketName}?prefix=${prefix}&recursive=${recursive}&force-start=${forceStart}&force-stop=${forceStop}`
); );
if (c !== null) { if (c !== null) {
@@ -215,125 +214,130 @@ const Heal = ({ classes, namespace, tenant }: IHeal) => {
value: bucketName.name, value: bucketName.name,
})); }));
return ( return (
<Grid item xs={12}> <React.Fragment>
<Grid item xs={12} className={classes.actionsTray}> <PageHeader label="Heal" />
<FormControl variant="outlined"> <Grid container className={classes.container}>
<Select <Grid item xs={12}>
id="bucket-name" <Grid item xs={12} className={classes.actionsTray}>
name="bucket-name" <FormControl variant="outlined">
value={bucketName} <Select
onChange={(e) => { id="bucket-name"
setBucketName(e.target.value as string); name="bucket-name"
}} value={bucketName}
className={classes.searchField} onChange={(e) => {
input={<SelectStyled />} setBucketName(e.target.value as string);
displayEmpty }}
> className={classes.searchField}
<MenuItem value="" key={`select-bucket-name-default`}> input={<SelectStyled />}
Select Bucket displayEmpty
</MenuItem>
{bucketNames.map((option) => (
<MenuItem
value={option.value}
key={`select-bucket-name-${option.label}`}
> >
{option.label} <MenuItem value="" key={`select-bucket-name-default`}>
</MenuItem> Select Bucket
))} </MenuItem>
</Select> {bucketNames.map((option) => (
</FormControl> <MenuItem
<TextField value={option.value}
placeholder="Prefix" key={`select-bucket-name-${option.label}`}
className={classes.searchField} >
id="prefix-resource" {option.label}
label="" </MenuItem>
disabled={false} ))}
InputProps={{ </Select>
disableUnderline: true, </FormControl>
}} <TextField
onChange={(e) => { placeholder="Prefix"
setPrefix(e.target.value); className={classes.searchField}
}} id="prefix-resource"
/> label=""
<Button disabled={false}
type="submit" InputProps={{
variant="contained" disableUnderline: true,
color="primary" }}
disabled={start} onChange={(e) => {
onClick={() => setStart(true)} setPrefix(e.target.value);
> }}
Start />
</Button> <Button
</Grid> type="submit"
<Grid item xs={12} className={classes.inlineCheckboxes}> variant="contained"
<CheckboxWrapper color="primary"
name="recursive" disabled={start}
id="recursive" onClick={() => setStart(true)}
value="recursive" >
checked={recursive} Start
onChange={(e) => { </Button>
setRecursive(e.target.checked); </Grid>
}} <Grid item xs={12} className={classes.inlineCheckboxes}>
disabled={false} <CheckboxWrapper
label="Recursive" name="recursive"
/> id="recursive"
<CheckboxWrapper value="recursive"
name="forceStart" checked={recursive}
id="forceStart" onChange={(e) => {
value="forceStart" setRecursive(e.target.checked);
checked={forceStart} }}
onChange={(e) => { disabled={false}
setForceStart(e.target.checked); label="Recursive"
}} />
disabled={false} <CheckboxWrapper
label="Force Start" name="forceStart"
/> id="forceStart"
<CheckboxWrapper value="forceStart"
name="forceStop" checked={forceStart}
id="forceStop" onChange={(e) => {
value="forceStop" setForceStart(e.target.checked);
checked={forceStop} }}
onChange={(e) => { disabled={false}
setForceStop(e.target.checked); label="Force Start"
}} />
disabled={false} <CheckboxWrapper
label="Force Stop" name="forceStop"
/> id="forceStop"
</Grid> value="forceStop"
<Grid item xs={12}> checked={forceStop}
<br /> onChange={(e) => {
</Grid> setForceStop(e.target.checked);
<Grid item xs={12} className={classes.graphContainer}> }}
<HorizontalBar disabled={false}
data={data} label="Force Stop"
width={80} />
height={30} </Grid>
options={{ <Grid item xs={12}>
title: { <br />
display: true, </Grid>
text: "Item's Health Status [%]", <Grid item xs={12} className={classes.graphContainer}>
fontSize: 20, <HorizontalBar
}, data={data}
legend: { width={80}
display: true, height={30}
position: "right", options={{
}, title: {
}} display: true,
/> text: "Item's Health Status [%]",
<Grid item xs={12} className={classes.scanInfo}> fontSize: 20,
<div className={classes.scanData}> },
<strong>Size scanned:</strong> {hStatus.sizeScanned} legend: {
</div> display: true,
<div className={classes.scanData}> position: "right",
<strong>Objects healed:</strong> {hStatus.objectsHealed} /{" "} },
{hStatus.objectsScanned} }}
</div> />
<div className={classes.scanData}> <Grid item xs={12} className={classes.scanInfo}>
<strong>Healing time:</strong> {hStatus.healDuration}s <div className={classes.scanData}>
</div> <strong>Size scanned:</strong> {hStatus.sizeScanned}
</div>
<div className={classes.scanData}>
<strong>Objects healed:</strong> {hStatus.objectsHealed} /{" "}
{hStatus.objectsScanned}
</div>
<div className={classes.scanData}>
<strong>Healing time:</strong> {hStatus.healDuration}s
</div>
</Grid>
</Grid>
</Grid> </Grid>
</Grid> </Grid>
</Grid> </React.Fragment>
); );
}; };

View File

@@ -15,22 +15,23 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket"; import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket";
import { AppState } from "../../../../../store"; import { AppState } from "../../../store";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { logMessageReceived, logResetMessages } from "./actions"; import { logMessageReceived, logResetMessages } from "./actions";
import { LogMessage } from "./types"; import { LogMessage } from "./types";
import { createStyles, Theme, withStyles } from "@material-ui/core/styles"; import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import { timeFromDate } from "../../../../../common/utils"; import { timeFromDate } from "../../../common/utils";
import { wsProtocol } from "../../../../../utils/wsUtils"; import { wsProtocol } from "../../../utils/wsUtils";
import { import {
actionsTray, actionsTray,
containerForHeader, containerForHeader,
searchField, searchField,
} from "../../../Common/FormComponents/common/styleLibrary"; } from "../Common/FormComponents/common/styleLibrary";
import { Grid } from "@material-ui/core"; import { Grid } from "@material-ui/core";
import TextField from "@material-ui/core/TextField"; import TextField from "@material-ui/core/TextField";
import InputAdornment from "@material-ui/core/InputAdornment"; import InputAdornment from "@material-ui/core/InputAdornment";
import SearchIcon from "@material-ui/icons/Search"; import SearchIcon from "@material-ui/icons/Search";
import PageHeader from "../Common/PageHeader/PageHeader";
const styles = (theme: Theme) => const styles = (theme: Theme) =>
createStyles({ createStyles({
@@ -81,8 +82,6 @@ const Logs = ({
logMessageReceived, logMessageReceived,
logResetMessages, logResetMessages,
messages, messages,
namespace,
tenant,
}: ILogs) => { }: ILogs) => {
const [highlight, setHighlight] = useState(""); const [highlight, setHighlight] = useState("");
@@ -95,7 +94,7 @@ const Logs = ({
const wsProt = wsProtocol(url.protocol); const wsProt = wsProtocol(url.protocol);
const c = new W3CWebSocket( const c = new W3CWebSocket(
`${wsProt}://${url.hostname}:${port}/ws/console/${namespace}/${tenant}` `${wsProt}://${url.hostname}:${port}/ws/console`
); );
let interval: any | null = null; let interval: any | null = null;
@@ -324,33 +323,38 @@ const Logs = ({
}); });
return ( return (
<Grid item xs={12}> <React.Fragment>
<Grid item xs={12} className={classes.actionsTray}> <PageHeader label="Logs" />
<TextField <Grid container>
placeholder="Highlight Line" <Grid item xs={12} className={classes.container}>
className={classes.searchField} <Grid item xs={12} className={classes.actionsTray}>
id="search-resource" <TextField
label="" placeholder="Highlight Line"
onChange={(val) => { className={classes.searchField}
setHighlight(val.target.value); id="search-resource"
}} label=""
InputProps={{ onChange={(val) => {
disableUnderline: true, setHighlight(val.target.value);
startAdornment: ( }}
<InputAdornment position="start"> InputProps={{
<SearchIcon /> disableUnderline: true,
</InputAdornment> startAdornment: (
), <InputAdornment position="start">
}} <SearchIcon />
/> </InputAdornment>
),
}}
/>
</Grid>
<Grid item xs={12}>
<br />
</Grid>
<Grid item xs={12}>
<div className={classes.logList}>{renderLines}</div>
</Grid>
</Grid>
</Grid> </Grid>
<Grid item xs={12}> </React.Fragment>
<br />
</Grid>
<Grid item xs={12}>
<div className={classes.logList}>{renderLines}</div>
</Grid>
</Grid>
); );
}; };

View File

@@ -44,10 +44,14 @@ import {
ServiceAccountsIcon, ServiceAccountsIcon,
UsersIcon, UsersIcon,
WarpIcon, WarpIcon,
TraceIcon,
} from "../../../icons"; } from "../../../icons";
import { clearSession } from "../../../common/utils"; import { clearSession } from "../../../common/utils";
import LicenseIcon from "../../../icons/LicenseIcon"; import LicenseIcon from "../../../icons/LicenseIcon";
import LogoutIcon from "../../../icons/LogoutIcon"; import LogoutIcon from "../../../icons/LogoutIcon";
import ConsoleIcon from "../../../icons/ConsoleIcon";
import HealIcon from "../../../icons/HealIcon";
import WatchIcon from "../../../icons/WatchIcon";
const styles = (theme: Theme) => const styles = (theme: Theme) =>
createStyles({ createStyles({
@@ -238,6 +242,38 @@ const Menu = ({ userLoggedIn, classes, pages }: IMenuProps) => {
name: "IAM Policies", name: "IAM Policies",
icon: <IAMPoliciesIcon />, icon: <IAMPoliciesIcon />,
}, },
{
group: "Tools",
type: "item",
component: NavLink,
to: "/logs",
name: "Logs",
icon: <ConsoleIcon />,
},
{
group: "Tools",
type: "item",
component: NavLink,
to: "/watch",
name: "Watch",
icon: <WatchIcon />,
},
{
group: "Tools",
type: "item",
component: NavLink,
to: "/trace",
name: "Trace",
icon: <TraceIcon />,
},
{
group: "Tools",
type: "item",
component: NavLink,
to: "/heal",
name: "Heal",
icon: <HealIcon />,
},
{ {
group: "Admin", group: "Admin",
type: "item", type: "item",

View File

@@ -18,6 +18,7 @@ export const menuGroups = [
{ label: "", group: "common", collapsible: false }, { label: "", group: "common", collapsible: false },
{ label: "User", group: "User", collapsible: true }, { label: "User", group: "User", collapsible: true },
{ label: "Admin", group: "Admin", collapsible: true }, { label: "Admin", group: "Admin", collapsible: true },
{ label: "Tools", group: "Tools", collapsible: true },
{ label: "Operator", group: "Operator", collapsible: true }, { label: "Operator", group: "Operator", collapsible: true },
{ label: "", group: "License", collapsible: false }, { label: "", group: "License", collapsible: false },
]; ];

View File

@@ -34,14 +34,9 @@ import AddBucket from "../../Buckets/ListBuckets/AddBucket";
import ReplicationSetup from "./ReplicationSetup"; import ReplicationSetup from "./ReplicationSetup";
import api from "../../../../common/api"; import api from "../../../../common/api";
import { ITenant, IPool } from "../ListTenants/types"; import { ITenant, IPool } from "../ListTenants/types";
import Logs from "./Logs/Logs";
import Trace from "./Trace/Trace";
import Watch from "./Watch/Watch";
import Heal from "./Heal/Heal";
import PageHeader from "../../Common/PageHeader/PageHeader"; import PageHeader from "../../Common/PageHeader/PageHeader";
import UsageBarWrapper from "../../Common/UsageBarWrapper/UsageBarWrapper"; import UsageBarWrapper from "../../Common/UsageBarWrapper/UsageBarWrapper";
import UpdateTenantModal from "./UpdateTenantModal"; import UpdateTenantModal from "./UpdateTenantModal";
import EditIcon from "@material-ui/icons/Edit";
import PencilIcon from "../../Common/TableWrapper/TableActionIcons/PencilIcon"; import PencilIcon from "../../Common/TableWrapper/TableActionIcons/PencilIcon";
interface ITenantDetailsProps { interface ITenantDetailsProps {
@@ -306,7 +301,7 @@ const TenantDetails = ({ classes, match }: ITenantDetailsProps) => {
<Grid item xs={12}> <Grid item xs={12}>
<br /> <br />
</Grid> </Grid>
<Grid item xs={7}> <Grid item xs={6}>
<Tabs <Tabs
value={selectedTab} value={selectedTab}
indicatorColor="primary" indicatorColor="primary"
@@ -317,13 +312,9 @@ const TenantDetails = ({ classes, match }: ITenantDetailsProps) => {
aria-label="tenant-tabs" aria-label="tenant-tabs"
> >
<Tab label="Clusters" /> <Tab label="Clusters" />
<Tab label="Logs" />
<Tab label="Trace" />
<Tab label="Watch" />
<Tab label="Heal" />
</Tabs> </Tabs>
</Grid> </Grid>
<Grid item xs={5} className={classes.actionsTray}> <Grid item xs={6} className={classes.actionsTray}>
<Button <Button
variant="contained" variant="contained"
color="primary" color="primary"
@@ -363,18 +354,6 @@ const TenantDetails = ({ classes, match }: ITenantDetailsProps) => {
/> />
)} )}
</Grid> </Grid>
{selectedTab === 1 && tenant !== null && (
<Logs namespace={tenant.namespace} tenant={tenant.name} />
)}
{selectedTab === 2 && tenant !== null && (
<Trace namespace={tenant.namespace} tenant={tenant.name} />
)}
{selectedTab === 3 && tenant !== null && (
<Watch namespace={tenant.namespace} tenant={tenant.name} />
)}
{selectedTab === 4 && tenant !== null && (
<Heal namespace={tenant.namespace} tenant={tenant.name} />
)}
</Grid> </Grid>
</React.Fragment> </React.Fragment>
); );

View File

@@ -16,16 +16,17 @@
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket"; import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket";
import { AppState } from "../../../../../store"; import { AppState } from "../../../store";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { traceMessageReceived, traceResetMessages } from "./actions"; import { traceMessageReceived, traceResetMessages } from "./actions";
import { TraceMessage } from "./types"; import { TraceMessage } from "./types";
import { createStyles, Theme, withStyles } from "@material-ui/core/styles"; import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import { niceBytes, timeFromDate } from "../../../../../common/utils"; import { niceBytes, timeFromDate } from "../../../common/utils";
import { wsProtocol } from "../../../../../utils/wsUtils"; import { wsProtocol } from "../../../utils/wsUtils";
import { containerForHeader } from "../../../Common/FormComponents/common/styleLibrary"; import { containerForHeader } from "../Common/FormComponents/common/styleLibrary";
import { Grid } from "@material-ui/core"; import { Grid } from "@material-ui/core";
import TableWrapper from "../../../Common/TableWrapper/TableWrapper"; import TableWrapper from "../Common/TableWrapper/TableWrapper";
import PageHeader from "../Common/PageHeader/PageHeader";
const styles = (theme: Theme) => const styles = (theme: Theme) =>
createStyles({ createStyles({
@@ -67,8 +68,6 @@ const Trace = ({
traceMessageReceived, traceMessageReceived,
traceResetMessages, traceResetMessages,
messages, messages,
namespace,
tenant,
}: ITrace) => { }: ITrace) => {
useEffect(() => { useEffect(() => {
traceResetMessages(); traceResetMessages();
@@ -77,9 +76,7 @@ const Trace = ({
const port = isDev ? "9090" : url.port; const port = isDev ? "9090" : url.port;
const wsProt = wsProtocol(url.protocol); const wsProt = wsProtocol(url.protocol);
const c = new W3CWebSocket( const c = new W3CWebSocket(`${wsProt}://${url.hostname}:${port}/ws/trace`);
`${wsProt}://${url.hostname}:${port}/ws/trace/${namespace}/${tenant}`
);
let interval: any | null = null; let interval: any | null = null;
if (c !== null) { if (c !== null) {
@@ -109,59 +106,64 @@ const Trace = ({
}, [traceMessageReceived, traceResetMessages]); }, [traceMessageReceived, traceResetMessages]);
return ( return (
<Grid item xs={12}> <React.Fragment>
<TableWrapper <PageHeader label={"Trace"} />
itemActions={[]} <Grid container>
columns={[ <Grid item xs={12} className={classes.container}>
{ <TableWrapper
label: "Time", itemActions={[]}
elementKey: "time", columns={[
renderFunction: (time: Date) => { {
const timeParse = new Date(time); label: "Time",
return timeFromDate(timeParse); elementKey: "time",
}, renderFunction: (time: Date) => {
globalClass: classes.timeItem, const timeParse = new Date(time);
}, return timeFromDate(timeParse);
{ label: "Name", elementKey: "api" }, },
{ globalClass: classes.timeItem,
label: "Status", },
elementKey: "", { label: "Name", elementKey: "api" },
renderFunction: (fullElement: TraceMessage) => {
`${fullElement.statusCode} ${fullElement.statusMsg}`, label: "Status",
renderFullObject: true, elementKey: "",
}, renderFunction: (fullElement: TraceMessage) =>
{ `${fullElement.statusCode} ${fullElement.statusMsg}`,
label: "Location", renderFullObject: true,
elementKey: "configuration_id", },
renderFunction: (fullElement: TraceMessage) => {
`${fullElement.host} ${fullElement.client}`, label: "Location",
renderFullObject: true, elementKey: "configuration_id",
}, renderFunction: (fullElement: TraceMessage) =>
{ `${fullElement.host} ${fullElement.client}`,
label: "Load Time", renderFullObject: true,
elementKey: "callStats.duration", },
globalClass: classes.timeItem, {
}, label: "Load Time",
{ elementKey: "callStats.duration",
label: "Upload", globalClass: classes.timeItem,
elementKey: "callStats.rx", },
renderFunction: niceBytes, {
globalClass: classes.sizeItem, label: "Upload",
}, elementKey: "callStats.rx",
{ renderFunction: niceBytes,
label: "Download", globalClass: classes.sizeItem,
elementKey: "callStats.tx", },
renderFunction: niceBytes, {
globalClass: classes.sizeItem, label: "Download",
}, elementKey: "callStats.tx",
]} renderFunction: niceBytes,
isLoading={false} globalClass: classes.sizeItem,
records={messages} },
entityName="Traces" ]}
idField="api" isLoading={false}
customEmptyMessage="There are no traced Elements yet" records={messages}
/> entityName="Traces"
</Grid> idField="api"
customEmptyMessage="There are no traced Elements yet"
/>
</Grid>
</Grid>
</React.Fragment>
); );
}; };

View File

@@ -16,21 +16,22 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Button, Grid, TextField, InputBase } from "@material-ui/core"; import { Button, Grid, TextField, InputBase } from "@material-ui/core";
import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket"; import { IMessageEvent, w3cwebsocket as W3CWebSocket } from "websocket";
import { AppState } from "../../../../../store"; import { AppState } from "../../../store";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { watchMessageReceived, watchResetMessages } from "./actions"; import { watchMessageReceived, watchResetMessages } from "./actions";
import { EventInfo, BucketList, Bucket } from "./types"; import { EventInfo, BucketList, Bucket } from "./types";
import { createStyles, Theme, withStyles } from "@material-ui/core/styles"; import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import { niceBytes, timeFromDate } from "../../../../../common/utils"; import { niceBytes, timeFromDate } from "../../../common/utils";
import { wsProtocol } from "../../../../../utils/wsUtils"; import { wsProtocol } from "../../../utils/wsUtils";
import api from "../../../../../common/api"; import api from "../../../common/api";
import { FormControl, MenuItem, Select } from "@material-ui/core"; import { FormControl, MenuItem, Select } from "@material-ui/core";
import { import {
actionsTray, actionsTray,
containerForHeader, containerForHeader,
searchField, searchField,
} from "../../../Common/FormComponents/common/styleLibrary"; } from "../Common/FormComponents/common/styleLibrary";
import TableWrapper from "../../../Common/TableWrapper/TableWrapper"; import TableWrapper from "../Common/TableWrapper/TableWrapper";
import PageHeader from "../Common/PageHeader/PageHeader";
const styles = (theme: Theme) => const styles = (theme: Theme) =>
createStyles({ createStyles({
@@ -84,8 +85,6 @@ interface IWatch {
watchMessageReceived: typeof watchMessageReceived; watchMessageReceived: typeof watchMessageReceived;
watchResetMessages: typeof watchResetMessages; watchResetMessages: typeof watchResetMessages;
messages: EventInfo[]; messages: EventInfo[];
namespace: string;
tenant: string;
} }
const Watch = ({ const Watch = ({
@@ -93,8 +92,6 @@ const Watch = ({
watchMessageReceived, watchMessageReceived,
watchResetMessages, watchResetMessages,
messages, messages,
namespace,
tenant,
}: IWatch) => { }: IWatch) => {
const [start, setStart] = useState(false); const [start, setStart] = useState(false);
const [bucketName, setBucketName] = useState("Select Bucket"); const [bucketName, setBucketName] = useState("Select Bucket");
@@ -104,7 +101,7 @@ const Watch = ({
const fetchBucketList = () => { const fetchBucketList = () => {
api api
.invoke("GET", `/api/v1/operator/${namespace}/${tenant}/buckets`) .invoke("GET", `/api/v1/buckets`)
.then((res: BucketList) => { .then((res: BucketList) => {
let buckets: Bucket[] = []; let buckets: Bucket[] = [];
if (res.buckets !== null) { if (res.buckets !== null) {
@@ -130,7 +127,7 @@ const Watch = ({
const wsProt = wsProtocol(url.protocol); const wsProt = wsProtocol(url.protocol);
const c = new W3CWebSocket( const c = new W3CWebSocket(
`${wsProt}://${url.hostname}:${port}/ws/watch/${namespace}/${tenant}/${bucketName}?prefix=${prefix}&suffix=${suffix}` `${wsProt}://${url.hostname}:${port}/ws/watch/${bucketName}?prefix=${prefix}&suffix=${suffix}`
); );
let interval: any | null = null; let interval: any | null = null;
@@ -181,98 +178,103 @@ const Watch = ({
})); }));
return ( return (
<Grid item xs={12}> <React.Fragment>
<Grid item xs={12} className={classes.actionsTray}> <PageHeader label="Watch" />
<FormControl variant="outlined"> <Grid container>
<Select <Grid item xs={12} className={classes.container}>
id="bucket-name" <Grid item xs={12} className={classes.actionsTray}>
name="bucket-name" <FormControl variant="outlined">
value={bucketName} <Select
onChange={(e) => { id="bucket-name"
setBucketName(e.target.value as string); name="bucket-name"
}} value={bucketName}
className={classes.searchField} onChange={(e) => {
disabled={start} setBucketName(e.target.value as string);
input={<SelectStyled />} }}
> className={classes.searchField}
<MenuItem disabled={start}
value={bucketName} input={<SelectStyled />}
key={`select-bucket-name-default`}
disabled={true}
>
Select Bucket
</MenuItem>
{bucketNames.map((option) => (
<MenuItem
value={option.value}
key={`select-bucket-name-${option.label}`}
> >
{option.label} <MenuItem
</MenuItem> value={bucketName}
))} key={`select-bucket-name-default`}
</Select> disabled={true}
</FormControl> >
<TextField Select Bucket
placeholder="Prefix" </MenuItem>
className={`${classes.searchField} ${classes.searchPrefix}`} {bucketNames.map((option) => (
id="prefix-resource" <MenuItem
label="" value={option.value}
disabled={start} key={`select-bucket-name-${option.label}`}
InputProps={{ >
disableUnderline: true, {option.label}
}} </MenuItem>
onChange={(e) => { ))}
setPrefix(e.target.value); </Select>
}} </FormControl>
/> <TextField
<TextField placeholder="Prefix"
placeholder="Suffix" className={`${classes.searchField} ${classes.searchPrefix}`}
className={`${classes.searchField} ${classes.searchPrefix}`} id="prefix-resource"
id="suffix-resource" label=""
label="" disabled={start}
disabled={start} InputProps={{
InputProps={{ disableUnderline: true,
disableUnderline: true, }}
}} onChange={(e) => {
onChange={(e) => { setPrefix(e.target.value);
setSuffix(e.target.value); }}
}} />
/> <TextField
<Button placeholder="Suffix"
type="submit" className={`${classes.searchField} ${classes.searchPrefix}`}
variant="contained" id="suffix-resource"
color="primary" label=""
disabled={start} disabled={start}
onClick={() => setStart(true)} InputProps={{
> disableUnderline: true,
Start }}
</Button> onChange={(e) => {
setSuffix(e.target.value);
}}
/>
<Button
type="submit"
variant="contained"
color="primary"
disabled={start}
onClick={() => setStart(true)}
>
Start
</Button>
</Grid>
<Grid item xs={12}>
<br />
</Grid>
<TableWrapper
columns={[
{
label: "Time",
elementKey: "Time",
renderFunction: timeFromDate,
},
{
label: "Size",
elementKey: "Size",
renderFunction: niceBytes,
},
{ label: "Type", elementKey: "Type" },
{ label: "Path", elementKey: "Path" },
]}
records={messages}
entityName={"Watch"}
customEmptyMessage={"No Changes at this time"}
idField={"watch_table"}
isLoading={false}
/>
</Grid>
</Grid> </Grid>
<Grid item xs={12}> </React.Fragment>
<br />
</Grid>
<TableWrapper
columns={[
{
label: "Time",
elementKey: "Time",
renderFunction: timeFromDate,
},
{
label: "Size",
elementKey: "Size",
renderFunction: niceBytes,
},
{ label: "Type", elementKey: "Type" },
{ label: "Path", elementKey: "Path" },
]}
records={messages}
entityName={"Watch"}
customEmptyMessage={"No Changes at this time"}
idField={"watch_table"}
isLoading={false}
/>
</Grid>
); );
}; };

View File

@@ -17,9 +17,9 @@
import { applyMiddleware, combineReducers, compose, createStore } from "redux"; import { applyMiddleware, combineReducers, compose, createStore } from "redux";
import thunk from "redux-thunk"; import thunk from "redux-thunk";
import { systemReducer } from "./reducer"; import { systemReducer } from "./reducer";
import { traceReducer } from "./screens/Console/Tenants/TenantDetails/Trace/reducers"; import { traceReducer } from "./screens/Console/Trace/reducers";
import { logReducer } from "./screens/Console/Tenants/TenantDetails/Logs/reducers"; import { logReducer } from "./screens/Console/Logs/reducers";
import { watchReducer } from "./screens/Console/Tenants/TenantDetails/Watch/reducers"; import { watchReducer } from "./screens/Console/Watch/reducers";
import { consoleReducer } from "./screens/Console/reducer"; import { consoleReducer } from "./screens/Console/reducer";
import { bucketsReducer } from "./screens/Console/Buckets/reducers"; import { bucketsReducer } from "./screens/Console/Buckets/reducers";
import { objectBrowserReducer } from "./screens/Console/ObjectBrowser/reducers"; import { objectBrowserReducer } from "./screens/Console/ObjectBrowser/reducers";

View File

@@ -21,8 +21,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"net/http"
"regexp"
"strings" "strings"
"time" "time"
@@ -95,29 +93,3 @@ func getLogTime(lt string) string {
} }
return tm.Format(logTimeFormat) return tm.Format(logTimeFormat)
} }
// getConsoleLogOptionsFromReq return tenant name from url
// path come as : `/console/<namespace>/<tenantName>`
func getConsoleLogOptionsFromReq(req *http.Request) (namespace, tenant string, err error) {
re := regexp.MustCompile(`(/console/)(.*?)/(.*?)(\?.*?$|$)`)
matches := re.FindAllSubmatch([]byte(req.URL.Path), -1)
if len(matches) == 0 || len(matches[0]) < 4 {
return "", "", fmt.Errorf("invalid url: %s", req.URL.Path)
}
namespace = strings.TrimSpace(string(matches[0][2]))
tenant = strings.TrimSpace(string(matches[0][3]))
return namespace, tenant, nil
}
// getTraceOptionsFromReq return tenant name from url
// path come as : `/trace/<namespace>/<tenantName>`
func getTraceOptionsFromReq(req *http.Request) (namespace, tenant string, err error) {
re := regexp.MustCompile(`(/trace/)(.*?)/(.*?)(\?.*?$|$)`)
matches := re.FindAllSubmatch([]byte(req.URL.Path), -1)
if len(matches) == 0 || len(matches[0]) < 4 {
return "", "", fmt.Errorf("invalid url: %s", req.URL.Path)
}
namespace = strings.TrimSpace(string(matches[0][2]))
tenant = strings.TrimSpace(string(matches[0][3]))
return namespace, tenant, nil
}

View File

@@ -103,8 +103,6 @@ type healStatus struct {
} }
type healOptions struct { type healOptions struct {
Namespace string
Tenant string
BucketName string BucketName string
Prefix string Prefix string
ForceStart bool ForceStart bool
@@ -319,18 +317,16 @@ func getHRITypeAndName(i madmin.HealResultItem) (typ, name string) {
// and query params come on request form // and query params come on request form
func getHealOptionsFromReq(req *http.Request) (*healOptions, error) { func getHealOptionsFromReq(req *http.Request) (*healOptions, error) {
hOptions := healOptions{} hOptions := healOptions{}
re := regexp.MustCompile(`(/heal/)(.*?)/(.*?)/(.*?)(\?.*?$|$)`) re := regexp.MustCompile(`(/heal/)(.*?)(\?.*?$|$)`)
matches := re.FindAllSubmatch([]byte(req.URL.Path), -1) matches := re.FindAllSubmatch([]byte(req.URL.Path), -1)
// matches comes as e.g. // matches comes as e.g.
// [["...", "/heal/", "namespace", "tenant", "bucket1"]] // [["...", "/heal/", "bucket1"]]
// [["/heal/" "/heal/" ""]] // [["/heal/" "/heal/" ""]]
if len(matches) == 0 || len(matches[0]) < 5 { if len(matches) == 0 || len(matches[0]) < 3 {
return nil, fmt.Errorf("invalid url: %s", req.URL.Path) return nil, fmt.Errorf("invalid url: %s", req.URL.Path)
} }
hOptions.Namespace = strings.TrimSpace(string(matches[0][2])) hOptions.BucketName = strings.TrimSpace(string(matches[0][2]))
hOptions.Tenant = strings.TrimSpace(string(matches[0][3]))
hOptions.BucketName = strings.TrimSpace(string(matches[0][4]))
hOptions.Prefix = req.FormValue("prefix") hOptions.Prefix = req.FormValue("prefix")
hOptions.HealOpts.ScanMode = transformScanStr(req.FormValue("scan")) hOptions.HealOpts.ScanMode = transformScanStr(req.FormValue("scan"))

View File

@@ -205,7 +205,7 @@ func TestHeal(t *testing.T) {
} }
// Test-3: getHealOptionsFromReq return heal options from request // Test-3: getHealOptionsFromReq return heal options from request
u, _ := url.Parse("http://localhost/api/v1/heal/namespace/tenantName/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=true&remove=true&dry-run=true&scan=deep") u, _ := url.Parse("http://localhost/api/v1/heal/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=true&remove=true&dry-run=true&scan=deep")
req := &http.Request{ req := &http.Request{
URL: u, URL: u,
} }
@@ -231,7 +231,7 @@ func TestHeal(t *testing.T) {
} }
// Test-4: getHealOptionsFromReq return error if boolean value not valid // Test-4: getHealOptionsFromReq return error if boolean value not valid
u, _ = url.Parse("http://localhost/api/v1/heal/namespace/tenantName/bucket1?prefix=file/&recursive=nonbool&force-start=true&force-stop=true&remove=true&dry-run=true&scan=deep") u, _ = url.Parse("http://localhost/api/v1/heal/bucket1?prefix=file/&recursive=nonbool&force-start=true&force-stop=true&remove=true&dry-run=true&scan=deep")
req = &http.Request{ req = &http.Request{
URL: u, URL: u,
} }
@@ -240,7 +240,7 @@ func TestHeal(t *testing.T) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error()) assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
} }
// Test-5: getHealOptionsFromReq return error if boolean value not valid // Test-5: getHealOptionsFromReq return error if boolean value not valid
u, _ = url.Parse("http://localhost/api/v1/heal/namespace/tenantName/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=true&remove=nonbool&dry-run=true&scan=deep") u, _ = url.Parse("http://localhost/api/v1/heal/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=true&remove=nonbool&dry-run=true&scan=deep")
req = &http.Request{ req = &http.Request{
URL: u, URL: u,
} }
@@ -249,7 +249,7 @@ func TestHeal(t *testing.T) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error()) assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
} }
// Test-6: getHealOptionsFromReq return error if boolean value not valid // Test-6: getHealOptionsFromReq return error if boolean value not valid
u, _ = url.Parse("http://localhost/api/v1/heal/namespace/tenantName/bucket1?prefix=file/&recursive=true&force-start=nonbool&force-stop=true&remove=true&dry-run=true&scan=deep") u, _ = url.Parse("http://localhost/api/v1/heal/bucket1?prefix=file/&recursive=true&force-start=nonbool&force-stop=true&remove=true&dry-run=true&scan=deep")
req = &http.Request{ req = &http.Request{
URL: u, URL: u,
} }
@@ -258,7 +258,7 @@ func TestHeal(t *testing.T) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error()) assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
} }
// Test-7: getHealOptionsFromReq return error if boolean value not valid // Test-7: getHealOptionsFromReq return error if boolean value not valid
u, _ = url.Parse("http://localhost/api/v1/heal/namespace/tenantName/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=nonbool&remove=true&dry-run=true&scan=deep") u, _ = url.Parse("http://localhost/api/v1/heal/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=nonbool&remove=true&dry-run=true&scan=deep")
req = &http.Request{ req = &http.Request{
URL: u, URL: u,
} }
@@ -267,7 +267,7 @@ func TestHeal(t *testing.T) {
assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error()) assert.Equal("strconv.ParseBool: parsing \"nonbool\": invalid syntax", err.Error())
} }
// Test-8: getHealOptionsFromReq return error if boolean value not valid // Test-8: getHealOptionsFromReq return error if boolean value not valid
u, _ = url.Parse("http://localhost/api/v1/heal/namespace/tenantName/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=true&remove=true&dry-run=nonbool&scan=deep") u, _ = url.Parse("http://localhost/api/v1/heal/bucket1?prefix=file/&recursive=true&force-start=true&force-stop=true&remove=true&dry-run=nonbool&scan=deep")
req = &http.Request{ req = &http.Request{
URL: u, URL: u,
} }

View File

@@ -387,29 +387,6 @@ func newS3BucketClient(claims *models.Principal, bucketName string, prefix strin
return s3Client, nil return s3Client, nil
} }
// newTenantS3BucketClient creates a new mc S3Client for an specific tenant on a namespace to talk to the server based on a bucket
func newTenantS3BucketClient(claims *models.Principal, tenantEndpoint, bucketName string) (*mc.S3Client, error) {
if strings.TrimSpace(bucketName) != "" {
tenantEndpoint += fmt.Sprintf("/%s", bucketName)
}
if claims == nil {
return nil, fmt.Errorf("the provided credentials are invalid")
}
s3Config := newS3Config(tenantEndpoint, claims.STSAccessKeyID, claims.STSSecretAccessKey, claims.STSSessionToken, false)
client, pErr := mc.S3New(s3Config)
if pErr != nil {
return nil, pErr.Cause
}
s3Client, ok := client.(*mc.S3Client)
if !ok {
return nil, fmt.Errorf("the provided url doesn't point to a S3 server")
}
return s3Client, nil
}
// newS3Config simply creates a new Config struct using the passed // newS3Config simply creates a new Config struct using the passed
// parameters. // parameters.
func newS3Config(endpoint, accessKey, secretKey, sessionToken string, insecure bool) *mc.Config { func newS3Config(endpoint, accessKey, secretKey, sessionToken string, insecure bool) *mc.Config {

View File

@@ -135,8 +135,6 @@ func configureAPI(api *operations.ConsoleAPI) http.Handler {
registerObjectsHandlers(api) registerObjectsHandlers(api)
// Register Bucket Quota's Handlers // Register Bucket Quota's Handlers
registerBucketQuotaHandlers(api) registerBucketQuotaHandlers(api)
// List buckets
registerOperatorBucketsHandlers(api)
// Register Account handlers // Register Account handlers
registerAccountHandlers(api) registerAccountHandlers(api)

View File

@@ -2088,43 +2088,6 @@ func init() {
} }
} }
}, },
"/operator/{namespace}/{tenant}/buckets": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "List Buckets for Operator Console",
"operationId": "OperatorListBuckets",
"parameters": [
{
"type": "string",
"name": "namespace",
"in": "path",
"required": true
},
{
"type": "string",
"name": "tenant",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/listBucketsResponse"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/policies": { "/policies": {
"get": { "get": {
"tags": [ "tags": [
@@ -7202,43 +7165,6 @@ func init() {
} }
} }
}, },
"/operator/{namespace}/{tenant}/buckets": {
"get": {
"tags": [
"OperatorAPI"
],
"summary": "List Buckets for Operator Console",
"operationId": "OperatorListBuckets",
"parameters": [
{
"type": "string",
"name": "namespace",
"in": "path",
"required": true
},
{
"type": "string",
"name": "tenant",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/listBucketsResponse"
}
},
"default": {
"description": "Generic error response.",
"schema": {
"$ref": "#/definitions/error"
}
}
}
}
},
"/policies": { "/policies": {
"get": { "get": {
"tags": [ "tags": [

View File

@@ -38,7 +38,6 @@ import (
"github.com/minio/console/models" "github.com/minio/console/models"
"github.com/minio/console/restapi/operations/admin_api" "github.com/minio/console/restapi/operations/admin_api"
"github.com/minio/console/restapi/operations/operator_api"
"github.com/minio/console/restapi/operations/user_api" "github.com/minio/console/restapi/operations/user_api"
) )
@@ -227,9 +226,6 @@ func NewConsoleAPI(spec *loads.Document) *ConsoleAPI {
AdminAPINotificationEndpointListHandler: admin_api.NotificationEndpointListHandlerFunc(func(params admin_api.NotificationEndpointListParams, principal *models.Principal) middleware.Responder { AdminAPINotificationEndpointListHandler: admin_api.NotificationEndpointListHandlerFunc(func(params admin_api.NotificationEndpointListParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.NotificationEndpointList has not yet been implemented") return middleware.NotImplemented("operation admin_api.NotificationEndpointList has not yet been implemented")
}), }),
OperatorAPIOperatorListBucketsHandler: operator_api.OperatorListBucketsHandlerFunc(func(params operator_api.OperatorListBucketsParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation operator_api.OperatorListBuckets has not yet been implemented")
}),
AdminAPIPolicyInfoHandler: admin_api.PolicyInfoHandlerFunc(func(params admin_api.PolicyInfoParams, principal *models.Principal) middleware.Responder { AdminAPIPolicyInfoHandler: admin_api.PolicyInfoHandlerFunc(func(params admin_api.PolicyInfoParams, principal *models.Principal) middleware.Responder {
return middleware.NotImplemented("operation admin_api.PolicyInfo has not yet been implemented") return middleware.NotImplemented("operation admin_api.PolicyInfo has not yet been implemented")
}), }),
@@ -477,8 +473,6 @@ type ConsoleAPI struct {
UserAPIMakeBucketHandler user_api.MakeBucketHandler UserAPIMakeBucketHandler user_api.MakeBucketHandler
// AdminAPINotificationEndpointListHandler sets the operation handler for the notification endpoint list operation // AdminAPINotificationEndpointListHandler sets the operation handler for the notification endpoint list operation
AdminAPINotificationEndpointListHandler admin_api.NotificationEndpointListHandler AdminAPINotificationEndpointListHandler admin_api.NotificationEndpointListHandler
// OperatorAPIOperatorListBucketsHandler sets the operation handler for the operator list buckets operation
OperatorAPIOperatorListBucketsHandler operator_api.OperatorListBucketsHandler
// AdminAPIPolicyInfoHandler sets the operation handler for the policy info operation // AdminAPIPolicyInfoHandler sets the operation handler for the policy info operation
AdminAPIPolicyInfoHandler admin_api.PolicyInfoHandler AdminAPIPolicyInfoHandler admin_api.PolicyInfoHandler
// UserAPIPostBucketsBucketNameObjectsUploadHandler sets the operation handler for the post buckets bucket name objects upload operation // UserAPIPostBucketsBucketNameObjectsUploadHandler sets the operation handler for the post buckets bucket name objects upload operation
@@ -775,9 +769,6 @@ func (o *ConsoleAPI) Validate() error {
if o.AdminAPINotificationEndpointListHandler == nil { if o.AdminAPINotificationEndpointListHandler == nil {
unregistered = append(unregistered, "admin_api.NotificationEndpointListHandler") unregistered = append(unregistered, "admin_api.NotificationEndpointListHandler")
} }
if o.OperatorAPIOperatorListBucketsHandler == nil {
unregistered = append(unregistered, "operator_api.OperatorListBucketsHandler")
}
if o.AdminAPIPolicyInfoHandler == nil { if o.AdminAPIPolicyInfoHandler == nil {
unregistered = append(unregistered, "admin_api.PolicyInfoHandler") unregistered = append(unregistered, "admin_api.PolicyInfoHandler")
} }
@@ -1186,10 +1177,6 @@ func (o *ConsoleAPI) initHandlerCache() {
if o.handlers["GET"] == nil { if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler) o.handlers["GET"] = make(map[string]http.Handler)
} }
o.handlers["GET"]["/operator/{namespace}/{tenant}/buckets"] = operator_api.NewOperatorListBuckets(o.context, o.OperatorAPIOperatorListBucketsHandler)
if o.handlers["GET"] == nil {
o.handlers["GET"] = make(map[string]http.Handler)
}
o.handlers["GET"]["/policies/{name}"] = admin_api.NewPolicyInfo(o.context, o.AdminAPIPolicyInfoHandler) o.handlers["GET"]["/policies/{name}"] = admin_api.NewPolicyInfo(o.context, o.AdminAPIPolicyInfoHandler)
if o.handlers["POST"] == nil { if o.handlers["POST"] == nil {
o.handlers["POST"] = make(map[string]http.Handler) o.handlers["POST"] = make(map[string]http.Handler)

View File

@@ -1,90 +0,0 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2020 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package operator_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"net/http"
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/models"
)
// OperatorListBucketsHandlerFunc turns a function with the right signature into a operator list buckets handler
type OperatorListBucketsHandlerFunc func(OperatorListBucketsParams, *models.Principal) middleware.Responder
// Handle executing the request and returning a response
func (fn OperatorListBucketsHandlerFunc) Handle(params OperatorListBucketsParams, principal *models.Principal) middleware.Responder {
return fn(params, principal)
}
// OperatorListBucketsHandler interface for that can handle valid operator list buckets params
type OperatorListBucketsHandler interface {
Handle(OperatorListBucketsParams, *models.Principal) middleware.Responder
}
// NewOperatorListBuckets creates a new http.Handler for the operator list buckets operation
func NewOperatorListBuckets(ctx *middleware.Context, handler OperatorListBucketsHandler) *OperatorListBuckets {
return &OperatorListBuckets{Context: ctx, Handler: handler}
}
/*OperatorListBuckets swagger:route GET /operator/{namespace}/{tenant}/buckets OperatorAPI operatorListBuckets
List Buckets for Operator Console
*/
type OperatorListBuckets struct {
Context *middleware.Context
Handler OperatorListBucketsHandler
}
func (o *OperatorListBuckets) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
route, rCtx, _ := o.Context.RouteInfo(r)
if rCtx != nil {
r = rCtx
}
var Params = NewOperatorListBucketsParams()
uprinc, aCtx, err := o.Context.Authorize(r, route)
if err != nil {
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
if aCtx != nil {
r = aCtx
}
var principal *models.Principal
if uprinc != nil {
principal = uprinc.(*models.Principal) // this is really a models.Principal, I promise
}
if err := o.Context.BindValidRequest(r, route, &Params); err != nil { // bind params
o.Context.Respond(rw, r, route.Produces, route, err)
return
}
res := o.Handler.Handle(Params, principal) // actually handle the request
o.Context.Respond(rw, r, route.Produces, route, res)
}

View File

@@ -1,114 +0,0 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2020 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package operator_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/errors"
"github.com/go-openapi/runtime/middleware"
"github.com/go-openapi/strfmt"
)
// NewOperatorListBucketsParams creates a new OperatorListBucketsParams object
// no default values defined in spec.
func NewOperatorListBucketsParams() OperatorListBucketsParams {
return OperatorListBucketsParams{}
}
// OperatorListBucketsParams contains all the bound params for the operator list buckets operation
// typically these are obtained from a http.Request
//
// swagger:parameters OperatorListBuckets
type OperatorListBucketsParams struct {
// HTTP Request Object
HTTPRequest *http.Request `json:"-"`
/*
Required: true
In: path
*/
Namespace string
/*
Required: true
In: path
*/
Tenant string
}
// BindRequest both binds and validates a request, it assumes that complex things implement a Validatable(strfmt.Registry) error interface
// for simple values it will use straight method calls.
//
// To ensure default values, the struct must have been initialized with NewOperatorListBucketsParams() beforehand.
func (o *OperatorListBucketsParams) BindRequest(r *http.Request, route *middleware.MatchedRoute) error {
var res []error
o.HTTPRequest = r
rNamespace, rhkNamespace, _ := route.Params.GetOK("namespace")
if err := o.bindNamespace(rNamespace, rhkNamespace, route.Formats); err != nil {
res = append(res, err)
}
rTenant, rhkTenant, _ := route.Params.GetOK("tenant")
if err := o.bindTenant(rTenant, rhkTenant, route.Formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
// bindNamespace binds and validates parameter Namespace from path.
func (o *OperatorListBucketsParams) bindNamespace(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// Parameter is provided by construction from the route
o.Namespace = raw
return nil
}
// bindTenant binds and validates parameter Tenant from path.
func (o *OperatorListBucketsParams) bindTenant(rawData []string, hasKey bool, formats strfmt.Registry) error {
var raw string
if len(rawData) > 0 {
raw = rawData[len(rawData)-1]
}
// Required: true
// Parameter is provided by construction from the route
o.Tenant = raw
return nil
}

View File

@@ -1,133 +0,0 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2020 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package operator_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"net/http"
"github.com/go-openapi/runtime"
"github.com/minio/console/models"
)
// OperatorListBucketsOKCode is the HTTP code returned for type OperatorListBucketsOK
const OperatorListBucketsOKCode int = 200
/*OperatorListBucketsOK A successful response.
swagger:response operatorListBucketsOK
*/
type OperatorListBucketsOK struct {
/*
In: Body
*/
Payload *models.ListBucketsResponse `json:"body,omitempty"`
}
// NewOperatorListBucketsOK creates OperatorListBucketsOK with default headers values
func NewOperatorListBucketsOK() *OperatorListBucketsOK {
return &OperatorListBucketsOK{}
}
// WithPayload adds the payload to the operator list buckets o k response
func (o *OperatorListBucketsOK) WithPayload(payload *models.ListBucketsResponse) *OperatorListBucketsOK {
o.Payload = payload
return o
}
// SetPayload sets the payload to the operator list buckets o k response
func (o *OperatorListBucketsOK) SetPayload(payload *models.ListBucketsResponse) {
o.Payload = payload
}
// WriteResponse to the client
func (o *OperatorListBucketsOK) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(200)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}
/*OperatorListBucketsDefault Generic error response.
swagger:response operatorListBucketsDefault
*/
type OperatorListBucketsDefault struct {
_statusCode int
/*
In: Body
*/
Payload *models.Error `json:"body,omitempty"`
}
// NewOperatorListBucketsDefault creates OperatorListBucketsDefault with default headers values
func NewOperatorListBucketsDefault(code int) *OperatorListBucketsDefault {
if code <= 0 {
code = 500
}
return &OperatorListBucketsDefault{
_statusCode: code,
}
}
// WithStatusCode adds the status to the operator list buckets default response
func (o *OperatorListBucketsDefault) WithStatusCode(code int) *OperatorListBucketsDefault {
o._statusCode = code
return o
}
// SetStatusCode sets the status to the operator list buckets default response
func (o *OperatorListBucketsDefault) SetStatusCode(code int) {
o._statusCode = code
}
// WithPayload adds the payload to the operator list buckets default response
func (o *OperatorListBucketsDefault) WithPayload(payload *models.Error) *OperatorListBucketsDefault {
o.Payload = payload
return o
}
// SetPayload sets the payload to the operator list buckets default response
func (o *OperatorListBucketsDefault) SetPayload(payload *models.Error) {
o.Payload = payload
}
// WriteResponse to the client
func (o *OperatorListBucketsDefault) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
rw.WriteHeader(o._statusCode)
if o.Payload != nil {
payload := o.Payload
if err := producer.Produce(rw, payload); err != nil {
panic(err) // let the recovery middleware deal with this
}
}
}

View File

@@ -1,124 +0,0 @@
// Code generated by go-swagger; DO NOT EDIT.
// This file is part of MinIO Console Server
// Copyright (c) 2020 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package operator_api
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the generate command
import (
"errors"
"net/url"
golangswaggerpaths "path"
"strings"
)
// OperatorListBucketsURL generates an URL for the operator list buckets operation
type OperatorListBucketsURL struct {
Namespace string
Tenant string
_basePath string
// avoid unkeyed usage
_ struct{}
}
// WithBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *OperatorListBucketsURL) WithBasePath(bp string) *OperatorListBucketsURL {
o.SetBasePath(bp)
return o
}
// SetBasePath sets the base path for this url builder, only required when it's different from the
// base path specified in the swagger spec.
// When the value of the base path is an empty string
func (o *OperatorListBucketsURL) SetBasePath(bp string) {
o._basePath = bp
}
// Build a url path and query string
func (o *OperatorListBucketsURL) Build() (*url.URL, error) {
var _result url.URL
var _path = "/operator/{namespace}/{tenant}/buckets"
namespace := o.Namespace
if namespace != "" {
_path = strings.Replace(_path, "{namespace}", namespace, -1)
} else {
return nil, errors.New("namespace is required on OperatorListBucketsURL")
}
tenant := o.Tenant
if tenant != "" {
_path = strings.Replace(_path, "{tenant}", tenant, -1)
} else {
return nil, errors.New("tenant is required on OperatorListBucketsURL")
}
_basePath := o._basePath
if _basePath == "" {
_basePath = "/api/v1"
}
_result.Path = golangswaggerpaths.Join(_basePath, _path)
return &_result, nil
}
// Must is a helper function to panic when the url builder returns an error
func (o *OperatorListBucketsURL) Must(u *url.URL, err error) *url.URL {
if err != nil {
panic(err)
}
if u == nil {
panic("url can't be nil")
}
return u
}
// String returns the string representation of the path with query string
func (o *OperatorListBucketsURL) String() string {
return o.Must(o.Build()).String()
}
// BuildFull builds a full url with scheme, host, path and query string
func (o *OperatorListBucketsURL) BuildFull(scheme, host string) (*url.URL, error) {
if scheme == "" {
return nil, errors.New("scheme is required for a full url on OperatorListBucketsURL")
}
if host == "" {
return nil, errors.New("host is required for a full url on OperatorListBucketsURL")
}
base, err := o.Build()
if err != nil {
return nil, err
}
base.Scheme = scheme
base.Host = host
return base, nil
}
// StringFull returns the string representation of a complete url
func (o *OperatorListBucketsURL) StringFull(scheme, host string) string {
return o.Must(o.BuildFull(scheme, host)).String()
}

View File

@@ -1,93 +0,0 @@
// This file is part of MinIO Console Server
// Copyright (c) 2020 MinIO, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package restapi
import (
"context"
"time"
"github.com/go-openapi/runtime/middleware"
"github.com/minio/console/cluster"
"github.com/minio/console/models"
"github.com/minio/console/restapi/operations"
"github.com/minio/console/restapi/operations/operator_api"
)
func registerOperatorBucketsHandlers(api *operations.ConsoleAPI) {
// list buckets
api.OperatorAPIOperatorListBucketsHandler = operator_api.OperatorListBucketsHandlerFunc(func(params operator_api.OperatorListBucketsParams, session *models.Principal) middleware.Responder {
listBucketsResponse, err := getOperatorListBucketsResponse(session, params.Namespace, params.Tenant)
if err != nil {
return operator_api.NewOperatorListBucketsDefault(int(err.Code)).WithPayload(err)
}
return operator_api.NewOperatorListBucketsOK().WithPayload(listBucketsResponse)
})
}
// getListBucketsResponse performs listBuckets() and serializes it to the handler's output
func getOperatorListBucketsResponse(session *models.Principal, namespace, tenant string) (*models.ListBucketsResponse, *models.Error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
opClientClientSet, err := cluster.OperatorClient(session.STSSessionToken)
if err != nil {
return nil, prepareError(err)
}
clientSet, err := cluster.K8sClient(session.STSSessionToken)
if err != nil {
return nil, prepareError(err)
}
opClient := &operatorClient{
client: opClientClientSet,
}
k8sClient := &k8sClient{
client: clientSet,
}
minTenant, err := getTenant(ctx, opClient, namespace, tenant)
if err != nil {
return nil, prepareError(err)
}
minTenant.EnsureDefaults()
svcURL := GetTenantServiceURL(minTenant)
// getTenantAdminClient will use all certificates under ~/.console/certs/CAs to trust the TLS connections with MinIO tenants
mAdmin, err := getTenantAdminClient(
ctx,
k8sClient,
minTenant,
svcURL,
)
if err != nil {
return nil, prepareError(err)
}
// create a minioClient interface implementation
// defining the client to be used
adminClient := adminClient{client: mAdmin}
buckets, err := getAccountInfo(ctx, adminClient)
if err != nil {
return nil, prepareError(err)
}
// serialize output
listBucketsResponse := &models.ListBucketsResponse{
Buckets: buckets,
Total: int64(len(buckets)),
}
return listBucketsResponse, nil
}

View File

@@ -30,8 +30,6 @@ import (
) )
type watchOptions struct { type watchOptions struct {
Namespace string
Tenant string
BucketName string BucketName string
mc.WatchOptions mc.WatchOptions
} }
@@ -89,19 +87,17 @@ func getWatchOptionsFromReq(req *http.Request) (*watchOptions, error) {
// Default Events if not defined // Default Events if not defined
wOptions.Events = []string{"put", "get", "delete"} wOptions.Events = []string{"put", "get", "delete"}
re := regexp.MustCompile(`(/watch/)(.*?)/(.*?)/(.*?)(\?.*?$|$)`) re := regexp.MustCompile(`(/watch/)(.*?$)`)
matches := re.FindAllSubmatch([]byte(req.URL.Path), -1) matches := re.FindAllSubmatch([]byte(req.URL.Path), -1)
// matches comes as e.g. // matches comes as e.g.
// [["...", "/watch/", "namespace", "tenant", "bucket1"]] // [["...", "/watch/", "bucket1"]]
// [["/watch/" "/watch/" ""]] // [["/watch/" "/watch/" ""]]
if len(matches) == 0 || len(matches[0]) < 5 { if len(matches) == 0 || len(matches[0]) < 3 {
return nil, fmt.Errorf("invalid url: %s", req.URL.Path) return nil, fmt.Errorf("invalid url: %s", req.URL.Path)
} }
wOptions.Namespace = strings.TrimSpace(string(matches[0][2])) wOptions.BucketName = strings.TrimSpace(string(matches[0][2]))
wOptions.Tenant = strings.TrimSpace(string(matches[0][3]))
wOptions.BucketName = strings.TrimSpace(string(matches[0][4]))
events := req.FormValue("events") events := req.FormValue("events")
if strings.TrimSpace(events) != "" { if strings.TrimSpace(events) != "" {

View File

@@ -199,7 +199,7 @@ func TestWatch(t *testing.T) {
} }
// Test-6: getWatchOptionsFromReq return parameters from path // Test-6: getWatchOptionsFromReq return parameters from path
u, err := url.Parse("http://localhost/api/v1/watch/namespace/tenantName/bucket1?prefix=&suffix=.jpg&events=put,get") u, err := url.Parse("http://localhost/api/v1/watch/bucket1?prefix=&suffix=.jpg&events=put,get")
if err != nil { if err != nil {
t.Errorf("Failed on %s:, error occurred: %s", "url.Parse()", err.Error()) t.Errorf("Failed on %s:, error occurred: %s", "url.Parse()", err.Error())
} }
@@ -221,7 +221,7 @@ func TestWatch(t *testing.T) {
} }
// Test-7: getWatchOptionsFromReq return default events if not defined // Test-7: getWatchOptionsFromReq return default events if not defined
u, err = url.Parse("http://localhost/api/v1/watch/namespace/tenantName/bucket1?prefix=&suffix=.jpg&events=") u, err = url.Parse("http://localhost/api/v1/watch/bucket1?prefix=&suffix=.jpg&events=")
if err != nil { if err != nil {
t.Errorf("Failed on %s:, error occurred: %s", "url.Parse()", err.Error()) t.Errorf("Failed on %s:, error occurred: %s", "url.Parse()", err.Error())
} }
@@ -244,7 +244,7 @@ func TestWatch(t *testing.T) {
} }
// Test-8: getWatchOptionsFromReq return default events if not defined // Test-8: getWatchOptionsFromReq return default events if not defined
u, err = url.Parse("http://localhost/api/v1/watch/namespace/tenantName/bucket2?prefix=&suffix=") u, err = url.Parse("http://localhost/api/v1/watch/bucket2?prefix=&suffix=")
if err != nil { if err != nil {
t.Errorf("Failed on %s:, error occurred: %s", "url.Parse()", err.Error()) t.Errorf("Failed on %s:, error occurred: %s", "url.Parse()", err.Error())
} }

View File

@@ -22,11 +22,9 @@ import (
"net" "net"
"net/http" "net/http"
"strings" "strings"
"time"
"github.com/go-openapi/errors" "github.com/go-openapi/errors"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"github.com/minio/console/cluster"
"github.com/minio/console/models" "github.com/minio/console/models"
"github.com/minio/console/pkg/auth" "github.com/minio/console/pkg/auth"
) )
@@ -121,28 +119,14 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
wsPath := strings.TrimPrefix(req.URL.Path, wsBasePath) wsPath := strings.TrimPrefix(req.URL.Path, wsBasePath)
switch { switch {
case strings.HasPrefix(wsPath, `/trace`): case strings.HasPrefix(wsPath, `/trace`):
// Trace api only for operator Console wsAdminClient, err := newWebSocketAdminClient(conn, session)
namespace, tenant, err := getTraceOptionsFromReq(req)
if err != nil {
log.Println("error getting trace options:", err)
closeWsConn(conn)
return
}
wsAdminClient, err := newWebSocketTenantAdminClient(conn, session, namespace, tenant)
if err != nil { if err != nil {
closeWsConn(conn) closeWsConn(conn)
return return
} }
go wsAdminClient.trace() go wsAdminClient.trace()
case strings.HasPrefix(wsPath, `/console`): case strings.HasPrefix(wsPath, `/console`):
// Trace api only for operator Console wsAdminClient, err := newWebSocketAdminClient(conn, session)
namespace, tenant, err := getConsoleLogOptionsFromReq(req)
if err != nil {
log.Println("error getting log options:", err)
closeWsConn(conn)
return
}
wsAdminClient, err := newWebSocketTenantAdminClient(conn, session, namespace, tenant)
if err != nil { if err != nil {
closeWsConn(conn) closeWsConn(conn)
return return
@@ -155,7 +139,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
closeWsConn(conn) closeWsConn(conn)
return return
} }
wsAdminClient, err := newWebSocketTenantAdminClient(conn, session, hOptions.Namespace, hOptions.Tenant) wsAdminClient, err := newWebSocketAdminClient(conn, session)
if err != nil { if err != nil {
closeWsConn(conn) closeWsConn(conn)
return return
@@ -168,7 +152,7 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
closeWsConn(conn) closeWsConn(conn)
return return
} }
wsS3Client, err := newWebSocketS3Client(conn, session, wOptions.Namespace, wOptions.Tenant, wOptions.BucketName) wsS3Client, err := newWebSocketS3Client(conn, session, wOptions.BucketName)
if err != nil { if err != nil {
closeWsConn(conn) closeWsConn(conn)
return return
@@ -180,44 +164,13 @@ func serveWS(w http.ResponseWriter, req *http.Request) {
} }
} }
// newWebSocketTenantAdminClient creates a ws Client with a k8s tenant client // newWebSocketAdminClient returns a wsAdminClient authenticated as an admin user
// this is to be used for a kubernetes environment and for a particular tenant func newWebSocketAdminClient(conn *websocket.Conn, autClaims *models.Principal) (*wsAdminClient, error) {
// in a defined namespace // Only start Websocket Interaction after user has been
func newWebSocketTenantAdminClient(conn *websocket.Conn, session *models.Principal, namespace, tenant string) (*wsAdminClient, error) { // authenticated with MinIO
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) mAdmin, err := newAdminFromClaims(autClaims)
defer cancel()
opClientClientSet, err := cluster.OperatorClient(session.STSSessionToken)
if err != nil {
return nil, err
}
clientSet, err := cluster.K8sClient(session.STSSessionToken)
if err != nil {
return nil, err
}
opClient := &operatorClient{
client: opClientClientSet,
}
k8sClient := &k8sClient{
client: clientSet,
}
minTenant, err := getTenant(ctx, opClient, namespace, tenant)
if err != nil {
return nil, err
}
minTenant.EnsureDefaults()
svcURL := GetTenantServiceURL(minTenant)
// getTenantAdminClient will use all certificates under ~/.console/certs/CAs to trust the TLS connections with MinIO tenants
mAdmin, err := getTenantAdminClient(
ctx,
k8sClient,
minTenant,
svcURL,
)
if err != nil { if err != nil {
log.Println("error creating Madmin Client:", err)
return nil, err return nil, err
} }
// create a websocket connection interface implementation // create a websocket connection interface implementation
@@ -232,53 +185,12 @@ func newWebSocketTenantAdminClient(conn *websocket.Conn, session *models.Princip
} }
// newWebSocketS3Client returns a wsAdminClient authenticated as Console admin // newWebSocketS3Client returns a wsAdminClient authenticated as Console admin
func newWebSocketS3Client(conn *websocket.Conn, claims *models.Principal, namespace, tenant, bucketName string) (*wsS3Client, error) { func newWebSocketS3Client(conn *websocket.Conn, claims *models.Principal, bucketName string) (*wsS3Client, error) {
// Only start Websocket Interaction after user has been // Only start Websocket Interaction after user has been
// authenticated with MinIO // authenticated with MinIO
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) s3Client, err := newS3BucketClient(claims, bucketName, "")
defer cancel()
opClientClientSet, err := cluster.OperatorClient(claims.STSSessionToken)
if err != nil {
return nil, err
}
clientSet, err := cluster.K8sClient(claims.STSSessionToken)
if err != nil {
return nil, err
}
opClient := &operatorClient{
client: opClientClientSet,
}
k8sClient := &k8sClient{
client: clientSet,
}
minTenant, err := getTenant(ctx, opClient, namespace, tenant)
if err != nil {
return nil, err
}
minTenant.EnsureDefaults()
// Get Tenant Creds and substitute session ones
tenantCreds, err := getTenantCreds(ctx, k8sClient, minTenant)
if err != nil {
return nil, err
}
tenantClaims := &models.Principal{
STSAccessKeyID: tenantCreds.accessKey,
STSSecretAccessKey: tenantCreds.secretKey,
}
svcURL := GetTenantServiceURL(minTenant)
s3Client, err := newTenantS3BucketClient(tenantClaims, svcURL, bucketName)
if err != nil { if err != nil {
log.Println("error creating S3Client:", err) log.Println("error creating S3Client:", err)
_ = conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
_ = conn.Close()
return nil, err return nil, err
} }
// create a websocket connection interface implementation // create a websocket connection interface implementation

View File

@@ -1948,31 +1948,6 @@ paths:
$ref: "#/definitions/error" $ref: "#/definitions/error"
tags: tags:
- AdminAPI - AdminAPI
/operator/{namespace}/{tenant}/buckets:
get:
summary: List Buckets for Operator Console
operationId: OperatorListBuckets
parameters:
- name: namespace
in: path
required: true
type: string
- name: tenant
in: path
required: true
type: string
responses:
200:
description: A successful response.
schema:
$ref: "#/definitions/listBucketsResponse"
default:
description: Generic error response.
schema:
$ref: "#/definitions/error"
tags:
- OperatorAPI
definitions: definitions: