Exemplo n.º 1
0
func (c *ServerEndpointConfig) Validate() (bool, error) {
	var err error
	valid := true
	if c.Address == "" {
		fmt.Fprintln(os.Stderr, "Must specify address for server")
		valid = false
	}
	if c.Token == "" {
		fmt.Fprintln(os.Stderr, "Must specify token for server")
		valid = false
	}
	if c.TokenSecret == "" {
		fmt.Fprintln(os.Stderr, "Must specify token_secret for server")
		valid = false
	}
	if c.Password == "" {
		fmt.Fprintln(os.Stderr, "Must specify password for server")
		valid = false
	}
	if c.Method == "" {
		fmt.Fprintln(os.Stderr, "Must specify method for server")
		valid = false
	}

	c.headerCipher, err = ss.NewCipher(c.Method, c.Password)

	return valid, err
}
Exemplo n.º 2
0
func (c *Config) Validate() (bool, error) {
	var err error
	valid := true

	if len(c.Listen) == 0 {
		log.Error("Must specify address for server")
		valid = false
	}
	if c.Password == "" {
		log.Error("Must specify password for server")
		valid = false
	}
	if c.Method == "" {
		log.Error("Must specify method for server")
		valid = false
	}

	for key, _ := range c.Tokens {
		if len(key) > ss.TOKEN_SIZE {
			log.WithField("token", key).Errorf(fmt.Sprintf("Token lenght must be less equal %v", ss.TOKEN_SIZE))
			valid = false
		}
	}

	if !valid {
		return valid, errors.New("Invalid config file")
	}

	if c.headerCipher, err = ss.NewCipher(c.Method, c.Password); err != nil {
		valid = false
		return valid, err
	}

	return valid, nil
}