github.com/minio/console@v1.4.1/web-app/src/screens/Console/EventDestinations/utils.ts (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 17 import { NotificationEndpointItem } from "api/consoleApi"; 18 import { IElementValue } from "../Configurations/types"; 19 import { TransformedEndpointItem } from "./types"; 20 21 export const notifyPostgres = "notify_postgres"; 22 export const notifyMysql = "notify_mysql"; 23 export const notifyKafka = "notify_kafka"; 24 export const notifyAmqp = "notify_amqp"; 25 export const notifyMqtt = "notify_mqtt"; 26 export const notifyRedis = "notify_redis"; 27 export const notifyNats = "notify_nats"; 28 export const notifyElasticsearch = "notify_elasticsearch"; 29 export const notifyWebhooks = "notify_webhook"; 30 export const notifyNsq = "notify_nsq"; 31 export const notificationTransform = ( 32 notificationElements: NotificationEndpointItem[], 33 ) => { 34 return notificationElements.map((element) => { 35 return { 36 service_name: `${element.service}:${element.account_id}`, 37 name: element.service, 38 account_id: element.account_id, 39 status: element.status, 40 }; 41 }) as TransformedEndpointItem[]; 42 }; 43 44 export class DestType { 45 static DB: string = "database"; 46 static Queue: string = "queue"; 47 static Func: string = "functions"; 48 } 49 50 const getImgBaseURL = () => { 51 return `${document.baseURI}`; 52 }; 53 54 export const destinationList = [ 55 { 56 actionTrigger: notifyPostgres, 57 targetTitle: "PostgreSQL", 58 logo: `${getImgBaseURL()}postgres-logo.svg`, 59 category: DestType.DB, 60 }, 61 { 62 actionTrigger: notifyKafka, 63 targetTitle: "Kafka", 64 logo: `${getImgBaseURL()}kafka-logo.svg`, 65 category: DestType.Queue, 66 }, 67 { 68 actionTrigger: notifyAmqp, 69 targetTitle: "AMQP", 70 logo: `${getImgBaseURL()}amqp-logo.svg`, 71 category: DestType.Queue, 72 }, 73 { 74 actionTrigger: notifyMqtt, 75 targetTitle: "MQTT", 76 logo: `${getImgBaseURL()}mqtt-logo.svg`, 77 category: DestType.Queue, 78 }, 79 { 80 actionTrigger: notifyRedis, 81 targetTitle: "Redis", 82 logo: `${getImgBaseURL()}redis-logo.svg`, 83 category: DestType.Queue, 84 }, 85 { 86 actionTrigger: notifyNats, 87 targetTitle: "NATS", 88 logo: `${getImgBaseURL()}nats-logo.svg`, 89 category: DestType.Queue, 90 }, 91 { 92 actionTrigger: notifyMysql, 93 targetTitle: "Mysql", 94 logo: `${getImgBaseURL()}mysql-logo.svg`, 95 category: DestType.DB, 96 }, 97 { 98 actionTrigger: notifyElasticsearch, 99 targetTitle: "Elastic Search", 100 logo: `${getImgBaseURL()}elasticsearch-logo.svg`, 101 category: DestType.DB, 102 }, 103 { 104 actionTrigger: notifyWebhooks, 105 targetTitle: "Webhook", 106 logo: `${getImgBaseURL()}webhooks-logo.svg`, 107 category: DestType.Func, 108 }, 109 { 110 actionTrigger: notifyNsq, 111 targetTitle: "NSQ", 112 logo: `${getImgBaseURL()}nsq-logo.svg`, 113 category: DestType.Queue, 114 }, 115 ]; 116 117 const commonFields = [ 118 { 119 name: "queue_dir", 120 label: "Queue Directory", 121 required: false, 122 123 tooltip: "Staging directory for undelivered messages e.g. '/home/events'", 124 type: "string", 125 placeholder: "Enter Queue Directory", 126 }, 127 { 128 name: "queue_limit", 129 label: "Queue Limit", 130 required: false, 131 132 tooltip: "Maximum limit for undelivered messages, defaults to '10000'", 133 type: "number", 134 placeholder: "Enter Queue Limit", 135 }, 136 { 137 name: "comment", 138 label: "Comment", 139 required: false, 140 type: "comment", 141 placeholder: "Enter custom notes if any", 142 }, 143 ]; 144 145 export const removeEmptyFields = (formFields: IElementValue[]) => { 146 const nonEmptyFields = formFields.filter((field) => field.value !== ""); 147 148 return nonEmptyFields; 149 }; 150 151 export const notificationEndpointsFields: any = { 152 [notifyKafka]: [ 153 { 154 name: "brokers", 155 label: "Brokers", 156 required: true, 157 158 tooltip: "Comma separated list of Kafka broker addresses", 159 type: "string", 160 placeholder: "Enter Brokers", 161 }, 162 { 163 name: "topic", 164 label: "Topic", 165 tooltip: "Kafka topic used for bucket notifications", 166 type: "string", 167 placeholder: "Enter Topic", 168 }, 169 { 170 name: "sasl_username", 171 label: "SASL Username", 172 tooltip: "Username for SASL/PLAIN or SASL/SCRAM authentication", 173 type: "string", 174 placeholder: "Enter SASL Username", 175 }, 176 { 177 name: "sasl_password", 178 label: "SASL Password", 179 tooltip: "Password for SASL/PLAIN or SASL/SCRAM authentication", 180 type: "string", 181 placeholder: "Enter SASL Password", 182 }, 183 { 184 name: "sasl_mechanism", 185 label: "SASL Mechanism", 186 tooltip: "SASL authentication mechanism, default 'PLAIN'", 187 type: "string", 188 }, 189 { 190 name: "tls_client_auth", 191 label: "TLS Client Auth", 192 tooltip: 193 "Client Auth determines the Kafka server's policy for TLS client authorization", 194 type: "string", 195 placeholder: "Enter TLS Client Auth", 196 }, 197 { 198 name: "sasl", 199 label: "SASL", 200 tooltip: "Set to 'on' to enable SASL authentication", 201 type: "on|off", 202 }, 203 { 204 name: "tls", 205 label: "TLS", 206 tooltip: "Set to 'on' to enable TLS", 207 type: "on|off", 208 }, 209 { 210 name: "tls_skip_verify", 211 label: "TLS skip verify", 212 tooltip: 213 'Trust server TLS without verification, defaults to "on" (verify)', 214 type: "on|off", 215 }, 216 { 217 name: "client_tls_cert", 218 label: "client TLS cert", 219 tooltip: "Path to client certificate for mTLS authorization", 220 type: "path", 221 placeholder: "Enter TLS Client Cert", 222 }, 223 { 224 name: "client_tls_key", 225 label: "client TLS key", 226 tooltip: "Path to client key for mTLS authorization", 227 type: "path", 228 placeholder: "Enter TLS Client Key", 229 }, 230 { 231 name: "version", 232 label: "Version", 233 tooltip: "Specify the version of the Kafka cluster e.g '2.2.0'", 234 type: "string", 235 placeholder: "Enter Kafka Version", 236 }, 237 ...commonFields, 238 ], 239 [notifyAmqp]: [ 240 { 241 name: "url", 242 required: true, 243 label: "URL", 244 tooltip: 245 "AMQP server endpoint e.g. `amqp://myuser:mypassword@localhost:5672`", 246 type: "url", 247 }, 248 { 249 name: "exchange", 250 label: "Exchange", 251 tooltip: "Name of the AMQP exchange", 252 type: "string", 253 placeholder: "Enter Exchange", 254 }, 255 { 256 name: "exchange_type", 257 label: "Exchange Type", 258 tooltip: "AMQP exchange type", 259 type: "string", 260 placeholder: "Enter Exchange Type", 261 }, 262 { 263 name: "routing_key", 264 label: "Routing Key", 265 tooltip: "Routing key for publishing", 266 type: "string", 267 placeholder: "Enter Routing Key", 268 }, 269 { 270 name: "mandatory", 271 label: "Mandatory", 272 tooltip: 273 "Quietly ignore undelivered messages when set to 'off', default is 'on'", 274 type: "on|off", 275 }, 276 { 277 name: "durable", 278 label: "Durable", 279 tooltip: 280 "Persist queue across broker restarts when set to 'on', default is 'off'", 281 type: "on|off", 282 }, 283 { 284 name: "no_wait", 285 label: "No Wait", 286 tooltip: 287 "Non-blocking message delivery when set to 'on', default is 'off'", 288 type: "on|off", 289 }, 290 { 291 name: "internal", 292 label: "Internal", 293 tooltip: 294 "Set to 'on' for exchange to be not used directly by publishers, but only when bound to other exchanges", 295 type: "on|off", 296 }, 297 { 298 name: "auto_deleted", 299 label: "Auto Deleted", 300 tooltip: 301 "Auto delete queue when set to 'on', when there are no consumers", 302 type: "on|off", 303 }, 304 { 305 name: "delivery_mode", 306 label: "Delivery Mode", 307 tooltip: "Set to '1' for non-persistent or '2' for persistent queue", 308 type: "number", 309 placeholder: "Enter Delivery Mode", 310 }, 311 ...commonFields, 312 ], 313 [notifyRedis]: [ 314 { 315 name: "address", 316 required: true, 317 label: "Address", 318 tooltip: "Redis server's address e.g. `localhost:6379`", 319 type: "address", 320 placeholder: "Enter Address", 321 }, 322 { 323 name: "key", 324 required: true, 325 label: "Key", 326 tooltip: "Redis key to store/update events, key is auto-created", 327 type: "string", 328 placeholder: "Enter Key", 329 }, 330 { 331 name: "password", 332 label: "Password", 333 tooltip: "Redis server password", 334 type: "string", 335 placeholder: "Enter Password", 336 }, 337 ...commonFields, 338 ], 339 [notifyMqtt]: [ 340 { 341 name: "broker", 342 required: true, 343 label: "Broker", 344 tooltip: "MQTT server endpoint e.g. `tcp://localhost:1883`", 345 type: "uri", 346 placeholder: "Enter Brokers", 347 }, 348 { 349 name: "topic", 350 required: true, 351 label: "Topic", 352 tooltip: "Name of the MQTT topic to publish", 353 type: "string", 354 placeholder: "Enter Topic", 355 }, 356 { 357 name: "username", 358 label: "Username", 359 tooltip: "MQTT username", 360 type: "string", 361 placeholder: "Enter Username", 362 }, 363 { 364 name: "password", 365 label: "Password", 366 tooltip: "MQTT password", 367 type: "string", 368 placeholder: "Enter Password", 369 }, 370 { 371 name: "qos", 372 label: "QOS", 373 tooltip: "Set the quality of service priority, defaults to '0'", 374 type: "number", 375 placeholder: "Enter QOS", 376 }, 377 { 378 name: "keep_alive_interval", 379 label: "Keep Alive Interval", 380 tooltip: "Keep-alive interval for MQTT connections in s,m,h,d", 381 type: "duration", 382 placeholder: "Enter Keep Alive Interval", 383 }, 384 { 385 name: "reconnect_interval", 386 label: "Reconnect Interval", 387 tooltip: "Reconnect interval for MQTT connections in s,m,h,d", 388 type: "duration", 389 placeholder: "Enter Reconnect Interval", 390 }, 391 ...commonFields, 392 ], 393 [notifyNats]: [ 394 { 395 name: "address", 396 required: true, 397 label: "Address", 398 tooltip: "NATS server address e.g. '0.0.0.0:4222'", 399 type: "address", 400 placeholder: "Enter Address", 401 }, 402 { 403 name: "subject", 404 required: true, 405 label: "Subject", 406 tooltip: "NATS subscription subject", 407 type: "string", 408 placeholder: "Enter NATS Subject", 409 }, 410 { 411 name: "username", 412 label: "Username", 413 tooltip: "NATS username", 414 type: "string", 415 placeholder: "Enter NATS Username", 416 }, 417 { 418 name: "password", 419 label: "Password", 420 tooltip: "NATS password", 421 type: "string", 422 placeholder: "Enter NATS password", 423 }, 424 { 425 name: "token", 426 label: "Token", 427 tooltip: "NATS token", 428 type: "string", 429 placeholder: "Enter NATS token", 430 }, 431 { 432 name: "tls", 433 label: "TLS", 434 tooltip: "Set to 'on' to enable TLS", 435 type: "on|off", 436 }, 437 { 438 name: "tls_skip_verify", 439 label: "TLS Skip Verify", 440 tooltip: 441 'Trust server TLS without verification, defaults to "on" (verify)', 442 type: "on|off", 443 }, 444 { 445 name: "ping_interval", 446 label: "Ping Interval", 447 tooltip: "Client ping commands interval in s,m,h,d. Disabled by default", 448 type: "duration", 449 placeholder: "Enter Ping Interval", 450 }, 451 { 452 name: "streaming", 453 label: "Streaming", 454 tooltip: "Set to 'on' to use streaming NATS server", 455 type: "on|off", 456 }, 457 { 458 name: "streaming_async", 459 label: "Streaming async", 460 tooltip: "Set to 'on' to enable asynchronous publish", 461 type: "on|off", 462 }, 463 { 464 name: "streaming_max_pub_acks_in_flight", 465 label: "Streaming max publish ACKS in flight", 466 tooltip: "Number of messages to publish without waiting for ACKs", 467 type: "number", 468 placeholder: "Enter Streaming in flight value", 469 }, 470 { 471 name: "streaming_cluster_id", 472 label: "Streaming Cluster ID", 473 tooltip: "Unique ID for NATS streaming cluster", 474 type: "string", 475 placeholder: "Enter Streaming Cluster ID", 476 }, 477 { 478 name: "cert_authority", 479 label: "Cert Authority", 480 tooltip: "Path to certificate chain of the target NATS server", 481 type: "string", 482 placeholder: "Enter Cert Authority", 483 }, 484 { 485 name: "client_cert", 486 label: "Client Cert", 487 tooltip: "Client cert for NATS mTLS auth", 488 type: "string", 489 placeholder: "Enter Client Cert", 490 }, 491 { 492 name: "client_key", 493 label: "Client Key", 494 tooltip: "Client cert key for NATS mTLS authorization", 495 type: "string", 496 placeholder: "Enter Client Key", 497 }, 498 ...commonFields, 499 ], 500 [notifyElasticsearch]: [ 501 { 502 name: "url", 503 required: true, 504 label: "URL", 505 tooltip: 506 "Elasticsearch server's address, with optional authentication info", 507 type: "url", 508 placeholder: "Enter URL", 509 }, 510 { 511 name: "index", 512 required: true, 513 label: "Index", 514 tooltip: 515 "Elasticsearch index to store/update events, index is auto-created", 516 type: "string", 517 placeholder: "Enter Index", 518 }, 519 { 520 name: "format", 521 required: true, 522 label: "Format", 523 tooltip: 524 "'namespace' reflects current bucket/object list and 'access' reflects a journal of object operations, defaults to 'namespace'", 525 type: "enum", 526 placeholder: "Enter Format", 527 }, 528 ...commonFields, 529 ], 530 [notifyWebhooks]: [ 531 { 532 name: "endpoint", 533 required: true, 534 label: "Endpoint", 535 tooltip: 536 "Webhook server endpoint e.g. http://localhost:8080/minio/events", 537 type: "url", 538 placeholder: "Enter Endpoint", 539 }, 540 { 541 name: "auth_token", 542 label: "Auth Token", 543 tooltip: "Opaque string or JWT authorization token", 544 type: "string", 545 placeholder: "Enter auth_token", 546 }, 547 ...commonFields, 548 ], 549 [notifyNsq]: [ 550 { 551 name: "nsqd_address", 552 required: true, 553 label: "NSQD Address", 554 tooltip: "NSQ server address e.g. '127.0.0.1:4150'", 555 type: "address", 556 placeholder: "Enter nsqd_address", 557 }, 558 { 559 name: "topic", 560 required: true, 561 label: "Topic", 562 tooltip: "NSQ topic", 563 type: "string", 564 placeholder: "Enter Topic", 565 }, 566 { 567 name: "tls", 568 label: "TLS", 569 tooltip: "Set to 'on' to enable TLS", 570 type: "on|off", 571 }, 572 { 573 name: "tls_skip_verify", 574 label: "TLS Skip Verify", 575 tooltip: 576 'Trust server TLS without verification, defaults to "on" (verify)', 577 type: "on|off", 578 }, 579 ...commonFields, 580 ], 581 }; 582 583 const serviceToConfigMap: Record<string, string> = { 584 webhook: "notify_webhook", 585 amqp: "notify_amqp", 586 kafka: "notify_kafka", 587 mqtt: "notify_mqtt", 588 nats: "notify_nats", 589 nsq: "notify_nsq", 590 mysql: "notify_mysql", 591 postgresql: "notify_postgres", //looks different in server response(postgresql as opposed to postgres) from api/admin_notification_endpoints.go 592 elasticsearch: "notify_elasticsearch", 593 redis: "notify_redis", 594 }; 595 596 export const getNotificationConfigKey = (serviceName: string) => { 597 return serviceToConfigMap[serviceName]; 598 };