示例#1
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) FindPluginByNameAndService(pluginName string, service account.Service) (account.Plugin, error) {
	if plugin, ok := m.Plugins[service.Subdomain][pluginName]; !ok {
		return account.Plugin{}, errors.NewNotFoundError(errors.ErrPluginNotFound)
	} else {
		return plugin, nil
	}
}
示例#2
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) FindTeamByAlias(alias string) (account.Team, error) {
	if team, ok := m.Teams[alias]; !ok {
		return account.Team{}, errors.NewNotFoundError(errors.ErrTeamNotFound)
	} else {
		return team, nil
	}
}
示例#3
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) FindUserByEmail(email string) (account.User, error) {
	if user, ok := m.Users[email]; !ok {
		return account.User{}, errors.NewNotFoundError(errors.ErrUserNotFound)
	} else {
		return user, nil
	}
}
示例#4
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) FindHookByName(name string) (account.Hook, error) {
	if hook, ok := m.Hooks[name]; !ok {
		return account.Hook{}, errors.NewNotFoundError(errors.ErrHookNotFound)
	} else {
		return hook, nil
	}
}
示例#5
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) FindAppByClientId(id string) (account.App, error) {
	if app, ok := m.Apps[id]; !ok {
		return account.App{}, errors.NewNotFoundError(errors.ErrAppNotFound)
	} else {
		return app, nil
	}
}
示例#6
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) FindServiceBySubdomain(subdomain string) (account.Service, error) {
	if service, ok := m.Services[subdomain]; !ok {
		return account.Service{}, errors.NewNotFoundError(errors.ErrServiceNotFound)
	} else {
		return service, nil
	}
}
示例#7
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeleteTeam(t account.Team) error {
	if _, ok := m.Teams[t.Alias]; !ok {
		return errors.NewNotFoundError(errors.ErrTeamNotFound)
	}

	delete(m.Teams, t.Alias)
	return nil
}
示例#8
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeleteUser(u account.User) error {
	if _, ok := m.Users[u.Email]; !ok {
		return errors.NewNotFoundError(errors.ErrUserNotFound)
	}

	delete(m.Users, u.Email)
	return nil
}
示例#9
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeleteHook(w account.Hook) error {
	if _, ok := m.Hooks[w.Name]; !ok {
		return errors.NewNotFoundError(errors.ErrHookNotFound)
	}

	delete(m.Hooks, w.Name)
	return nil
}
示例#10
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeletePluginsByService(service account.Service) error {
	if _, ok := m.Plugins[service.Subdomain]; !ok {
		return errors.NewNotFoundError(errors.ErrPluginNotFound)
	}

	delete(m.Plugins, service.Subdomain)
	return nil
}
示例#11
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeletePlugin(pc account.Plugin) error {
	if _, ok := m.Plugins[pc.Service][pc.Name]; !ok {
		return errors.NewNotFoundError(errors.ErrPluginNotFound)
	}

	delete(m.Plugins, pc.Name)
	return nil
}
示例#12
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeleteApp(a account.App) error {
	if _, ok := m.Apps[a.ClientId]; !ok {
		return errors.NewNotFoundError(errors.ErrAppNotFound)
	}

	delete(m.Apps, a.ClientId)
	return nil
}
示例#13
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeleteService(s account.Service) error {
	if _, ok := m.Services[s.Subdomain]; !ok {
		return errors.NewNotFoundError(errors.ErrServiceNotFound)
	}

	delete(m.Services, s.Subdomain)
	return nil
}
示例#14
0
文件: user.go 项目: sinzone/apihub
// Updates the password for an existing account.
func (user *User) ChangePassword() error {
	if !user.Exists() {
		return errors.NewNotFoundError(errors.ErrUserNotFound)
	}

	user.hashPassword()
	return store.UpsertUser(*user)
}
示例#15
0
文件: mem.go 项目: sinzone/apihub
func (m *Mem) DeleteHooksByTeam(team account.Team) error {
	found := false
	for _, wh := range m.Hooks {
		if wh.Team == team.Alias {
			delete(m.Hooks, wh.Name)
			found = true
		}
	}
	if !found {
		return errors.NewNotFoundError(errors.ErrTeamNotFound)
	}
	return nil
}
示例#16
0
文件: app.go 项目: sinzone/apihub
func (app *App) Update() error {
	if err := app.valid(); err != nil {
		Logger.Info("Failed to create an app with invalid data: %+v.", app)
		return err
	}

	if !app.Exists() {
		Logger.Info("Failed to update a not-found app: %+v.", app)
		return errors.NewNotFoundError(errors.ErrAppNotFound)
	}

	err := store.UpsertApp(*app)
	Logger.Info("app.Update: %+v. Err: %s.", app, err)
	return err
}
示例#17
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeleteTeamByAlias(alias string) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Teams().Remove(bson.M{"alias": alias})

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrTeamNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#18
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeleteHook(w account.Hook) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Hooks().Remove(w)

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrHookNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#19
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeleteTeam(t account.Team) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Teams().Remove(t)

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrTeamNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#20
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeleteHooksByTeam(team account.Team) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Hooks().Remove(bson.M{"team": team.Alias})

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrHookNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#21
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeleteUser(u account.User) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Users().Remove(u)

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrUserNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#22
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeletePluginsByService(service account.Service) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Plugins().Remove(bson.M{"service": service.Subdomain})

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrPluginNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#23
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeletePlugin(pc account.Plugin) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Plugins().Remove(pc)

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrPluginNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#24
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeleteApp(app account.App) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Apps().Remove(bson.M{"clientid": app.ClientId})

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrAppNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#25
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) DeleteService(s account.Service) error {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	err := strg.Services().Remove(s)

	if err == mgo.ErrNotFound {
		return errors.NewNotFoundError(errors.ErrServiceNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return err
}
示例#26
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) FindUserByEmail(email string) (account.User, error) {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	user := account.User{}
	err := strg.Users().Find(bson.M{"email": email}).One(&user)

	if err == mgo.ErrNotFound {
		return account.User{}, errors.NewNotFoundError(errors.ErrUserNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return user, err
}
示例#27
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) FindHooksByEvent(event string) ([]account.Hook, error) {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	hooks := []account.Hook{}
	err := strg.Hooks().Find(bson.M{"events": bson.M{"$in": []string{event}}}).All(&hooks)

	if err == mgo.ErrNotFound {
		return []account.Hook{}, errors.NewNotFoundError(errors.ErrHookNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return hooks, err
}
示例#28
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) FindHookByName(name string) (account.Hook, error) {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	hooks := account.Hook{}
	err := strg.Hooks().Find(bson.M{"name": name}).One(&hooks)

	if err == mgo.ErrNotFound {
		return account.Hook{}, errors.NewNotFoundError(errors.ErrHookNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return hooks, err
}
示例#29
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) FindPluginByNameAndService(pluginName string, service account.Service) (account.Plugin, error) {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	var plugin account.Plugin
	err := strg.Plugins().Find(bson.M{"name": pluginName, "service": service.Subdomain}).One(&plugin)

	if err == mgo.ErrNotFound {
		return account.Plugin{}, errors.NewNotFoundError(errors.ErrPluginNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return plugin, err
}
示例#30
0
文件: mongore.go 项目: sinzone/apihub
func (m *Mongore) FindAppByClientId(clientid string) (account.App, error) {
	var strg Storage
	strg.Storage = m.openSession()
	defer strg.Close()

	var app account.App
	err := strg.Apps().Find(bson.M{"clientid": clientid}).One(&app)

	if err == mgo.ErrNotFound {
		return account.App{}, errors.NewNotFoundError(errors.ErrAppNotFound)
	}
	if err != nil {
		Logger.Warn(err.Error())
	}

	return app, err
}