From de4ff1c1f0ee8c19a4de258ad2fa929f03f6f1bd Mon Sep 17 00:00:00 2001 From: Alex <33497058+bexsoft@users.noreply.github.com> Date: Mon, 13 Feb 2023 17:04:35 -0600 Subject: [PATCH] Call Home Enabled in console (#2248) Signed-off-by: Benjamin Perez --- models/call_home_get_response.go | 70 ++++ models/call_home_set_status.go | 105 +++++ pkg/subnet/utils.go | 4 + .../Common/ModalWrapper/ConfirmDialog.tsx | 19 + .../src/screens/Console/Support/CallHome.tsx | 328 +++++++++++++++ .../Console/Support/CallHomeConfirmation.tsx | 218 ++++++++++ .../src/screens/Console/Support/types.ts | 20 + portal-ui/src/screens/Console/Tools/Tools.tsx | 15 +- portal-ui/src/screens/Console/valid-routes.ts | 16 +- restapi/admin_client_mock.go | 14 +- restapi/client-admin.go | 7 + restapi/configure_console.go | 2 + restapi/embedded_spec.go | 154 +++++++ restapi/operations/console_api.go | 25 ++ .../support/get_call_home_option_value.go | 88 ++++ .../get_call_home_option_value_parameters.go | 63 +++ .../get_call_home_option_value_responses.go | 135 +++++++ .../get_call_home_option_value_urlbuilder.go | 104 +++++ .../support/set_call_home_status.go | 88 ++++ .../set_call_home_status_parameters.go | 101 +++++ .../support/set_call_home_status_responses.go | 115 ++++++ .../set_call_home_status_urlbuilder.go | 104 +++++ restapi/user_support.go | 235 +++++++++++ restapi/user_support_test.go | 382 ++++++++++++++++++ swagger-console.yml | 58 ++- 25 files changed, 2445 insertions(+), 25 deletions(-) create mode 100644 models/call_home_get_response.go create mode 100644 models/call_home_set_status.go create mode 100644 portal-ui/src/screens/Console/Support/CallHome.tsx create mode 100644 portal-ui/src/screens/Console/Support/CallHomeConfirmation.tsx create mode 100644 portal-ui/src/screens/Console/Support/types.ts create mode 100644 restapi/operations/support/get_call_home_option_value.go create mode 100644 restapi/operations/support/get_call_home_option_value_parameters.go create mode 100644 restapi/operations/support/get_call_home_option_value_responses.go create mode 100644 restapi/operations/support/get_call_home_option_value_urlbuilder.go create mode 100644 restapi/operations/support/set_call_home_status.go create mode 100644 restapi/operations/support/set_call_home_status_parameters.go create mode 100644 restapi/operations/support/set_call_home_status_responses.go create mode 100644 restapi/operations/support/set_call_home_status_urlbuilder.go create mode 100644 restapi/user_support.go create mode 100644 restapi/user_support_test.go diff --git a/models/call_home_get_response.go b/models/call_home_get_response.go new file mode 100644 index 000000000..f07dca0f6 --- /dev/null +++ b/models/call_home_get_response.go @@ -0,0 +1,70 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2023 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 . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" +) + +// CallHomeGetResponse call home get response +// +// swagger:model callHomeGetResponse +type CallHomeGetResponse struct { + + // diagnostics status + DiagnosticsStatus bool `json:"diagnosticsStatus,omitempty"` + + // logs status + LogsStatus bool `json:"logsStatus,omitempty"` +} + +// Validate validates this call home get response +func (m *CallHomeGetResponse) Validate(formats strfmt.Registry) error { + return nil +} + +// ContextValidate validates this call home get response based on context it is used +func (m *CallHomeGetResponse) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *CallHomeGetResponse) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *CallHomeGetResponse) UnmarshalBinary(b []byte) error { + var res CallHomeGetResponse + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/models/call_home_set_status.go b/models/call_home_set_status.go new file mode 100644 index 000000000..34b956afc --- /dev/null +++ b/models/call_home_set_status.go @@ -0,0 +1,105 @@ +// Code generated by go-swagger; DO NOT EDIT. + +// This file is part of MinIO Console Server +// Copyright (c) 2023 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 . +// + +package models + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +import ( + "context" + + "github.com/go-openapi/errors" + "github.com/go-openapi/strfmt" + "github.com/go-openapi/swag" + "github.com/go-openapi/validate" +) + +// CallHomeSetStatus call home set status +// +// swagger:model callHomeSetStatus +type CallHomeSetStatus struct { + + // diag state + // Required: true + DiagState *bool `json:"diagState"` + + // logs state + // Required: true + LogsState *bool `json:"logsState"` +} + +// Validate validates this call home set status +func (m *CallHomeSetStatus) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateDiagState(formats); err != nil { + res = append(res, err) + } + + if err := m.validateLogsState(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *CallHomeSetStatus) validateDiagState(formats strfmt.Registry) error { + + if err := validate.Required("diagState", "body", m.DiagState); err != nil { + return err + } + + return nil +} + +func (m *CallHomeSetStatus) validateLogsState(formats strfmt.Registry) error { + + if err := validate.Required("logsState", "body", m.LogsState); err != nil { + return err + } + + return nil +} + +// ContextValidate validates this call home set status based on context it is used +func (m *CallHomeSetStatus) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + +// MarshalBinary interface implementation +func (m *CallHomeSetStatus) MarshalBinary() ([]byte, error) { + if m == nil { + return nil, nil + } + return swag.WriteJSON(m) +} + +// UnmarshalBinary interface implementation +func (m *CallHomeSetStatus) UnmarshalBinary(b []byte) error { + var res CallHomeSetStatus + if err := swag.ReadJSON(b, &res); err != nil { + return err + } + *m = res + return nil +} diff --git a/pkg/subnet/utils.go b/pkg/subnet/utils.go index 5a4fc9a23..aeaddcaf2 100644 --- a/pkg/subnet/utils.go +++ b/pkg/subnet/utils.go @@ -60,6 +60,10 @@ func subnetAPIKeyURL() string { return subnetBaseURL() + "/api/auth/api-key" } +func LogWebhookURL() string { + return subnetBaseURL() + "/api/logs" +} + func GenerateRegToken(clusterRegInfo mc.ClusterRegistrationInfo) (string, error) { token, e := json.Marshal(clusterRegInfo) if e != nil { diff --git a/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx b/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx index 97bbf4e8a..770cbe804 100644 --- a/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx +++ b/portal-ui/src/screens/Console/Common/ModalWrapper/ConfirmDialog.tsx @@ -1,3 +1,19 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2023 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 . + import React from "react"; import { Dialog, @@ -35,6 +51,7 @@ type ConfirmDialogProps = { cancelButtonProps?: ButtonProps & React.ButtonHTMLAttributes; titleIcon?: React.ReactNode; + confirmationButtonSimple?: boolean; }; const ConfirmDialog = ({ @@ -51,6 +68,7 @@ const ConfirmDialog = ({ confirmButtonProps = undefined, cancelButtonProps = undefined, titleIcon = null, + confirmationButtonSimple = false, }: ConfirmDialogProps) => { return ( + + )} + + + + )} + + + + + + + + Learn more about Call Home + + + + + Enabling Call Home sends cluster health & status to your + registered MinIO Subscription Network account every 24 + hours. +
+
+ This helps the MinIO support team to provide quick + incident responses along with suggestions for possible + improvements that can be made to your MinIO instances. +
+
+ Your cluster must be{" "} + registered in the + MinIO Subscription Network (SUBNET) before enabling this + feature. +
+
+ + } + /> +
+ + + + ); +}; + +export default CallHome; diff --git a/portal-ui/src/screens/Console/Support/CallHomeConfirmation.tsx b/portal-ui/src/screens/Console/Support/CallHomeConfirmation.tsx new file mode 100644 index 000000000..86f31fdf8 --- /dev/null +++ b/portal-ui/src/screens/Console/Support/CallHomeConfirmation.tsx @@ -0,0 +1,218 @@ +// This file is part of MinIO Console Server +// Copyright (c) 2023 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 . + +import React, { Fragment, useState } from "react"; +import { Button, CallHomeMenuIcon, CircleIcon, Grid } from "mds"; +import { LinearProgress } from "@mui/material"; +import api from "../../../common/api"; +import { ICallHomeResponse } from "./types"; +import { ErrorResponseHandler } from "../../../common/types"; +import { setErrorSnackMessage, setSnackBarMessage } from "../../../systemSlice"; +import { useAppDispatch } from "../../../store"; +import ModalWrapper from "../Common/ModalWrapper/ModalWrapper"; +import InputBoxWrapper from "../Common/FormComponents/InputBoxWrapper/InputBoxWrapper"; + +interface ICallHomeConfirmation { + onClose: (refresh: boolean) => any; + open: boolean; + diagStatus: boolean; + logsStatus: boolean; + disable?: boolean; +} + +const CallHomeConfirmation = ({ + onClose, + diagStatus, + logsStatus, + open, + disable = false, +}: ICallHomeConfirmation) => { + const dispatch = useAppDispatch(); + + const [loading, setLoading] = useState(false); + const [confirmText, setConfirmText] = useState(""); + + const onConfirmAction = () => { + setLoading(true); + api + .invoke("PUT", `/api/v1/support/callhome`, { + diagState: disable ? false : diagStatus, + logsState: disable ? false : logsStatus, + }) + .then((res: ICallHomeResponse) => { + dispatch(setSnackBarMessage("Configuration saved successfully")); + setLoading(false); + onClose(true); + }) + .catch((err: ErrorResponseHandler) => { + setLoading(false); + dispatch(setErrorSnackMessage(err)); + }); + }; + + return ( + onClose(false)} + titleIcon={} + > + {disable ? ( + + Please Acknowledge that after doing this action, we will no longer + receive updated cluster information automatically, losing the + potential benefits that Call Home provides to your MinIO cluster. + + Are you sure you want to disable SUBNET Call Home? + +
+ {loading && ( + + + + )} + +