当前位置: 首页>>代码示例>>Golang>>正文


Golang models.UpdatePluginSettingCmd类代码示例

本文整理汇总了Golang中github.com/grafana/grafana/pkg/models.UpdatePluginSettingCmd的典型用法代码示例。如果您正苦于以下问题:Golang UpdatePluginSettingCmd类的具体用法?Golang UpdatePluginSettingCmd怎么用?Golang UpdatePluginSettingCmd使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UpdatePluginSettingCmd类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: UpdatePluginSetting

func UpdatePluginSetting(cmd *m.UpdatePluginSettingCmd) error {
	return inTransaction2(func(sess *session) error {
		var pluginSetting m.PluginSetting

		exists, err := sess.Where("org_id=? and plugin_id=?", cmd.OrgId, cmd.PluginId).Get(&pluginSetting)
		sess.UseBool("enabled")
		sess.UseBool("pinned")
		if !exists {
			pluginSetting = m.PluginSetting{
				PluginId:       cmd.PluginId,
				OrgId:          cmd.OrgId,
				Enabled:        cmd.Enabled,
				Pinned:         cmd.Pinned,
				JsonData:       cmd.JsonData,
				SecureJsonData: cmd.GetEncryptedJsonData(),
				Created:        time.Now(),
				Updated:        time.Now(),
			}
			_, err = sess.Insert(&pluginSetting)
			return err
		} else {
			for key, data := range cmd.SecureJsonData {
				pluginSetting.SecureJsonData[key] = util.Encrypt([]byte(data), setting.SecretKey)
			}
			pluginSetting.Updated = time.Now()
			pluginSetting.Enabled = cmd.Enabled
			pluginSetting.JsonData = cmd.JsonData
			pluginSetting.Pinned = cmd.Pinned
			_, err = sess.Id(pluginSetting.Id).Update(&pluginSetting)
			return err
		}
	})
}
开发者ID:chancez,项目名称:grafana,代码行数:33,代码来源:plugin_setting.go

示例2: UpdatePluginSetting

func UpdatePluginSetting(cmd *m.UpdatePluginSettingCmd) error {
	return inTransaction2(func(sess *session) error {
		var pluginSetting m.PluginSetting

		exists, err := sess.Where("org_id=? and plugin_id=?", cmd.OrgId, cmd.PluginId).Get(&pluginSetting)
		sess.UseBool("enabled")
		sess.UseBool("pinned")
		if !exists {
			pluginSetting = m.PluginSetting{
				PluginId:       cmd.PluginId,
				OrgId:          cmd.OrgId,
				Enabled:        cmd.Enabled,
				Pinned:         cmd.Pinned,
				JsonData:       cmd.JsonData,
				PluginVersion:  cmd.PluginVersion,
				SecureJsonData: cmd.GetEncryptedJsonData(),
				Created:        time.Now(),
				Updated:        time.Now(),
			}

			// add state change event on commit success
			sess.events = append(sess.events, &m.PluginStateChangedEvent{
				PluginId: cmd.PluginId,
				OrgId:    cmd.OrgId,
				Enabled:  cmd.Enabled,
			})

			_, err = sess.Insert(&pluginSetting)
			return err
		} else {
			for key, data := range cmd.SecureJsonData {
				pluginSetting.SecureJsonData[key] = util.Encrypt([]byte(data), setting.SecretKey)
			}

			// add state change event on commit success
			if pluginSetting.Enabled != cmd.Enabled {
				sess.events = append(sess.events, &m.PluginStateChangedEvent{
					PluginId: cmd.PluginId,
					OrgId:    cmd.OrgId,
					Enabled:  cmd.Enabled,
				})
			}

			pluginSetting.Updated = time.Now()
			pluginSetting.Enabled = cmd.Enabled
			pluginSetting.JsonData = cmd.JsonData
			pluginSetting.Pinned = cmd.Pinned
			pluginSetting.PluginVersion = cmd.PluginVersion

			_, err = sess.Id(pluginSetting.Id).Update(&pluginSetting)
			return err
		}
	})
}
开发者ID:Robin7Ma,项目名称:grafana,代码行数:54,代码来源:plugin_setting.go

示例3: UpdatePluginSetting

func UpdatePluginSetting(c *middleware.Context, cmd m.UpdatePluginSettingCmd) Response {
	pluginId := c.Params(":pluginId")

	cmd.OrgId = c.OrgId
	cmd.PluginId = pluginId

	if _, ok := plugins.Apps[cmd.PluginId]; !ok {
		return ApiError(404, "Plugin not installed.", nil)
	}

	if err := bus.Dispatch(&cmd); err != nil {
		return ApiError(500, "Failed to update plugin setting", err)
	}

	return ApiSuccess("Plugin settings updated")
}
开发者ID:Xetius,项目名称:grafana,代码行数:16,代码来源:plugins.go


注:本文中的github.com/grafana/grafana/pkg/models.UpdatePluginSettingCmd类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。