github.com/mattermosttest/mattermost-server/v5@v5.0.0-20200917143240-9dfa12e121f9/model/system.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See LICENSE.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"encoding/json"
     8  	"io"
     9  	"math/big"
    10  )
    11  
    12  const (
    13  	SYSTEM_DIAGNOSTIC_ID                          = "DiagnosticId"
    14  	SYSTEM_RAN_UNIT_TESTS                         = "RanUnitTests"
    15  	SYSTEM_LAST_SECURITY_TIME                     = "LastSecurityTime"
    16  	SYSTEM_ACTIVE_LICENSE_ID                      = "ActiveLicenseId"
    17  	SYSTEM_LAST_COMPLIANCE_TIME                   = "LastComplianceTime"
    18  	SYSTEM_ASYMMETRIC_SIGNING_KEY                 = "AsymmetricSigningKey"
    19  	SYSTEM_POST_ACTION_COOKIE_SECRET              = "PostActionCookieSecret"
    20  	SYSTEM_INSTALLATION_DATE_KEY                  = "InstallationDate"
    21  	SYSTEM_FIRST_SERVER_RUN_TIMESTAMP_KEY         = "FirstServerRunTimestamp"
    22  	SYSTEM_CLUSTER_ENCRYPTION_KEY                 = "ClusterEncryptionKey"
    23  	SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_200 = "warn_metric_number_of_active_users_200"
    24  	SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_400 = "warn_metric_number_of_active_users_400"
    25  	SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_500 = "warn_metric_number_of_active_users_500"
    26  )
    27  
    28  const (
    29  	WARN_METRIC_STATUS_LIMIT_REACHED = "true"
    30  	WARN_METRIC_STATUS_RUNONCE       = "runonce"
    31  	WARN_METRIC_STATUS_ACK           = "ack"
    32  	WARN_METRIC_STATUS_STORE_PREFIX  = "warn_metric_"
    33  )
    34  
    35  type System struct {
    36  	Name  string `json:"name"`
    37  	Value string `json:"value"`
    38  }
    39  
    40  func (o *System) ToJson() string {
    41  	b, _ := json.Marshal(o)
    42  	return string(b)
    43  }
    44  
    45  func SystemFromJson(data io.Reader) *System {
    46  	var o *System
    47  	json.NewDecoder(data).Decode(&o)
    48  	return o
    49  }
    50  
    51  type SystemPostActionCookieSecret struct {
    52  	Secret []byte `json:"key,omitempty"`
    53  }
    54  
    55  type SystemAsymmetricSigningKey struct {
    56  	ECDSAKey *SystemECDSAKey `json:"ecdsa_key,omitempty"`
    57  }
    58  
    59  type SystemECDSAKey struct {
    60  	Curve string   `json:"curve"`
    61  	X     *big.Int `json:"x"`
    62  	Y     *big.Int `json:"y"`
    63  	D     *big.Int `json:"d,omitempty"`
    64  }
    65  
    66  // ServerBusyState provides serialization for app.Busy.
    67  type ServerBusyState struct {
    68  	Busy       bool   `json:"busy"`
    69  	Expires    int64  `json:"expires"`
    70  	Expires_ts string `json:"expires_ts,omitempty"`
    71  }
    72  
    73  func (sbs *ServerBusyState) ToJson() string {
    74  	b, _ := json.Marshal(sbs)
    75  	return string(b)
    76  }
    77  
    78  func ServerBusyStateFromJson(r io.Reader) *ServerBusyState {
    79  	var sbs *ServerBusyState
    80  	json.NewDecoder(r).Decode(&sbs)
    81  	return sbs
    82  }
    83  
    84  var WarnMetricsTable = map[string]WarnMetric{
    85  	SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_200: {
    86  		Id:        SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_200,
    87  		Limit:     200,
    88  		IsBotOnly: true,
    89  		IsRunOnce: true,
    90  	},
    91  	SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_400: {
    92  		Id:        SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_400,
    93  		Limit:     400,
    94  		IsBotOnly: true,
    95  		IsRunOnce: true,
    96  	},
    97  	SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_500: {
    98  		Id:        SYSTEM_WARN_METRIC_NUMBER_OF_ACTIVE_USERS_500,
    99  		Limit:     500,
   100  		IsBotOnly: false,
   101  		IsRunOnce: false,
   102  	},
   103  }
   104  
   105  type WarnMetric struct {
   106  	Id        string
   107  	Limit     int64
   108  	IsBotOnly bool
   109  	IsRunOnce bool
   110  }
   111  
   112  type WarnMetricDisplayTexts struct {
   113  	BotTitle       string
   114  	BotMessageBody string
   115  	BotMailToBody  string
   116  	EmailBody      string
   117  }
   118  type WarnMetricStatus struct {
   119  	Id          string `json:"id"`
   120  	Limit       int64  `json:"limit"`
   121  	Acked       bool   `json:"acked"`
   122  	StoreStatus string `json:"store_status,omitempty"`
   123  }
   124  
   125  func (wms *WarnMetricStatus) ToJson() string {
   126  	b, _ := json.Marshal(wms)
   127  	return string(b)
   128  }
   129  
   130  func WarnMetricStatusFromJson(data io.Reader) *WarnMetricStatus {
   131  	var o WarnMetricStatus
   132  	if err := json.NewDecoder(data).Decode(&o); err != nil {
   133  		return nil
   134  	} else {
   135  		return &o
   136  	}
   137  }
   138  
   139  func MapWarnMetricStatusToJson(o map[string]*WarnMetricStatus) string {
   140  	b, _ := json.Marshal(o)
   141  	return string(b)
   142  }
   143  
   144  type SendWarnMetricAck struct {
   145  	ForceAck bool `json:"forceAck"`
   146  }
   147  
   148  func (swma *SendWarnMetricAck) ToJson() string {
   149  	b, _ := json.Marshal(swma)
   150  	return string(b)
   151  }
   152  
   153  func SendWarnMetricAckFromJson(r io.Reader) *SendWarnMetricAck {
   154  	var swma *SendWarnMetricAck
   155  	json.NewDecoder(r).Decode(&swma)
   156  	return swma
   157  }