func validateOptions(cfg *config) (err error) {
	// step: read in the token if required

	if cfg.vaultAuthFile != "" {
		if exists, _ := fileExists(cfg.vaultAuthFile); !exists {
			return fmt.Errorf("the token file: %s does not exists, please check", cfg.vaultAuthFile)
		}

		cfg.vaultAuthOptions, err = readConfigFile(cfg.vaultAuthFile, cfg.vaultAuthFileFormat)
		if err != nil {
			return fmt.Errorf("unable to read in authentication options from: %s, error: %s", cfg.vaultAuthFile, err)
		}
		if cfg.vaultAuthOptions.VaultURL != "" {
			cfg.vaultURL = cfg.vaultAuthOptions.VaultURL
		}
	}

	if cfg.vaultURL == "" {
		cfg.vaultURL = os.Getenv("VAULT_ADDR")
	}

	if cfg.vaultURL == "" {
		return fmt.Errorf("VAULT_ADDR is unset")
	}

	// step: validate the vault url
	if _, err = url.Parse(cfg.vaultURL); err != nil {
		return fmt.Errorf("invalid vault url: '%s' specified", cfg.vaultURL)
	}

	if cfg.vaultCaFile != "" {
		if exists, _ := fileExists(cfg.vaultCaFile); !exists {
			return fmt.Errorf("the ca certificate file: %s does not exist", cfg.vaultCaFile)
		}
	}

	if cfg.skipTLSVerify == true && cfg.vaultCaFile != "" {
		return fmt.Errorf("you are skipping the tls but supplying a CA, doesn't make sense")
	}

	return nil
}
// validateOptions parses and validates the command line options
validateOptions parses and validates the command line options
// validateOptions parses and validates the command line options
func validateOptions(cfg *config) (err error) {
	if cfg.vaultAuthFile != "" {
		if exists, _ := fileExists(cfg.vaultAuthFile); !exists {
			return fmt.Errorf("the token file: %s does not exists, please check", cfg.vaultAuthFile)
		}
		cfg.vaultAuthOptions, err = readConfigFile(cfg.vaultAuthFile, cfg.vaultAuthFileFormat)
		if err != nil {
			return fmt.Errorf("unable to read in authentication options from: %s, error: %s", cfg.vaultAuthFile, err)
		}
		if cfg.vaultAuthOptions.VaultURL != "" {
			cfg.vaultURL = cfg.vaultAuthOptions.VaultURL
		}
	}
	if cfg.vaultURL == "" {
		cfg.vaultURL = os.Getenv("VAULT_ADDR")
	}
	if cfg.vaultURL == "" {
		return fmt.Errorf("VAULT_ADDR is unset")
	}
	if _, err = url.Parse(cfg.vaultURL); err != nil {
		return fmt.Errorf("invalid vault url: '%s' specified", cfg.vaultURL)
	}
	if cfg.vaultCaFile != "" {
		if exists, _ := fileExists(cfg.vaultCaFile); !exists {
			return fmt.Errorf("the ca certificate file: %s does not exist", cfg.vaultCaFile)
		}
	}
	if cfg.skipTLSVerify == true && cfg.vaultCaFile != "" {
		return fmt.Errorf("you are skipping the tls but supplying a CA, doesn't make sense")
	}
	return nil
}
func validateOptions ( cfg * config ) ( err error ) { if cfg . vaultAuthFile != " " { if exists , _ := fileExists ( cfg . vaultAuthFile ) ; ! exists { return fmt . Errorf ( " " , cfg . vaultAuthFile ) } cfg . vaultAuthOptions , err = readConfigFile ( cfg . vaultAuthFile , cfg . vaultAuthFileFormat ) if err != nil { return fmt . Errorf ( " " , cfg . vaultAuthFile , err ) } if cfg . vaultAuthOptions . VaultURL != " " { cfg . vaultURL = cfg . vaultAuthOptions . VaultURL } } if cfg . vaultURL == " " { cfg . vaultURL = os . Getenv ( " " ) } if cfg . vaultURL == " " { return fmt . Errorf ( " " ) } if _ , err = url . Parse ( cfg . vaultURL ) ; err != nil { return fmt . Errorf ( " " , cfg . vaultURL ) } if cfg . vaultCaFile != " " { if exists , _ := fileExists ( cfg . vaultCaFile ) ; ! exists { return fmt . Errorf ( " " , cfg . vaultCaFile ) } } if cfg . skipTLSVerify == true && cfg . vaultCaFile != " " { return fmt . Errorf ( " " ) } return nil }
validateOptions parses and validates the command line options
validateOptions parses and validates the command line options
// step: read in the token if required // step: validate the vault url