// validateConfig checks the values provided to all of the configuration
// options, ensuring that e.g. `since` is a valid date, `jira-uri` is a
// real URI, etc. This is the first level of checking. It does not confirm
// if a JIRA cli is running at `jira-uri` for example; that is checked
// in getJIRAClient when we actually make a call to the API.
validateConfig checks the values provided to all of the configuration
options, ensuring that e.g. `since` is a valid date, `jira-uri` is a
real URI, etc. This is the first level of checking. It does not confirm
if a JIRA cli is running at `jira-uri` for example; that is checked
in getJIRAClient when we actually make a call to the API.
// validateConfig checks the values provided to all of the configuration // options ensuring that e . g . ` since ` is a valid date ` jira - uri ` is a // real URI etc . This is the first level of checking . It does not confirm // if a JIRA cli is running at ` jira - uri ` for example ; that is checked // in getJIRAClient when we actually make a call to the API .
func (c *Config) validateConfig() error {
	c.log.Debug("Checking config variables...")
	token := c.cmdConfig.GetString("github-token")
	if token == "" {
		return errors.New("GitHub token required")
	}
	c.basicAuth = (c.cmdConfig.GetString("jira-user") != "") && (c.cmdConfig.GetString("jira-pass") != "")
	if c.basicAuth {
		c.log.Debug("Using HTTP Basic Authentication")
		jUser := c.cmdConfig.GetString("jira-user")
		if jUser == "" {
			return errors.New("Jira username required")
		}
		jPass := c.cmdConfig.GetString("jira-pass")
		if jPass == "" {
			fmt.Print("Enter your JIRA password: ")
			bytePass, err := terminal.ReadPassword(int(syscall.Stdin))
			if err != nil {
				return errors.New("JIRA password required")
			}
			fmt.Println()
			c.cmdConfig.Set("jira-pass", string(bytePass))
		}
	} else {
		c.log.Debug("Using OAuth 1.0a authentication")
		token := c.cmdConfig.GetString("jira-token")
		if token == "" {
			return errors.New("JIRA access token required")
		}
		secret := c.cmdConfig.GetString("jira-secret")
		if secret == "" {
			return errors.New("JIRA access token secret required")
		}
		consumerKey := c.cmdConfig.GetString("jira-consumer-key")
		if consumerKey == "" {
			return errors.New("JIRA consumer key required for OAuth handshake")
		}
		privateKey := c.cmdConfig.GetString("jira-private-key-path")
		if privateKey == "" {
			return errors.New("JIRA private key required for OAuth handshake")
		}
		_, err := os.Open(privateKey)
		if err != nil {
			return errors.New("JIRA private key must point to existing PEM file")
		}
	}
	repo := c.cmdConfig.GetString("repo-name")
	if repo == "" {
		return errors.New("GitHub repository required")
	}
	if !strings.Contains(repo, "/") || len(strings.Split(repo, "/")) != 2 {
		return errors.New("GitHub repository must be of form user/repo")
	}
	uri := c.cmdConfig.GetString("jira-uri")
	if uri == "" {
		return errors.New("JIRA URI required")
	}
	if _, err := url.ParseRequestURI(uri); err != nil {
		return errors.New("JIRA URI must be valid URI")
	}
	project := c.cmdConfig.GetString("jira-project")
	if project == "" {
		return errors.New("JIRA project required")
	}
	issueType := c.cmdConfig.GetString("jira-issue-type")
	if issueType == "" {
		c.cmdConfig.Set("jira-issue-type", defaultJiraIssueType)
	}
	sinceStr := c.cmdConfig.GetString("since")
	if sinceStr == "" {
		c.cmdConfig.Set("since", "1970-01-01T00:00:00+0000")
	}
	since, err := time.Parse(dateFormat, sinceStr)
	if err != nil {
		return errors.New("Since date must be in ISO-8601 format")
	}
	c.since = since
	c.log.Debug("All config variables are valid!")
	return nil
}
func ( c * Config ) validateConfig ( ) error { c . log . Debug ( " " ) token := c . cmdConfig . GetString ( " " ) if token == " " { return errors . New ( " " ) } c . basicAuth = ( c . cmdConfig . GetString ( " " ) != " " ) && ( c . cmdConfig . GetString ( " " ) != " " ) if c . basicAuth { c . log . Debug ( " " ) jUser := c . cmdConfig . GetString ( " " ) if jUser == " " { return errors . New ( " " ) } jPass := c . cmdConfig . GetString ( " " ) if jPass == " " { fmt . Print ( " " ) bytePass , err := terminal . ReadPassword ( int ( syscall . Stdin ) ) if err != nil { return errors . New ( " " ) } fmt . Println ( ) c . cmdConfig . Set ( " " , string ( bytePass ) ) } } else { c . log . Debug ( " " ) token := c . cmdConfig . GetString ( " " ) if token == " " { return errors . New ( " " ) } secret := c . cmdConfig . GetString ( " " ) if secret == " " { return errors . New ( " " ) } consumerKey := c . cmdConfig . GetString ( " " ) if consumerKey == " " { return errors . New ( " " ) } privateKey := c . cmdConfig . GetString ( " " ) if privateKey == " " { return errors . New ( " " ) } _ , err := os . Open ( privateKey ) if err != nil { return errors . New ( " " ) } } repo := c . cmdConfig . GetString ( " " ) if repo == " " { return errors . New ( " " ) } if ! strings . Contains ( repo , " " ) || len ( strings . Split ( repo , " " ) ) != 2 { return errors . New ( " " ) } uri := c . cmdConfig . GetString ( " " ) if uri == " " { return errors . New ( " " ) } if _ , err := url . ParseRequestURI ( uri ) ; err != nil { return errors . New ( " " ) } project := c . cmdConfig . GetString ( " " ) if project == " " { return errors . New ( " " ) } issueType := c . cmdConfig . GetString ( " " ) if issueType == " " { c . cmdConfig . Set ( " " , defaultJiraIssueType ) } sinceStr := c . cmdConfig . GetString ( " " ) if sinceStr == " " { c . cmdConfig . Set ( " " , " " ) } since , err := time . Parse ( dateFormat , sinceStr ) if err != nil { return errors . New ( " " ) } c . since = since c . log . Debug ( " " ) return nil }
validateConfig checks the values provided to all of the configuration
options, ensuring that e.g.
validateConfig checks the values provided to all of the configuration options ensuring that e . g .
// Log level and config file location are validated already // Default if unset