func (f *influxPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
	cp := cpolicy.New()
	config := cpolicy.NewPolicyNode()

	r1, err := cpolicy.NewStringRule("host", true)
	handleErr(err)
	r1.Description = "Influxdb host"
	config.Add(r1)

	r2, err := cpolicy.NewIntegerRule("port", true)
	handleErr(err)
	r2.Description = "Influxdb port"
	config.Add(r2)

	r3, err := cpolicy.NewStringRule("database", true)
	handleErr(err)
	r3.Description = "Influxdb db name"
	config.Add(r3)

	r4, err := cpolicy.NewStringRule("user", true)
	handleErr(err)
	r4.Description = "Influxdb user"
	config.Add(r4)

	r5, err := cpolicy.NewStringRule("password", true)
	handleErr(err)
	r5.Description = "Influxdb password"
	config.Add(r5)

	r6, err := cpolicy.NewStringRule("retention", false, "autogen")
	handleErr(err)
	r6.Description = "Influxdb retention policy"
	config.Add(r6)

	r7, err := cpolicy.NewBoolRule("https", false, false)
	handleErr(err)
	r7.Description = "Influxdb HTTPS connection"
	config.Add(r7)

	r8, err := cpolicy.NewBoolRule("skip-verify", false, false)
	handleErr(err)
	r8.Description = "Influxdb HTTPS Skip certificate verification"
	config.Add(r8)

	r9, err := cpolicy.NewStringRule("precision", false, "s")
	handleErr(err)
	r9.Description = "Influxdb timestamp precision"
	config.Add(r9)

	cp.Add([]string{""}, config)
	return cp, nil
}
func (rmq *rmqPublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
	cp := cpolicy.New()
	config := cpolicy.NewPolicyNode()

	r1, err := cpolicy.NewStringRule("uri", true)
	handleErr(err)
	r1.Description = "RabbitMQ URI (user:password@ip:port/vhost)"
	config.Add(r1)

	r2, err := cpolicy.NewStringRule("exchange_name", true)
	handleErr(err)
	r2.Description = "RabbitMQ Exchange Name"
	config.Add(r2)

	r3, err := cpolicy.NewStringRule("exchange_type", true)
	handleErr(err)
	r3.Description = "RabbitMQ Exchange Type"
	config.Add(r3)

	r4, err := cpolicy.NewStringRule("routing_key", true)
	handleErr(err)
	r4.Description = "RabbitMQ Routing Key"
	config.Add(r4)

	r5, err := cpolicy.NewBoolRule("durable", false, true)
	handleErr(err)
	r5.Description = "RabbitMQ Durable"
	config.Add(r5)

	cp.Add([]string{""}, config)
	return cp, nil
}
Пример #3
0
func (p *mockPlugin) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
	cp := cpolicy.New()
	cpn := cpolicy.NewPolicyNode()
	r1, _ := cpolicy.NewStringRule("username", false, "root")
	r2, _ := cpolicy.NewStringRule("password", true)
	r3, _ := cpolicy.NewBoolRule("bool_rule_default_true", false, true)
	r4, _ := cpolicy.NewBoolRule("bool_rule_default_false", false, false)
	r5, _ := cpolicy.NewIntegerRule("integer_rule", true, 1234)
	r5.SetMaximum(9999)
	r5.SetMinimum(1000)
	r6, _ := cpolicy.NewFloatRule("float_rule", true, 0.1234)
	r6.SetMaximum(.9999)
	r6.SetMinimum(.001)
	cpn.Add(r1, r2, r3, r4, r5, r6)
	ns := []string{"one", "two", "potato"}
	cp.Add(ns, cpn)

	return cp, nil
}
Пример #4
0
func (p *passthruProcessor) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
	cp := cpolicy.New()
	config := cpolicy.NewPolicyNode()

	r1, err := cpolicy.NewBoolRule(debug, false)
	if err != nil {
		panic(err)
	}
	r1.Description = "Debug mode"
	config.Add(r1)

	cp.Add([]string{""}, config)
	return cp, nil
}
Пример #5
0
func (f *filePublisher) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) {
	cp := cpolicy.New()
	config := cpolicy.NewPolicyNode()

	r1, err := cpolicy.NewStringRule("file", true)
	handleErr(err)
	r1.Description = "Absolute path to the output file for publishing"

	r2, err := cpolicy.NewBoolRule(debug, false)
	handleErr(err)
	r2.Description = "Debug mode"

	config.Add(r1)
	cp.Add([]string{""}, config)
	return cp, nil
}
Пример #6
0
func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy {
	result := cpolicy.New()
	nodes := make(map[string]*cpolicy.ConfigPolicyNode)
	for k, v := range reply.BoolPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			var br *cpolicy.BoolRule
			var err error
			if val.HasDefault {
				br, err = cpolicy.NewBoolRule(key, val.Required, val.Default)
			} else {
				br, err = cpolicy.NewBoolRule(key, val.Required)
			}
			if err != nil {
				rpcLogger.Warn("Empty key found with value %v", val)
				continue
			}
			nodes[k].Add(br)
		}
	}

	for k, v := range reply.StringPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			var sr *cpolicy.StringRule
			var err error
			if val.HasDefault {
				sr, err = cpolicy.NewStringRule(key, val.Required, val.Default)
			} else {
				sr, err = cpolicy.NewStringRule(key, val.Required)
			}
			if err != nil {
				rpcLogger.Warn("Empty key found with value %v", val)
				continue
			}

			nodes[k].Add(sr)
		}
	}

	for k, v := range reply.IntegerPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			var ir *cpolicy.IntRule
			var err error
			if val.HasDefault {
				ir, err = cpolicy.NewIntegerRule(key, val.Required, int(val.Default))
			} else {
				ir, err = cpolicy.NewIntegerRule(key, val.Required)
			}
			if err != nil {
				rpcLogger.Warn("Empty key found with value %v", val)
				continue
			}
			if val.HasMin {
				ir.SetMinimum(int(val.Minimum))
			}
			if val.HasMax {
				ir.SetMaximum(int(val.Maximum))
			}

			nodes[k].Add(ir)
		}
	}

	for k, v := range reply.FloatPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			var fr *cpolicy.FloatRule
			var err error
			if val.HasDefault {
				fr, err = cpolicy.NewFloatRule(key, val.Required)
			} else {

				fr, err = cpolicy.NewFloatRule(key, val.Required)
			}
			if err != nil {
				rpcLogger.Warn("Empty key found with value %v", val)
				continue
			}

			if val.HasMin {
				fr.SetMinimum(val.Minimum)
			}
			if val.HasMax {
				fr.SetMaximum(val.Maximum)
			}

			nodes[k].Add(fr)
		}
	}

	for key, node := range nodes {
		keys := strings.Split(key, ".")
		result.Add(keys, node)
	}

	return result
}
Пример #7
0
func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy {
	result := cpolicy.New()
	nodes := make(map[string]*cpolicy.ConfigPolicyNode)
	for k, v := range reply.BoolPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			br, err := cpolicy.NewBoolRule(key, val.Required, val.Default)
			if err != nil {
				// The only error that can be thrown is empty key error, ignore something with empty key
				continue
			}
			nodes[k].Add(br)
		}
	}

	for k, v := range reply.StringPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			sr, err := cpolicy.NewStringRule(key, val.Required, val.Default)
			if err != nil {
				continue
			}

			nodes[k].Add(sr)
		}
	}

	for k, v := range reply.IntegerPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			sr, err := cpolicy.NewIntegerRule(key, val.Required, int(val.Default))
			if err != nil {
				continue
			}

			nodes[k].Add(sr)
		}
	}

	for k, v := range reply.FloatPolicy {
		if _, ok := nodes[k]; !ok {
			nodes[k] = cpolicy.NewPolicyNode()
		}
		for key, val := range v.Rules {
			sr, err := cpolicy.NewFloatRule(key, val.Required, val.Default)
			if err != nil {
				continue
			}

			nodes[k].Add(sr)
		}
	}

	for key, node := range nodes {
		keys := strings.Split(key, ".")
		result.Add(keys, node)
	}

	return result
}