Esempio n. 1
0
 public bool HandlesOption(NsqConfig c, string option)
 {
     switch (option)
     {
     case "tls_min_version":
     case "tls_check_certificate_revocation":
     case "tls_insecure_skip_verify":
         return(true);
     }
     return(false);
 }
Esempio n. 2
0
            public void Set(NsqConfig c, string option, object value)
            {
                var tlsConfig = c.TlsConfig != null
                                    ? c.TlsConfig.Clone()
                                    : new TlsConfig();

                switch (option)
                {
                case "tls_min_version":
                    var version = (string)value;
                    switch (version)
                    {
                    case "ssl3.0":
                        tlsConfig.MinVersion = SslProtocols.Ssl3;
                        break;

                    case "tls1.0":
                        tlsConfig.MinVersion = SslProtocols.Tls;
                        break;

#if !NETFX_3_5 && !NETFX_4_0
                    case "tls1.1":
                        tlsConfig.MinVersion = SslProtocols.Tls11;
                        break;

                    case "tls1.2":
                        tlsConfig.MinVersion = SslProtocols.Tls12;
                        break;
#endif
                    default:
                        throw new Exception(string.Format("ERROR: {0} is not a tls version", value));
                    }
                    break;

                case "tls_check_certificate_revocation":
                    bool checkCertificationRevocation = value.Coerce <bool>();
                    tlsConfig.CheckCertificateRevocation = checkCertificationRevocation;
                    break;

                case "tls_insecure_skip_verify":
                    bool insecureSkipVerify = value.Coerce <bool>();
                    tlsConfig.InsecureSkipVerify = insecureSkipVerify;
                    break;

                default:
                    throw new Exception(string.Format("unknown option {0}", option));
                }

                c.TlsConfig = tlsConfig;
            }
Esempio n. 3
0
            public bool HandlesOption(NsqConfig c, string option)
            {
                var typ = c.GetType();

                foreach (var field in typ.GetProperties())
                {
                    var opt = field.Get <OptAttribute>();
                    if (opt != null && opt.Name == option)
                    {
                        return(true);
                    }
                }

                return(false);
            }
Esempio n. 4
0
            public void Validate(NsqConfig c)
            {
                var typ = c.GetType();

                foreach (var field in typ.GetProperties())
                {
                    MinAttribute min = field.Get <MinAttribute>();
                    MaxAttribute max = field.Get <MaxAttribute>();

                    if (min == null && max == null)
                    {
                        continue;
                    }

                    object value = field.GetValue(c, index: null);

                    var opt = field.Get <OptAttribute>();
                    if (min != null)
                    {
                        var coercedMinVal = (IComparable)opt.Coerce(min.Value, field.PropertyType);
                        if (coercedMinVal.CompareTo(value) == 1)
                        {
                            throw new Exception(string.Format("invalid {0} ! {1} < {2}", opt.Name, value, coercedMinVal));
                        }
                    }
                    if (max != null)
                    {
                        var coercedMaxVal = (IComparable)opt.Coerce(max.Value, field.PropertyType);
                        if (coercedMaxVal.CompareTo(value) == -1)
                        {
                            throw new Exception(string.Format("invalid {0} ! {1} > {2}", opt.Name, value, coercedMaxVal));
                        }
                    }
                }

                if (c.HeartbeatInterval > c.ReadTimeout)
                {
                    throw new Exception(string.Format("HeartbeatInterval {0} must be less than ReadTimeout {1}",
                                                      c.HeartbeatInterval, c.ReadTimeout));
                }

                // TODO: PR go-nsq: this check was removed, seems still valid since the value can be set through code
                // https://github.com/nsqio/go-nsq/commit/dd8e5fc4ad80922d884ece51f5574af3fa4f14d3#diff-b4bda758a2aef091432646c354b4dc59L376
                if (c.BackoffStrategy == null)
                {
                    throw new Exception(string.Format("BackoffStrategy cannot be null"));
                }
            }
Esempio n. 5
0
        /// <summary>Clones (makes a copy) of this instance.</summary>
        /// <returns>A copy of this object.</returns>
        public NsqConfig Clone()
        {
            var newConfig = new NsqConfig();

            newConfig.BackoffStrategy = BackoffStrategy;

            var typ = GetType();

            foreach (var field in typ.GetProperties())
            {
                var opt = field.Get <OptAttribute>();
                if (opt != null)
                {
                    newConfig.Set(opt.Name, field.GetValue(this, index: null));
                }
            }

            return(newConfig);
        }
Esempio n. 6
0
            public void Set(NsqConfig c, string option, object value)
            {
                var typ = c.GetType();

                foreach (var field in typ.GetProperties())
                {
                    var opt = field.Get <OptAttribute>();
                    if (opt == null || opt.Name != option)
                    {
                        continue;
                    }

                    var min = field.Get <MinAttribute>();
                    var max = field.Get <MaxAttribute>();

                    var coercedVal = opt.Coerce(value, field.PropertyType);

                    if (min != null)
                    {
                        var coercedMinVal = (IComparable)opt.Coerce(min.Value, field.PropertyType);
                        if (coercedMinVal.CompareTo(coercedVal) == 1)
                        {
                            throw new Exception(string.Format("invalid {0} ! {1} < {2}", opt.Name, coercedVal, coercedMinVal));
                        }
                    }

                    if (max != null)
                    {
                        var coercedMaxVal = (IComparable)opt.Coerce(max.Value, field.PropertyType);
                        if (coercedMaxVal.CompareTo(coercedVal) == -1)
                        {
                            throw new Exception(string.Format("invalid {0} ! {1} > {2}", opt.Name, coercedVal, coercedMaxVal));
                        }
                    }

                    field.SetValue(c, coercedVal, index: null);
                    return;
                }

                throw new Exception(string.Format("unknown option {0}", option));
            }
Esempio n. 7
0
            public void SetDefaults(NsqConfig c)
            {
                Type typ = c.GetType();

                foreach (var field in typ.GetProperties())
                {
                    var opt          = field.Get <OptAttribute>();
                    var defaultValue = field.Get <DefaultAttribute>();
                    if (opt == null || defaultValue == null)
                    {
                        continue;
                    }

                    c.Set(opt.Name, defaultValue.Value);
                }

                string hostname = OS.Hostname();

                c.ClientID  = hostname.Split(new[] { '.' })[0];
                c.Hostname  = hostname;
                c.UserAgent = string.Format("{0}/{1}", ClientInfo.ClientName, ClientInfo.Version);
            }
Esempio n. 8
0
 public void Validate(NsqConfig c)
 {
     // no op
 }