Пример #1
0
func (c *cleaner) add(v interface{}) {
	var fn func()
	switch model := v.(type) {
	case *models.User:
		fn = func() {
			modelhelper.RemoveUser(model.Name)
		}
	case *models.Account:
		fn = func() {
			modelhelper.RemoveAccount(model.Id)
		}
	case *models.Group:
		fn = func() {
			modelhelper.RemoveGroup(model.Id)
		}
	case *models.Machine:
		fn = func() {
			modelhelper.DeleteMachine(model.ObjectId)
		}
	case *models.ComputeStack:
		fn = func() {
			modelhelper.DeleteComputeStack(model.Id.Hex())
		}
	default:
		panic(fmt.Errorf("cleaner for %T not implemented", v))
	}
	*c = append(*c, fn)
}
Пример #2
0
func deleteGroups(res interface{}) error {
	g := res.(*models.Group)
	if isIn(g.Slug, "koding", "guests", "team") {
		return nil
	}

	admins, err := helper.FetchAdminAccounts(g.Slug)
	// if we have any admin, no need to delete
	if len(admins) > 0 {
		existingGroupBySlug.Set(g.Slug, struct{}{})
		return nil
	}

	// if we have error other than not found, it is better not to delete
	if err != mgo.ErrNotFound {
		return nil
	}

	fmt.Printf("deleting jGroup %q\n", g.Slug)
	if !*flagDry {
		return helper.RemoveGroup(g.Id)
	}

	return nil
}