storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/config/notify/legacy.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2019 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package notify
    18  
    19  import (
    20  	"fmt"
    21  	"strconv"
    22  	"strings"
    23  
    24  	"storj.io/minio/cmd/config"
    25  	"storj.io/minio/pkg/event/target"
    26  )
    27  
    28  // SetNotifyKafka - helper for config migration from older config.
    29  func SetNotifyKafka(s config.Config, kName string, cfg target.KafkaArgs) error {
    30  	if !cfg.Enable {
    31  		return nil
    32  	}
    33  
    34  	if err := cfg.Validate(); err != nil {
    35  		return err
    36  	}
    37  
    38  	s[config.NotifyKafkaSubSys][kName] = config.KVS{
    39  		config.KV{
    40  			Key:   config.Enable,
    41  			Value: config.EnableOn,
    42  		},
    43  		config.KV{
    44  			Key: target.KafkaBrokers,
    45  			Value: func() string {
    46  				var brokers []string
    47  				for _, broker := range cfg.Brokers {
    48  					brokers = append(brokers, broker.String())
    49  				}
    50  				return strings.Join(brokers, config.ValueSeparator)
    51  			}(),
    52  		},
    53  		config.KV{
    54  			Key:   target.KafkaTopic,
    55  			Value: cfg.Topic,
    56  		},
    57  		config.KV{
    58  			Key:   target.KafkaQueueDir,
    59  			Value: cfg.QueueDir,
    60  		},
    61  		config.KV{
    62  			Key:   target.KafkaClientTLSCert,
    63  			Value: cfg.TLS.ClientTLSCert,
    64  		},
    65  		config.KV{
    66  			Key:   target.KafkaClientTLSKey,
    67  			Value: cfg.TLS.ClientTLSKey,
    68  		},
    69  		config.KV{
    70  			Key:   target.KafkaQueueLimit,
    71  			Value: strconv.Itoa(int(cfg.QueueLimit)),
    72  		},
    73  		config.KV{
    74  			Key:   target.KafkaTLS,
    75  			Value: config.FormatBool(cfg.TLS.Enable),
    76  		},
    77  		config.KV{
    78  			Key:   target.KafkaTLSSkipVerify,
    79  			Value: config.FormatBool(cfg.TLS.SkipVerify),
    80  		},
    81  		config.KV{
    82  			Key:   target.KafkaTLSClientAuth,
    83  			Value: strconv.Itoa(int(cfg.TLS.ClientAuth)),
    84  		},
    85  		config.KV{
    86  			Key:   target.KafkaSASL,
    87  			Value: config.FormatBool(cfg.SASL.Enable),
    88  		},
    89  		config.KV{
    90  			Key:   target.KafkaSASLUsername,
    91  			Value: cfg.SASL.User,
    92  		},
    93  		config.KV{
    94  			Key:   target.KafkaSASLPassword,
    95  			Value: cfg.SASL.Password,
    96  		},
    97  	}
    98  	return nil
    99  }
   100  
   101  // SetNotifyAMQP - helper for config migration from older config.
   102  func SetNotifyAMQP(s config.Config, amqpName string, cfg target.AMQPArgs) error {
   103  	if !cfg.Enable {
   104  		return nil
   105  	}
   106  
   107  	if err := cfg.Validate(); err != nil {
   108  		return err
   109  	}
   110  
   111  	s[config.NotifyAMQPSubSys][amqpName] = config.KVS{
   112  		config.KV{
   113  			Key:   config.Enable,
   114  			Value: config.EnableOn,
   115  		},
   116  		config.KV{
   117  			Key:   target.AmqpURL,
   118  			Value: cfg.URL.String(),
   119  		},
   120  		config.KV{
   121  			Key:   target.AmqpExchange,
   122  			Value: cfg.Exchange,
   123  		},
   124  		config.KV{
   125  			Key:   target.AmqpRoutingKey,
   126  			Value: cfg.RoutingKey,
   127  		},
   128  		config.KV{
   129  			Key:   target.AmqpExchangeType,
   130  			Value: cfg.ExchangeType,
   131  		},
   132  		config.KV{
   133  			Key:   target.AmqpDeliveryMode,
   134  			Value: strconv.Itoa(int(cfg.DeliveryMode)),
   135  		},
   136  		config.KV{
   137  			Key:   target.AmqpMandatory,
   138  			Value: config.FormatBool(cfg.Mandatory),
   139  		},
   140  		config.KV{
   141  			Key:   target.AmqpInternal,
   142  			Value: config.FormatBool(cfg.Immediate),
   143  		},
   144  		config.KV{
   145  			Key:   target.AmqpDurable,
   146  			Value: config.FormatBool(cfg.Durable),
   147  		},
   148  		config.KV{
   149  			Key:   target.AmqpNoWait,
   150  			Value: config.FormatBool(cfg.NoWait),
   151  		},
   152  		config.KV{
   153  			Key:   target.AmqpAutoDeleted,
   154  			Value: config.FormatBool(cfg.AutoDeleted),
   155  		},
   156  		config.KV{
   157  			Key:   target.AmqpQueueDir,
   158  			Value: cfg.QueueDir,
   159  		},
   160  		config.KV{
   161  			Key:   target.AmqpQueueLimit,
   162  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   163  		},
   164  	}
   165  
   166  	return nil
   167  }
   168  
   169  // SetNotifyES - helper for config migration from older config.
   170  func SetNotifyES(s config.Config, esName string, cfg target.ElasticsearchArgs) error {
   171  	if !cfg.Enable {
   172  		return nil
   173  	}
   174  
   175  	if err := cfg.Validate(); err != nil {
   176  		return err
   177  	}
   178  
   179  	s[config.NotifyESSubSys][esName] = config.KVS{
   180  		config.KV{
   181  			Key:   config.Enable,
   182  			Value: config.EnableOn,
   183  		},
   184  		config.KV{
   185  			Key:   target.ElasticFormat,
   186  			Value: cfg.Format,
   187  		},
   188  		config.KV{
   189  			Key:   target.ElasticURL,
   190  			Value: cfg.URL.String(),
   191  		},
   192  		config.KV{
   193  			Key:   target.ElasticIndex,
   194  			Value: cfg.Index,
   195  		},
   196  		config.KV{
   197  			Key:   target.ElasticQueueDir,
   198  			Value: cfg.QueueDir,
   199  		},
   200  		config.KV{
   201  			Key:   target.ElasticQueueLimit,
   202  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   203  		},
   204  		config.KV{
   205  			Key:   target.ElasticUsername,
   206  			Value: cfg.Username,
   207  		},
   208  		config.KV{
   209  			Key:   target.ElasticPassword,
   210  			Value: cfg.Password,
   211  		},
   212  	}
   213  
   214  	return nil
   215  }
   216  
   217  // SetNotifyRedis - helper for config migration from older config.
   218  func SetNotifyRedis(s config.Config, redisName string, cfg target.RedisArgs) error {
   219  	if !cfg.Enable {
   220  		return nil
   221  	}
   222  
   223  	if err := cfg.Validate(); err != nil {
   224  		return err
   225  	}
   226  
   227  	s[config.NotifyRedisSubSys][redisName] = config.KVS{
   228  		config.KV{
   229  			Key:   config.Enable,
   230  			Value: config.EnableOn,
   231  		},
   232  		config.KV{
   233  			Key:   target.RedisFormat,
   234  			Value: cfg.Format,
   235  		},
   236  		config.KV{
   237  			Key:   target.RedisAddress,
   238  			Value: cfg.Addr.String(),
   239  		},
   240  		config.KV{
   241  			Key:   target.RedisPassword,
   242  			Value: cfg.Password,
   243  		},
   244  		config.KV{
   245  			Key:   target.RedisKey,
   246  			Value: cfg.Key,
   247  		},
   248  		config.KV{
   249  			Key:   target.RedisQueueDir,
   250  			Value: cfg.QueueDir,
   251  		},
   252  		config.KV{
   253  			Key:   target.RedisQueueLimit,
   254  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   255  		},
   256  	}
   257  
   258  	return nil
   259  }
   260  
   261  // SetNotifyWebhook - helper for config migration from older config.
   262  func SetNotifyWebhook(s config.Config, whName string, cfg target.WebhookArgs) error {
   263  	if !cfg.Enable {
   264  		return nil
   265  	}
   266  
   267  	if err := cfg.Validate(); err != nil {
   268  		return err
   269  	}
   270  
   271  	s[config.NotifyWebhookSubSys][whName] = config.KVS{
   272  		config.KV{
   273  			Key:   config.Enable,
   274  			Value: config.EnableOn,
   275  		},
   276  		config.KV{
   277  			Key:   target.WebhookEndpoint,
   278  			Value: cfg.Endpoint.String(),
   279  		},
   280  		config.KV{
   281  			Key:   target.WebhookAuthToken,
   282  			Value: cfg.AuthToken,
   283  		},
   284  		config.KV{
   285  			Key:   target.WebhookQueueDir,
   286  			Value: cfg.QueueDir,
   287  		},
   288  		config.KV{
   289  			Key:   target.WebhookQueueLimit,
   290  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   291  		},
   292  		config.KV{
   293  			Key:   target.WebhookClientCert,
   294  			Value: cfg.ClientCert,
   295  		},
   296  		config.KV{
   297  			Key:   target.WebhookClientKey,
   298  			Value: cfg.ClientKey,
   299  		},
   300  	}
   301  
   302  	return nil
   303  }
   304  
   305  // SetNotifyPostgres - helper for config migration from older config.
   306  func SetNotifyPostgres(s config.Config, psqName string, cfg target.PostgreSQLArgs) error {
   307  	if !cfg.Enable {
   308  		return nil
   309  	}
   310  
   311  	if err := cfg.Validate(); err != nil {
   312  		return err
   313  	}
   314  
   315  	s[config.NotifyPostgresSubSys][psqName] = config.KVS{
   316  		config.KV{
   317  			Key:   config.Enable,
   318  			Value: config.EnableOn,
   319  		},
   320  		config.KV{
   321  			Key:   target.PostgresFormat,
   322  			Value: cfg.Format,
   323  		},
   324  		config.KV{
   325  			Key:   target.PostgresConnectionString,
   326  			Value: cfg.ConnectionString,
   327  		},
   328  		config.KV{
   329  			Key:   target.PostgresTable,
   330  			Value: cfg.Table,
   331  		},
   332  		config.KV{
   333  			Key:   target.PostgresHost,
   334  			Value: cfg.Host.String(),
   335  		},
   336  		config.KV{
   337  			Key:   target.PostgresPort,
   338  			Value: cfg.Port,
   339  		},
   340  		config.KV{
   341  			Key:   target.PostgresUsername,
   342  			Value: cfg.Username,
   343  		},
   344  		config.KV{
   345  			Key:   target.PostgresPassword,
   346  			Value: cfg.Password,
   347  		},
   348  		config.KV{
   349  			Key:   target.PostgresDatabase,
   350  			Value: cfg.Database,
   351  		},
   352  		config.KV{
   353  			Key:   target.PostgresQueueDir,
   354  			Value: cfg.QueueDir,
   355  		},
   356  		config.KV{
   357  			Key:   target.PostgresQueueLimit,
   358  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   359  		},
   360  		config.KV{
   361  			Key:   target.PostgresMaxOpenConnections,
   362  			Value: strconv.Itoa(cfg.MaxOpenConnections),
   363  		},
   364  	}
   365  
   366  	return nil
   367  }
   368  
   369  // SetNotifyNSQ - helper for config migration from older config.
   370  func SetNotifyNSQ(s config.Config, nsqName string, cfg target.NSQArgs) error {
   371  	if !cfg.Enable {
   372  		return nil
   373  	}
   374  
   375  	if err := cfg.Validate(); err != nil {
   376  		return err
   377  	}
   378  
   379  	s[config.NotifyNSQSubSys][nsqName] = config.KVS{
   380  		config.KV{
   381  			Key:   config.Enable,
   382  			Value: config.EnableOn,
   383  		},
   384  		config.KV{
   385  			Key:   target.NSQAddress,
   386  			Value: cfg.NSQDAddress.String(),
   387  		},
   388  		config.KV{
   389  			Key:   target.NSQTopic,
   390  			Value: cfg.Topic,
   391  		},
   392  		config.KV{
   393  			Key:   target.NSQTLS,
   394  			Value: config.FormatBool(cfg.TLS.Enable),
   395  		},
   396  		config.KV{
   397  			Key:   target.NSQTLSSkipVerify,
   398  			Value: config.FormatBool(cfg.TLS.SkipVerify),
   399  		},
   400  		config.KV{
   401  			Key:   target.NSQQueueDir,
   402  			Value: cfg.QueueDir,
   403  		},
   404  		config.KV{
   405  			Key:   target.NSQQueueLimit,
   406  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   407  		},
   408  	}
   409  
   410  	return nil
   411  }
   412  
   413  // SetNotifyNATS - helper for config migration from older config.
   414  func SetNotifyNATS(s config.Config, natsName string, cfg target.NATSArgs) error {
   415  	if !cfg.Enable {
   416  		return nil
   417  	}
   418  
   419  	if err := cfg.Validate(); err != nil {
   420  		return err
   421  	}
   422  
   423  	s[config.NotifyNATSSubSys][natsName] = config.KVS{
   424  		config.KV{
   425  			Key:   config.Enable,
   426  			Value: config.EnableOn,
   427  		},
   428  		config.KV{
   429  			Key:   target.NATSAddress,
   430  			Value: cfg.Address.String(),
   431  		},
   432  		config.KV{
   433  			Key:   target.NATSSubject,
   434  			Value: cfg.Subject,
   435  		},
   436  		config.KV{
   437  			Key:   target.NATSUsername,
   438  			Value: cfg.Username,
   439  		},
   440  		config.KV{
   441  			Key:   target.NATSPassword,
   442  			Value: cfg.Password,
   443  		},
   444  		config.KV{
   445  			Key:   target.NATSToken,
   446  			Value: cfg.Token,
   447  		},
   448  		config.KV{
   449  			Key:   target.NATSCertAuthority,
   450  			Value: cfg.CertAuthority,
   451  		},
   452  		config.KV{
   453  			Key:   target.NATSClientCert,
   454  			Value: cfg.ClientCert,
   455  		},
   456  		config.KV{
   457  			Key:   target.NATSClientKey,
   458  			Value: cfg.ClientKey,
   459  		},
   460  		config.KV{
   461  			Key:   target.NATSTLS,
   462  			Value: config.FormatBool(cfg.Secure),
   463  		},
   464  		config.KV{
   465  			Key:   target.NATSTLSSkipVerify,
   466  			Value: config.FormatBool(cfg.Secure),
   467  		},
   468  		config.KV{
   469  			Key:   target.NATSPingInterval,
   470  			Value: strconv.FormatInt(cfg.PingInterval, 10),
   471  		},
   472  		config.KV{
   473  			Key:   target.NATSQueueDir,
   474  			Value: cfg.QueueDir,
   475  		},
   476  		config.KV{
   477  			Key:   target.NATSQueueLimit,
   478  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   479  		},
   480  		config.KV{
   481  			Key: target.NATSStreaming,
   482  			Value: func() string {
   483  				if cfg.Streaming.Enable {
   484  					return config.EnableOn
   485  				}
   486  				return config.EnableOff
   487  			}(),
   488  		},
   489  		config.KV{
   490  			Key:   target.NATSStreamingClusterID,
   491  			Value: cfg.Streaming.ClusterID,
   492  		},
   493  		config.KV{
   494  			Key:   target.NATSStreamingAsync,
   495  			Value: config.FormatBool(cfg.Streaming.Async),
   496  		},
   497  		config.KV{
   498  			Key:   target.NATSStreamingMaxPubAcksInFlight,
   499  			Value: strconv.Itoa(cfg.Streaming.MaxPubAcksInflight),
   500  		},
   501  	}
   502  
   503  	return nil
   504  }
   505  
   506  // SetNotifyMySQL - helper for config migration from older config.
   507  func SetNotifyMySQL(s config.Config, sqlName string, cfg target.MySQLArgs) error {
   508  	if !cfg.Enable {
   509  		return nil
   510  	}
   511  
   512  	if err := cfg.Validate(); err != nil {
   513  		return err
   514  	}
   515  
   516  	s[config.NotifyMySQLSubSys][sqlName] = config.KVS{
   517  		config.KV{
   518  			Key:   config.Enable,
   519  			Value: config.EnableOn,
   520  		},
   521  		config.KV{
   522  			Key:   target.MySQLFormat,
   523  			Value: cfg.Format,
   524  		},
   525  		config.KV{
   526  			Key:   target.MySQLDSNString,
   527  			Value: cfg.DSN,
   528  		},
   529  		config.KV{
   530  			Key:   target.MySQLTable,
   531  			Value: cfg.Table,
   532  		},
   533  		config.KV{
   534  			Key:   target.MySQLHost,
   535  			Value: cfg.Host.String(),
   536  		},
   537  		config.KV{
   538  			Key:   target.MySQLPort,
   539  			Value: cfg.Port,
   540  		},
   541  		config.KV{
   542  			Key:   target.MySQLUsername,
   543  			Value: cfg.User,
   544  		},
   545  		config.KV{
   546  			Key:   target.MySQLPassword,
   547  			Value: cfg.Password,
   548  		},
   549  		config.KV{
   550  			Key:   target.MySQLDatabase,
   551  			Value: cfg.Database,
   552  		},
   553  		config.KV{
   554  			Key:   target.MySQLQueueDir,
   555  			Value: cfg.QueueDir,
   556  		},
   557  		config.KV{
   558  			Key:   target.MySQLQueueLimit,
   559  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   560  		},
   561  		config.KV{
   562  			Key:   target.MySQLMaxOpenConnections,
   563  			Value: strconv.Itoa(cfg.MaxOpenConnections),
   564  		},
   565  	}
   566  
   567  	return nil
   568  }
   569  
   570  // SetNotifyMQTT - helper for config migration from older config.
   571  func SetNotifyMQTT(s config.Config, mqttName string, cfg target.MQTTArgs) error {
   572  	if !cfg.Enable {
   573  		return nil
   574  	}
   575  
   576  	if err := cfg.Validate(); err != nil {
   577  		return err
   578  	}
   579  
   580  	s[config.NotifyMQTTSubSys][mqttName] = config.KVS{
   581  		config.KV{
   582  			Key:   config.Enable,
   583  			Value: config.EnableOn,
   584  		},
   585  		config.KV{
   586  			Key:   target.MqttBroker,
   587  			Value: cfg.Broker.String(),
   588  		},
   589  		config.KV{
   590  			Key:   target.MqttTopic,
   591  			Value: cfg.Topic,
   592  		},
   593  		config.KV{
   594  			Key:   target.MqttQoS,
   595  			Value: fmt.Sprintf("%d", cfg.QoS),
   596  		},
   597  		config.KV{
   598  			Key:   target.MqttUsername,
   599  			Value: cfg.User,
   600  		},
   601  		config.KV{
   602  			Key:   target.MqttPassword,
   603  			Value: cfg.Password,
   604  		},
   605  		config.KV{
   606  			Key:   target.MqttReconnectInterval,
   607  			Value: cfg.MaxReconnectInterval.String(),
   608  		},
   609  		config.KV{
   610  			Key:   target.MqttKeepAliveInterval,
   611  			Value: cfg.KeepAlive.String(),
   612  		},
   613  		config.KV{
   614  			Key:   target.MqttQueueDir,
   615  			Value: cfg.QueueDir,
   616  		},
   617  		config.KV{
   618  			Key:   target.MqttQueueLimit,
   619  			Value: strconv.Itoa(int(cfg.QueueLimit)),
   620  		},
   621  	}
   622  
   623  	return nil
   624  }