Diff
checker
テキスト
テキスト
画像
ドキュメント
Excel
フォルダ
Legal
Enterprise
デスクトップ
料金
ログイン
Diffchecker デスクトップのダウンロード
テキスト比較
2 つのテキスト ファイルの違いを見つける
ツール
履歴
ライブエディター
未変更行を折りたたむ
折り返しなし
レイアウト
分割
統合
比較精度
スマート
単語
文字
シンタックスハイライト
構文を選択
無視
テキスト変換
最初の差分へ移動
入力を編集
Diffchecker Desktop
Diffcheckerを実行する最も安全な方法。Diffchecker Desktopアプリを入手:あなたの差分はコンピューターから出ることはありません!
Desktopを入手
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") }
違いを見つける