func getContainerIDsOfShaEnv(t *Task, app, sha, env string) ([]string, error) {
	containerIDs, err := datamodel.ListInstances(app, sha, env)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Error listing instances of %s @ %s in %s: %s", app, sha, env,
			err.Error()))
	}
	return containerIDs, nil
}
func getContainerIDsOfEnv(t *Task, app, env string) ([]string, error) {
	containerIDs := []string{}
	shas, err := datamodel.ListShas(app)
	if err != nil {
		return nil, errors.New(fmt.Sprintf("Error listing shas of %s : %s", app, err.Error()))
	}
	for _, sha := range shas {
		containerIDs, err = datamodel.ListInstances(app, sha, env)
		if err != nil {
			return nil, errors.New(fmt.Sprintf("Error listing instances of %s @ %s in %s: %s", app, sha, env,
				err.Error()))
		}
	}
	return containerIDs, nil
}
示例#3
0
func (e *ListContainersExecutor) Execute(t *Task) error {
	var err error
	if e.arg.App == "" && e.arg.Sha == "" && e.arg.Env == "" {
		// try to list all instances
		allContainerIDs, err := datamodel.ListAllInstances()
		if err != nil {
			e.reply.Status = StatusError
			return err
		} else {
			e.reply.Status = StatusOk
		}
		// filter by allowed app
		if err := AuthorizeSuperUser(&e.arg.ManagerAuthArg); err == nil {
			// if superuser, show everything
			e.reply.ContainerIDs = allContainerIDs
		} else {
			// else only show what is allowed
			allowedApps := GetAllowedApps(&e.arg.ManagerAuthArg, e.arg.ManagerAuthArg.User)
			e.reply.ContainerIDs = []string{}
			for _, cid := range allContainerIDs {
				if inst, err := datamodel.GetInstance(cid); err != nil && allowedApps[inst.App] {
					e.reply.ContainerIDs = append(e.reply.ContainerIDs, cid)
				}
			}
		}
		sort.Strings(e.reply.ContainerIDs)
		return nil
	}
	if e.arg.App == "" {
		return errors.New("App is empty")
	}
	if e.arg.Sha == "" {
		return errors.New("Sha is empty")
	}
	if e.arg.Env == "" {
		return errors.New("Environment is empty")
	}
	e.reply.ContainerIDs, err = datamodel.ListInstances(e.arg.App, e.arg.Sha, e.arg.Env)
	if err != nil {
		e.reply.Status = StatusError
	} else {
		sort.Strings(e.reply.ContainerIDs)
		e.reply.Status = StatusOk
	}
	return err
}