Пример #1
0
func (e *ListAppsExecutor) Execute(t *Task) error {
	var err error
	apps, err := datamodel.ListApps()
	err = AuthorizeSuperUser(&e.arg.ManagerAuthArg)
	if err == nil {
		e.reply.Apps = apps
	} else {
		allowedApps := GetAllowedApps(&e.arg.ManagerAuthArg, e.arg.ManagerAuthArg.User)
		appsCount := len(allowedApps)
		totalAppsCount := len(apps)
		e.reply.Apps = make([]string, 0, appsCount)
		for i := 0; i < totalAppsCount; i++ {
			if allowedApps[apps[i]] {
				e.reply.Apps = append(e.reply.Apps, apps[i])
			}
		}
		err = nil
	}
	if err != nil {
		e.reply.Status = StatusError
	} else {
		sort.Strings(e.reply.Apps)
		e.reply.Status = StatusOk
	}
	return err
}
Пример #2
0
func LoadEnvs() error {
	envMutex.Lock()
	// get app+sha -> env
	apps, err := datamodel.ListApps()
	if err != nil {
		envMutex.Unlock()
		return nil // if we can't get the apps, this means this is a fresh zookeeper. don't fail.
	}
	for _, app := range apps {
		shas, err := datamodel.ListShas(app)
		if err != nil {
			envMutex.Unlock()
			return err
		}
		for _, sha := range shas {
			appSha := app + sha
			envs, err := datamodel.ListAppEnvs(app, sha)
			if err != nil {
				envMutex.Unlock()
				return err
			}
			for _, env := range envs {
				if _, ok := appShas[env]; ok {
					appShas[env][appSha]++
				} else {
					appShas[env] = map[string]int{appSha: 1}
				}
			}
		}
	}
	envMutex.Unlock()
	return nil
}