Beispiel #1
0
func (p DockerPostgresPlugin) Validate(endpoint ShieldEndpoint) error {
	var (
		s   string
		err error
	)
	s, err = endpoint.StringValue("socket")
	if err != nil {
		ansi.Printf("@G{\u2713 socket}  using default socket @C{%s}\n", DefaultSocket)
	} else {
		ansi.Printf("@G{\u2713 socket}  using socket @C{%s}\n", s)
	}
	return nil
}
Beispiel #2
0
func Confirm(prompt string) bool {
	in := bufio.NewReader(os.Stdin)

	for {
		ansi.Printf("@Y{%s [y/n]} ", prompt)
		v, err := in.ReadString('\n')
		if err != nil {
			ansi.Fprintf(os.Stderr, "failed: @R{%s}\n", err)
			return false
		}

		switch strings.TrimRight(v, "\n") {
		case "Y":
			fallthrough
		case "y":
			fallthrough
		case "yes":
			return true

		case "N":
			fallthrough
		case "n":
			fallthrough
		case "no":
			return false
		}
	}
}
Beispiel #3
0
func (p RabbitMQBrokerPlugin) Validate(endpoint plugin.ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValue("rmq_url")
	if err != nil {
		ansi.Printf("@R{\u2717 rmq_url              %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 rmq_url}              @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("rmq_username")
	if err != nil {
		ansi.Printf("@R{\u2717 rmq_username         %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 rmq_username}         @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("rmq_password")
	if err != nil {
		ansi.Printf("@R{\u2717 rmq_password         %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 rmq_password}         @C{%s}\n", s)
	}

	tf, err := endpoint.BooleanValueDefault("skip_ssl_validation", false)
	if err != nil {
		ansi.Printf("@R{\u2717 skip_ssl_validation  %s}\n", err)
		fail = true
	} else {
		if tf {
			ansi.Printf("@G{\u2713 skip_ssl_validation}  @C{yes}, SSL will @Y{NOT} be validated\n")
		} else {
			ansi.Printf("@G{\u2713 skip_ssl_validation}  @C{no}, SSL @Y{WILL} be validated\n")
		}
	}

	if fail {
		return fmt.Errorf("rabbitmq-broker: invalid configuration")
	}
	return nil
}
Beispiel #4
0
func (p RedisBrokerPlugin) Validate(endpoint plugin.ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValue("redis_type")
	if err != nil {
		ansi.Printf("@R{\u2717 redis_type  %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 redis_type}  @C{%s}\n", s)
	}

	if fail {
		return fmt.Errorf("postgres: invalid configuration")
	}
	return nil
}
Beispiel #5
0
// Called to validate endpoints from the command line
func (p DummyPlugin) Validate(endpoint plugin.ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValue("data")
	if err != nil {
		ansi.Printf("@R{\u2717 data   %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 data}  @C{%s}\n", s)
	}

	if fail {
		return fmt.Errorf("dummy: invalid configuration")
	}
	return nil
}
Beispiel #6
0
func (p S3Plugin) Validate(endpoint plugin.ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValueDefault("s3_host", DefaultS3Host)
	if err != nil {
		ansi.Printf("@R{\u2717 s3_host              %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 s3_host}              @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("access_key_id")
	if err != nil {
		ansi.Printf("@R{\u2717 access_key_id        %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 access_key_id}        @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("secret_access_key")
	if err != nil {
		ansi.Printf("@R{\u2717 secret_access_key    %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 secret_access_key}    @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("bucket")
	if err != nil {
		ansi.Printf("@R{\u2717 bucket               %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 bucket}               @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("prefix", DefaultPrefix)
	if err != nil {
		ansi.Printf("@R{\u2717 prefix               %s}\n", err)
		fail = true
	} else if s == "" {
		ansi.Printf("@G{\u2713 prefix}               (none)\n")
	} else {
		ansi.Printf("@G{\u2713 prefix}               @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("signature_version", DefaultSigVersion)
	if err != nil {
		ansi.Printf("@R{\u2717 signature_version    %s}\n", err)
		fail = true
	} else if !validSigVersion(s) {
		ansi.Printf("@R{\u2717 signature_version    Unexpected signature version '%s' found (expecting '2' or '4')}\n", s)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 signature_version}    @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("socks5_proxy", "")
	if err != nil {
		ansi.Printf("@R{\u2717 socks5_proxy         %s}\n", err)
		fail = true
	} else if s == "" {
		ansi.Printf("@G{\u2713 socks5_proxy}         (no proxy will be used)\n")
	} else {
		ansi.Printf("@G{\u2713 socks5_proxy}         @C{%s}\n", s)
	}

	tf, err := endpoint.BooleanValueDefault("skip_ssl_validation", DefaultSkipSSLValidation)
	if err != nil {
		ansi.Printf("@R{\u2717 skip_ssl_validation  %s}\n", err)
		fail = true
	} else if tf {
		ansi.Printf("@G{\u2713 skip_ssl_validation}  @C{yes}, SSL will @Y{NOT} be validated\n")
	} else {
		ansi.Printf("@G{\u2713 skip_ssl_validation}  @C{no}, SSL @Y{WILL} be validated\n")
	}

	if fail {
		return fmt.Errorf("s3: invalid configuration")
	}
	return nil
}
Beispiel #7
0
func (p FSPlugin) Validate(endpoint plugin.ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValue("base_dir")
	if err != nil {
		ansi.Printf("@R{\u2717 base_dir  %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 base_dir}  files in @C{%s} will be backed up\n", s)
	}

	s, err = endpoint.StringValueDefault("include", "")
	if err != nil {
		ansi.Printf("@R{\u2717 include   %s}\n", err)
		fail = true
	} else if s == "" {
		ansi.Printf("@G{\u2713 include}   all files will be included\n")
	} else {
		ansi.Printf("@G{\u2713 include}   only files matching @C{%s} will be backed up\n", s)
	}

	s, err = endpoint.StringValueDefault("exclude", "")
	if err != nil {
		ansi.Printf("@R{\u2717 base_dir  %s}\n", err)
		fail = true
	} else if s == "" {
		ansi.Printf("@G{\u2713 exclude}   no files will be excluded\n")
	} else {
		ansi.Printf("@G{\u2713 exclude}   files matching @C{%s} will be skipped\n", s)
	}

	s, err = endpoint.StringValueDefault("bsdtar", "")
	if err != nil {
		ansi.Printf("@R{\u2717 bsdtar    %s}\n", err)
		fail = true
	} else if s == "" {
		ansi.Printf("@G{\u2713 bsdtar}    using default @C{%s}\n", DefaultBsdTar)
	} else {
		ansi.Printf("@G{\u2713 bsdtar}    @C{%s}\n", s)
	}

	if fail {
		return fmt.Errorf("fs: invalid configuration")
	}
	return nil
}
Beispiel #8
0
func (p MySQLPlugin) Validate(endpoint ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValue("mysql_host")
	if err != nil {
		ansi.Printf("@R{\u2717 mysql_host          %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 mysql_host}          @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("mysql_port", "")
	if err != nil {
		ansi.Printf("@R{\u2717 mysql_port          %s}\n", err)
	} else if s == "" {
		ansi.Printf("@G{\u2713 mysql_port}          using default port @C{%s}\n", DefaultPort)
	} else {
		ansi.Printf("@G{\u2713 mysql_port}          @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("mysql_user")
	if err != nil {
		ansi.Printf("@R{\u2717 mysql_user          %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 mysql_user}          @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("mysql_password")
	if err != nil {
		ansi.Printf("@R{\u2717 mysql_password      %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 mysql_password}      @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("mysql_read_replica", "")
	if err != nil {
		ansi.Printf("@R{\u2717 mysql_read_replica  %s}\n", err)
		fail = true
	} else if s == "" {
		ansi.Printf("@G{\u2713 mysql_read_replica}  no read replica\n")
	} else {
		ansi.Printf("@G{\u2713 mysql_read_replica}  @C{%s}\n", s)
	}

	if fail {
		return fmt.Errorf("mysql: invalid configuration")
	}
	return nil
}
Beispiel #9
0
func (p PostgresPlugin) Validate(endpoint ShieldEndpoint) error {
	var (
		s    string
		err  error
		fail bool
	)

	s, err = endpoint.StringValue("pg_host")
	if err != nil {
		ansi.Printf("@R{\u2717 pg_host      %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 pg_host}      @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("pg_port", "")
	if err != nil {
		ansi.Printf("@R{\u2717 pg_port      %s}\n", err)
	} else if s == "" {
		ansi.Printf("@G{\u2713 pg_port}      using default port @C{%s}\n", DefaultPort)
	} else {
		ansi.Printf("@G{\u2713 pg_port}      @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("pg_user")
	if err != nil {
		ansi.Printf("@R{\u2717 pg_user      %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 pg_user}      @C{%s}\n", s)
	}

	s, err = endpoint.StringValue("pg_password")
	if err != nil {
		ansi.Printf("@R{\u2717 pg_password  %s}\n", err)
		fail = true
	} else {
		ansi.Printf("@G{\u2713 pg_password}  @C{%s}\n", s)
	}

	s, err = endpoint.StringValueDefault("pg_database", "")
	if err != nil {
		ansi.Printf("@R{\u2717 pg_database  %s}\n", err)
	} else if s == "" {
		ansi.Printf("@G{\u2713 pg_database}  none (all databases will be backed up)\n")
	} else {
		ansi.Printf("@G{\u2713 pg_database}  @C{%s}\n", s)
	}

	if fail {
		return fmt.Errorf("postgres: invalid configuration")
	}
	return nil
}