示例#1
0
文件: group.go 项目: jeromer/haiconf
func (g *Group) setName(args haiconf.CommandArgs) error {
	n, err := haiconf.CheckString("Name", args)
	if err != nil {
		return err
	}

	grp, err := hacks.LookupSystemGroup(n)
	exists := err == nil && grp.Gid != ""

	g.Name = n

	if g.Ensure == haiconf.ENSURE_PRESENT {
		if !exists {
			g.action = ACTION_CREATE
		}
		// ACTION_NOOP in setDefault()
	}

	if g.Ensure == haiconf.ENSURE_ABSENT {
		if exists {
			g.action = ACTION_REMOVE
		}
		// ACTION_NOOP in setDefault()
	}

	return nil
}
示例#2
0
func (h *HttpGet) setTo(args haiconf.CommandArgs) error {
	t, _ := haiconf.CheckString("To", args)

	if len(t) == 0 {
		return haiconf.NewArgError("To must be provided", args)
	}

	if !utils.HasFileName(t) {
		return haiconf.NewArgError(t+" must be a file name", args)
	}

	dir := filepath.Dir(t)
	id, err := utils.IsDir(dir)
	if err != nil {
		return haiconf.NewArgError(err.Error(), args)
	}

	if !id {
		return haiconf.NewArgError(dir+" is not a directory", args)
	}

	h.To = t

	return nil
}
示例#3
0
文件: cron.go 项目: jeromer/haiconf
func (c *Cron) setCommand(args haiconf.CommandArgs) error {
	// XXX : check command really exists ?
	cmd, err := haiconf.CheckString("Command", args)
	if err != nil {
		return err
	}

	c.Command = cmd

	return nil
}
示例#4
0
func (h *HttpGet) setFrom(args haiconf.CommandArgs) error {
	f, _ := haiconf.CheckString("From", args)

	if len(f) == 0 {
		return haiconf.NewArgError("From must be provided", args)
	}

	f = strings.ToLower(f)

	if f[:7] == "http://" || f[:8] == "https://" {
		h.From = f
		return nil
	}

	return haiconf.NewArgError("From must be http or https", args)
}
示例#5
0
文件: targz.go 项目: jeromer/haiconf
func (t *TarGz) setSource(args haiconf.CommandArgs) error {
	s, _ := haiconf.CheckString("Source", args)
	if len(s) == 0 {
		return haiconf.NewArgError("Source must be provided", args)
	}

	f, err := os.Open(s)
	if err != nil {
		if os.IsNotExist(err) {
			return haiconf.NewArgError("Source does not exist", args)
		}
	}
	defer f.Close()

	t.Source = s
	return nil
}
示例#6
0
文件: cron.go 项目: jeromer/haiconf
func (c *Cron) checkNonPredefined(schedule map[string]string) ([]string, error) {
	sched := make([]string, len(c.Schedule))

	tmp := make(haiconf.CommandArgs, len(schedule))
	for k, v := range schedule {
		tmp[k] = v
	}

	for i, nps := range NON_PREDEFINED_SCHEDULES {
		s, err := haiconf.CheckString(nps, tmp)
		if err != nil {
			return []string{}, err
		}
		sched[i] = s
	}

	return sched, nil
}
示例#7
0
func (t *UnTarGz) setDest(args haiconf.CommandArgs) error {
	d, _ := haiconf.CheckString("Dest", args)
	if len(d) == 0 {
		return haiconf.NewArgError("Dest must be provided", args)
	}

	id, err := utils.IsDir(d)
	if err != nil {
		return err
	}

	if !id {
		return haiconf.NewArgError(d+" is not a directory", args)
	}

	t.Dest = d
	return nil
}
示例#8
0
func (t *UnTarGz) setSource(args haiconf.CommandArgs) error {
	s, _ := haiconf.CheckString("Source", args)
	if len(s) == 0 {
		return haiconf.NewArgError("Source must be provided", args)
	}

	fi, err := os.Stat(s)
	if err != nil {
		return err
	}

	if !fi.Mode().IsRegular() {
		return haiconf.NewArgError(s+" is not a file", args)
	}

	t.Source = s
	return nil
}
示例#9
0
文件: targz.go 项目: jeromer/haiconf
func (t *TarGz) setDest(args haiconf.CommandArgs) error {
	d, _ := haiconf.CheckString("Dest", args)
	if len(d) == 0 {
		return haiconf.NewArgError("Dest must be provided", args)
	}

	if !strings.HasSuffix(d, ".tar.gz") {
		return haiconf.NewArgError("No tarball name provided", args)
	}

	id, err := utils.IsDir(filepath.Dir(d))
	if err != nil {
		return err
	}

	if !id {
		return haiconf.NewArgError(d+" is not a directory", args)
	}

	t.Dest = d
	return nil
}