github.com/minio/console@v1.4.1/web-app/src/screens/Console/Configurations/utils.tsx (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2021 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  import React from "react";
    17  import { IElement, IElementValue, IOverrideEnv, OverrideValue } from "./types";
    18  import {
    19    CodeIcon,
    20    CompressIcon,
    21    ConsoleIcon,
    22    FindReplaceIcon,
    23    FirstAidIcon,
    24    KeyIcon,
    25    LogsIcon,
    26    PendingItemsIcon,
    27    PublicIcon,
    28  } from "mds";
    29  
    30  export const configurationElements: IElement[] = [
    31    {
    32      icon: <PublicIcon />,
    33      configuration_id: "region",
    34      configuration_label: "Region",
    35    },
    36    {
    37      icon: <CompressIcon />,
    38      configuration_id: "compression",
    39      configuration_label: "Compression",
    40    },
    41    {
    42      icon: <CodeIcon />,
    43      configuration_id: "api",
    44      configuration_label: "API",
    45    },
    46    {
    47      icon: <FirstAidIcon />,
    48      configuration_id: "heal",
    49      configuration_label: "Heal",
    50    },
    51    {
    52      icon: <FindReplaceIcon />,
    53      configuration_id: "scanner",
    54      configuration_label: "Scanner",
    55    },
    56    {
    57      icon: <KeyIcon />,
    58      configuration_id: "etcd",
    59      configuration_label: "Etcd",
    60    },
    61    {
    62      icon: <ConsoleIcon />,
    63      configuration_id: "logger_webhook",
    64      configuration_label: "Logger Webhook",
    65    },
    66    {
    67      icon: <PendingItemsIcon />,
    68      configuration_id: "audit_webhook",
    69      configuration_label: "Audit Webhook",
    70    },
    71    {
    72      icon: <LogsIcon />,
    73      configuration_id: "audit_kafka",
    74      configuration_label: "Audit Kafka",
    75    },
    76  ];
    77  
    78  export const fieldsConfigurations: any = {
    79    region: [
    80      {
    81        name: "name",
    82        required: true,
    83        label: "Server Location",
    84        tooltip: 'Name of the location of the server e.g. "us-west-rack2"',
    85        type: "string",
    86        placeholder: "e.g. us-west-rack-2",
    87      },
    88      {
    89        name: "comment",
    90        required: false,
    91        label: "Comment",
    92        tooltip: "You can add a comment to this setting",
    93        type: "comment",
    94        placeholder: "Enter custom notes if any",
    95      },
    96    ],
    97    compression: [
    98      {
    99        name: "extensions",
   100        required: false,
   101        label: "Extensions",
   102        tooltip:
   103          'Extensions to compress e.g. ".txt", ".log" or ".csv" -  you can write one per field',
   104        type: "csv",
   105        placeholder: "Enter an Extension",
   106        withBorder: true,
   107      },
   108      {
   109        name: "mime_types",
   110        required: false,
   111        label: "Mime Types",
   112        tooltip:
   113          'Mime types e.g. "text/*", "application/json" or "application/xml" - you can write one per field',
   114        type: "csv",
   115        placeholder: "Enter a Mime Type",
   116        withBorder: true,
   117      },
   118    ],
   119    api: [
   120      {
   121        name: "requests_max",
   122        required: false,
   123        label: "Requests Max",
   124        tooltip: "Maximum number of concurrent requests, e.g. '1600'",
   125        type: "number",
   126        placeholder: "Enter Requests Max",
   127      },
   128      {
   129        name: "cors_allow_origin",
   130        required: false,
   131        label: "Cors Allow Origin",
   132        tooltip: "List of origins allowed for CORS requests",
   133        type: "csv",
   134        placeholder: "Enter allowed origin e.g. https://example.com",
   135      },
   136      {
   137        name: "replication_workers",
   138        required: false,
   139        label: "Replication Workers",
   140        tooltip: "Number of replication workers, defaults to 100",
   141        type: "number",
   142        placeholder: "Enter Replication Workers",
   143      },
   144      {
   145        name: "replication_failed_workers",
   146        required: false,
   147        label: "Replication Failed Workers",
   148        tooltip:
   149          "Number of replication workers for recently failed replicas, defaults to 4",
   150        type: "number",
   151        placeholder: "Enter Replication Failed Workers",
   152      },
   153    ],
   154    heal: [
   155      {
   156        name: "bitrotscan",
   157        required: false,
   158        label: "Bitrot Scan",
   159        tooltip:
   160          "Perform bitrot scan on disks when checking objects during scanner",
   161        type: "on|off",
   162      },
   163      {
   164        name: "max_sleep",
   165        required: false,
   166        label: "Max Sleep",
   167        tooltip:
   168          "Maximum sleep duration between objects to slow down heal operation, e.g. 2s",
   169        type: "duration",
   170        placeholder: "Enter Max Sleep Duration",
   171      },
   172      {
   173        name: "max_io",
   174        required: false,
   175        label: "Max IO",
   176        tooltip:
   177          "Maximum IO requests allowed between objects to slow down heal operation, e.g. 3",
   178        type: "number",
   179        placeholder: "Enter Max IO",
   180      },
   181    ],
   182    scanner: [
   183      {
   184        name: "delay",
   185        required: false,
   186        label: "Delay Multiplier",
   187        tooltip: "Scanner delay multiplier, defaults to '10.0'",
   188        type: "number",
   189        placeholder: "Enter Delay",
   190      },
   191      {
   192        name: "max_wait",
   193        required: false,
   194        label: "Max Wait",
   195        tooltip: "Maximum wait time between operations, defaults to '15s'",
   196        type: "duration",
   197        placeholder: "Enter Max Wait",
   198      },
   199      {
   200        name: "cycle",
   201        required: false,
   202        label: "Cycle",
   203        tooltip: "Time duration between scanner cycles, defaults to '1m'",
   204        type: "duration",
   205        placeholder: "Enter Cycle",
   206      },
   207    ],
   208    etcd: [
   209      {
   210        name: "endpoints",
   211        required: true,
   212        label: "Endpoints",
   213        tooltip:
   214          'List of etcd endpoints e.g. "http://localhost:2379" - you can write one per field',
   215        type: "csv",
   216        placeholder: "Enter Endpoint",
   217      },
   218      {
   219        name: "path_prefix",
   220        required: false,
   221        label: "Path Prefix",
   222        tooltip: 'Namespace prefix to isolate tenants e.g. "customer1/"',
   223        type: "string",
   224        placeholder: "Enter Path Prefix",
   225      },
   226      {
   227        name: "coredns_path",
   228        required: false,
   229        label: "Coredns Path",
   230        tooltip: 'Shared bucket DNS records, default is "/skydns"',
   231        type: "string",
   232        placeholder: "Enter Coredns Path",
   233      },
   234      {
   235        name: "client_cert",
   236        required: false,
   237        label: "Client Cert",
   238        tooltip: "Client cert for mTLS authentication",
   239        type: "string",
   240        placeholder: "Enter Client Cert",
   241      },
   242      {
   243        name: "client_cert_key",
   244        required: false,
   245        label: "Client Cert Key",
   246        tooltip: "Client cert key for mTLS authentication",
   247        type: "string",
   248        placeholder: "Enter Client Cert Key",
   249      },
   250      {
   251        name: "comment",
   252        required: false,
   253        label: "Comment",
   254        tooltip: "You can add a comment to this setting",
   255        type: "comment",
   256        multiline: true,
   257        placeholder: "Enter custom notes if any",
   258      },
   259    ],
   260    logger_webhook: [
   261      {
   262        name: "endpoint",
   263        required: true,
   264        label: "Endpoint",
   265        type: "string",
   266        placeholder: "Enter Endpoint",
   267      },
   268      {
   269        name: "auth_token",
   270        required: true,
   271        label: "Auth Token",
   272        type: "string",
   273        placeholder: "Enter Auth Token",
   274      },
   275    ],
   276    audit_webhook: [
   277      {
   278        name: "endpoint",
   279        required: true,
   280        label: "Endpoint",
   281        type: "string",
   282        placeholder: "Enter Endpoint",
   283      },
   284      {
   285        name: "auth_token",
   286        required: true,
   287        label: "Auth Token",
   288        type: "string",
   289        placeholder: "Enter Auth Token",
   290      },
   291    ],
   292    audit_kafka: [
   293      {
   294        name: "enable",
   295        required: false,
   296        label: "Enable",
   297        tooltip: "Enable audit_kafka target",
   298        type: "on|off",
   299        customValueProcess: (origValue: string) => {
   300          return origValue === "" || origValue === "on" ? "on" : "off";
   301        },
   302      },
   303      {
   304        name: "brokers",
   305        required: true,
   306        label: "Brokers",
   307        type: "csv",
   308        placeholder: "Enter Kafka Broker",
   309      },
   310      {
   311        name: "topic",
   312        required: false,
   313        label: "Topic",
   314        type: "string",
   315        placeholder: "Enter Kafka Topic",
   316        tooltip: "Kafka topic used for bucket notifications",
   317      },
   318      {
   319        name: "sasl",
   320        required: false,
   321        label: "Use SASL",
   322        tooltip:
   323          "Enable SASL (Simple Authentication and Security Layer) authentication",
   324        type: "on|off",
   325      },
   326      {
   327        name: "sasl_username",
   328        required: false,
   329        label: "SASL Username",
   330        type: "string",
   331        placeholder: "Enter SASL Username",
   332        tooltip: "Username for SASL/PLAIN or SASL/SCRAM authentication",
   333      },
   334      {
   335        name: "sasl_password",
   336        required: false,
   337        label: "SASL Password",
   338        type: "password",
   339        placeholder: "Enter SASL Password",
   340        tooltip: "Password for SASL/PLAIN or SASL/SCRAM authentication",
   341      },
   342      {
   343        name: "sasl_mechanism",
   344        required: false,
   345        label: "SASL Mechanism",
   346        type: "string",
   347        placeholder: "Enter SASL Mechanism",
   348        tooltip: "SASL authentication mechanism",
   349      },
   350      {
   351        name: "tls",
   352        required: false,
   353        label: "Use TLS",
   354        tooltip: "Enable TLS (Transport Layer Security)",
   355        type: "on|off",
   356      },
   357      {
   358        name: "tls_skip_verify",
   359        required: false,
   360        label: "Skip TLS Verification",
   361        tooltip: "Trust server TLS without verification",
   362        type: "on|off",
   363      },
   364      {
   365        name: "client_tls_cert",
   366        required: false,
   367        label: "Client Cert",
   368        tooltip: "Client cert for mTLS authentication",
   369        type: "string",
   370        placeholder: "Enter Client Cert",
   371      },
   372      {
   373        name: "client_tls_key",
   374        required: false,
   375        label: "Client Cert Key",
   376        tooltip: "Client cert key for mTLS authentication",
   377        type: "string",
   378        placeholder: "Enter Client Cert Key",
   379      },
   380      {
   381        name: "tls_client_auth",
   382        required: false,
   383        label: "TLS Client Auth",
   384        tooltip:
   385          "ClientAuth determines the Kafka server's policy for TLS client authorization",
   386        type: "string",
   387      },
   388      {
   389        name: "version",
   390        required: false,
   391        label: "Version",
   392        tooltip: "Specify the version of the Kafka cluster",
   393        type: "string",
   394      },
   395    ],
   396  };
   397  
   398  export const removeEmptyFields = (formFields: IElementValue[]) => {
   399    const nonEmptyFields = formFields.filter((field) => field.value !== "");
   400  
   401    return nonEmptyFields;
   402  };
   403  
   404  export const selectSAs = (
   405    e: React.ChangeEvent<HTMLInputElement>,
   406    setSelectedSAs: Function,
   407    selectedSAs: string[],
   408  ) => {
   409    const targetD = e.target;
   410    const value = targetD.value;
   411    const checked = targetD.checked;
   412  
   413    let elements: string[] = [...selectedSAs]; // We clone the selectedSAs array
   414    if (checked) {
   415      // If the user has checked this field we need to push this to selectedSAs
   416      elements.push(value);
   417    } else {
   418      // User has unchecked this field, we need to remove it from the list
   419      elements = elements.filter((element) => element !== value);
   420    }
   421    setSelectedSAs(elements);
   422    return elements;
   423  };
   424  
   425  export const overrideFields = (formFields: IElementValue[]): IOverrideEnv => {
   426    let overrideReturn: IOverrideEnv = {};
   427  
   428    formFields.forEach((envItem) => {
   429      // it has override values, we construct the value
   430      if (envItem.env_override) {
   431        const value: OverrideValue = {
   432          value: envItem.env_override.value || "",
   433          overrideEnv: envItem.env_override.name || "",
   434        };
   435  
   436        overrideReturn = { ...overrideReturn, [envItem.key]: value };
   437      }
   438    });
   439  
   440    return overrideReturn;
   441  };