Diff
checker
文本
文本
圖像
文檔
Excel
文件夾
Legal
Enterprise
桌面版
定價
登入
下載 Diffchecker 桌面版
比較文本
尋找兩個文字檔案之間的差異
工具
歷史
即時編輯器
摺疊未變更行
關閉換行
檢視
拆分
統一
比對精度
智能
單詞
字符
語法突出顯示
選擇語法
忽略
文字轉換
前往第一個差異
編輯輸入
Diffchecker Desktop
執行Diffchecker最安全的方式。取得Diffchecker桌面應用程式:您的差異永遠不會離開您的電腦!
取得桌面版
Untitled diff
建立於
7 年前
差異永不過期
清除
匯出
分享
解釋
59 刪除
行
總計
刪除
字符
總計
刪除
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
79 行
全部複製
66 新增
行
總計
新增
字符
總計
新增
要繼續使用此功能,請升級到
Diff
checker
Pro
查看價格
83 行
全部複製
package api
package api
import (
import (
複製
已複製
複製
已複製
"github.com/
grafana/grafana/pkg/api/dtos"
"github.com/
torkelo
/grafana
-pro
/pkg/bus"
"github.com
/grafana
/grafana
/pkg/bus"
"github.com/
torkelo
/grafana
-pro
/pkg/
middleware
"
"github.com/
grafana
/grafana
/pkg/
components/apikeygen
"
m
"github.com/
torkelo
/grafana
-pro
/pkg/models"
"github.com/
grafana
/grafana
/pkg/models"
"
github.com/torkelo/grafana-pro/pkg/util
"
"
time
"
)
)
複製
已複製
複製
已複製
func GetA
PI
Keys(c *
models.ReqContext) Response
{
func GetA
pi
Keys(c *
middleware.Context)
{
query :=
models
.GetApiKeysQuery{
OrgId
: c.
OrgId
}
query :=
m
.GetApiKeysQuery{
AccountId
: c.
AccountId
}
if err := bus.Dispatch(&query); err != nil {
if err := bus.Dispatch(&query); err != nil {
複製
已複製
複製
已複製
return Error
(500, "Failed to list api keys", err)
c.JsonApiErr
(500, "Failed to list api keys", err)
return
}
}
複製
已複製
複製
已複製
result := make([]*
models
.ApiKeyDTO, len(query.Result))
result := make([]*
m
.ApiKeyDTO, len(query.Result))
for i, t := range query.Result {
for i, t := range query.Result {
複製
已複製
複製
已複製
var expiration *time.Time = nil
result[i] = &
m
.ApiKeyDTO{
if t.Expires != nil {
Id:
t.Id,
v := time.Unix(*t.Expires, 0)
Name:
t.Name,
expiration = &v
Role:
t.Role,
}
Key: t.Key
,
result[i] = &
models
.ApiKeyDTO{
Id:
t.Id,
Name:
t.Name,
Role:
t.Role,
Expiration: expiration
,
}
}
}
}
複製
已複製
複製
已複製
c.
JSON(200, result)
return
JSON(200, result)
}
}
複製
已複製
複製
已複製
func DeleteA
PI
Key(c *
models.ReqContext) Response
{
func DeleteA
pi
Key(c *
middleware.Context)
{
id := c.ParamsInt64(":id")
id := c.ParamsInt64(":id")
複製
已複製
複製
已複製
cmd := &
models
.DeleteApiKeyCommand{Id: id,
OrgId
: c.
OrgId
}
cmd := &
m
.DeleteApiKeyCommand{Id: id,
AccountId
: c.
AccountId
}
err := bus.Dispatch(cmd)
err := bus.Dispatch(cmd)
if err != nil {
if err != nil {
複製
已複製
複製
已複製
return Error
(500, "Failed to delete API key", err)
c.JsonApiErr
(500, "Failed to delete API key", err)
return
}
}
複製
已複製
複製
已複製
return Success
("API key deleted")
c.JsonOK
("API key deleted")
}
}
複製
已複製
複製
已複製
func
(hs *HTTPServer)
AddA
PI
Key(c *
models.ReqContext
, cmd
models
.AddApiKeyCommand)
Response
{
func
AddA
pi
Key(c *
middleware.Context
, cmd
m
.AddApiKeyCommand)
{
if !cmd.Role.IsValid() {
if !cmd.Role.IsValid() {
複製
已複製
複製
已複製
return Error
(400, "Invalid role specified", nil)
c.JsonApiErr
(400, "Invalid role specified", nil)
return
}
}
複製
已複製
複製
已複製
if hs.Cfg.ApiKeyMaxSecondsToLive != -1 {
cmd.AccountId = c.AccountId
if cmd.SecondsToLive == 0 {
cmd.Key =
util.GetRandomString(64)
return Error(400, "Number of seconds before expiration should be set", nil)
}
if cmd.SecondsToLive > hs.Cfg.ApiKeyMaxSecondsToLive {
return Error(400, "Number of seconds before expiration is greater than the global limit", nil)
}
}
cmd.OrgId = c.OrgId
newKeyInfo := apikeygen.New(cmd.OrgId, cmd.Name)
cmd.Key =
newKeyInfo.HashedKey
if err := bus.Dispatch(&cmd); err != nil {
if err := bus.Dispatch(&cmd); err != nil {
複製
已複製
複製
已複製
if err == models.ErrInvalidApiKeyExpiration {
c.JsonApiErr
(500, "Failed to add API key", err)
return Error(400, err.Error(), nil)
return
}
return Error
(500, "Failed to add API key", err)
}
}
複製
已複製
複製
已複製
result := &
dtos.NewApiKeyResult{
result := &
m.ApiKeyDTO{
Id: cmd.Result.Id,
Name: cmd.Result.Name,
Name: cmd.Result.Name,
複製
已複製
複製
已複製
Key:
newKeyInfo.ClientSecret
}
Role: cmd.Result.Role,
Key:
cmd.Result.Key,
}
複製
已複製
複製
已複製
return
JSON(200, result)
c.
JSON(200, result)
}
func UpdateApiKey(c *middleware.Context, cmd m.UpdateApiKeyCommand) {
if !cmd.Role.IsValid() {
c.JsonApiErr(400, "Invalid role specified", nil)
return
}
cmd.AccountId = c.AccountId
err := bus.Dispatch(&cmd)
if err != nil {
c.JsonApiErr(500, "Failed to update api key", err)
return
}
c.JsonOK("API key updated")
}
}
已保存差異
原始文本
開啟檔案
package api import ( "github.com/grafana/grafana/pkg/api/dtos" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/components/apikeygen" "github.com/grafana/grafana/pkg/models" "time" ) func GetAPIKeys(c *models.ReqContext) Response { query := models.GetApiKeysQuery{OrgId: c.OrgId} if err := bus.Dispatch(&query); err != nil { return Error(500, "Failed to list api keys", err) } result := make([]*models.ApiKeyDTO, len(query.Result)) for i, t := range query.Result { var expiration *time.Time = nil if t.Expires != nil { v := time.Unix(*t.Expires, 0) expiration = &v } result[i] = &models.ApiKeyDTO{ Id: t.Id, Name: t.Name, Role: t.Role, Expiration: expiration, } } return JSON(200, result) } func DeleteAPIKey(c *models.ReqContext) Response { id := c.ParamsInt64(":id") cmd := &models.DeleteApiKeyCommand{Id: id, OrgId: c.OrgId} err := bus.Dispatch(cmd) if err != nil { return Error(500, "Failed to delete API key", err) } return Success("API key deleted") } func (hs *HTTPServer) AddAPIKey(c *models.ReqContext, cmd models.AddApiKeyCommand) Response { if !cmd.Role.IsValid() { return Error(400, "Invalid role specified", nil) } if hs.Cfg.ApiKeyMaxSecondsToLive != -1 { if cmd.SecondsToLive == 0 { return Error(400, "Number of seconds before expiration should be set", nil) } if cmd.SecondsToLive > hs.Cfg.ApiKeyMaxSecondsToLive { return Error(400, "Number of seconds before expiration is greater than the global limit", nil) } } cmd.OrgId = c.OrgId newKeyInfo := apikeygen.New(cmd.OrgId, cmd.Name) cmd.Key = newKeyInfo.HashedKey if err := bus.Dispatch(&cmd); err != nil { if err == models.ErrInvalidApiKeyExpiration { return Error(400, err.Error(), nil) } return Error(500, "Failed to add API key", err) } result := &dtos.NewApiKeyResult{ Name: cmd.Result.Name, Key: newKeyInfo.ClientSecret} return JSON(200, result) }
更改後文本
開啟檔案
package api import ( "github.com/torkelo/grafana-pro/pkg/bus" "github.com/torkelo/grafana-pro/pkg/middleware" m "github.com/torkelo/grafana-pro/pkg/models" "github.com/torkelo/grafana-pro/pkg/util" ) func GetApiKeys(c *middleware.Context) { query := m.GetApiKeysQuery{AccountId: c.AccountId} if err := bus.Dispatch(&query); err != nil { c.JsonApiErr(500, "Failed to list api keys", err) return } result := make([]*m.ApiKeyDTO, len(query.Result)) for i, t := range query.Result { result[i] = &m.ApiKeyDTO{ Id: t.Id, Name: t.Name, Role: t.Role, Key: t.Key, } } c.JSON(200, result) } func DeleteApiKey(c *middleware.Context) { id := c.ParamsInt64(":id") cmd := &m.DeleteApiKeyCommand{Id: id, AccountId: c.AccountId} err := bus.Dispatch(cmd) if err != nil { c.JsonApiErr(500, "Failed to delete API key", err) return } c.JsonOK("API key deleted") } func AddApiKey(c *middleware.Context, cmd m.AddApiKeyCommand) { if !cmd.Role.IsValid() { c.JsonApiErr(400, "Invalid role specified", nil) return } cmd.AccountId = c.AccountId cmd.Key = util.GetRandomString(64) if err := bus.Dispatch(&cmd); err != nil { c.JsonApiErr(500, "Failed to add API key", err) return } result := &m.ApiKeyDTO{ Id: cmd.Result.Id, Name: cmd.Result.Name, Role: cmd.Result.Role, Key: cmd.Result.Key, } c.JSON(200, result) } func UpdateApiKey(c *middleware.Context, cmd m.UpdateApiKeyCommand) { if !cmd.Role.IsValid() { c.JsonApiErr(400, "Invalid role specified", nil) return } cmd.AccountId = c.AccountId err := bus.Dispatch(&cmd) if err != nil { c.JsonApiErr(500, "Failed to update api key", err) return } c.JsonOK("API key updated") }
尋找差異