From e5a7a5d4b2ef69b07d7597c45dc116d7315dc812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=AB=20H=C7=8Ei?= Date: Wed, 7 Dec 2016 16:01:16 +0800 Subject: [PATCH 1/7] QCOS-3237 add scale up/down --- kirksdk/qcos_api.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kirksdk/qcos_api.go b/kirksdk/qcos_api.go index ebf581b..994cdc2 100644 --- a/kirksdk/qcos_api.go +++ b/kirksdk/qcos_api.go @@ -344,7 +344,8 @@ const ( const ( StateCreate = State("CREATING") - StateScaling = State("SCALING") + StateScalingUp = State("SCALING-UP") + StateScalingDown = State("SCALING-DOWN") StateAutoUpdating = State("AUTO-UPDATING") StateManualUpdating = State("MANUAL-UPDATING") StateStarting = State("STARTING") From 4789894da80da124cff5680b640979a722fcc239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C5=AB=20H=C7=8Ei?= Date: Mon, 12 Dec 2016 09:56:50 +0800 Subject: [PATCH 2/7] QCOS-3237 change SERVICE SCALING stte --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e16ab97..1f8fd29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # vNext +- Service SCALING 状态拆分为 SCALING-UP SCALING-DOWN # Release 1.2.0 - 添加禁用/启用AP端口的API,并在查看/搜索AP的API返回的端口信息中返回端口的启用状态(启用/禁用)。 From 6e6319166e68ab1b27f20cdb0aaababc1dad5dbc Mon Sep 17 00:00:00 2001 From: pqx Date: Wed, 14 Dec 2016 16:04:06 +0800 Subject: [PATCH 3/7] =?UTF-8?q?QCOS-3363=20=E4=B8=BASDK=E6=B7=BB=E5=8A=A0A?= =?UTF-8?q?pp=20Grant=20access=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kirksdk/account_api.go | 27 +++++++++++++++++++++++++++ kirksdk/account_client.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/kirksdk/account_api.go b/kirksdk/account_api.go index 92378bb..953a9fa 100644 --- a/kirksdk/account_api.go +++ b/kirksdk/account_api.go @@ -80,6 +80,21 @@ type AccountClient interface { // GetQcosClient 用于得到与某个 App 交互的 QcosClient GetQcosClient(ctx context.Context, appURI string) (client QcosClient, err error) + + // CreateAppGrant 将应用授权给用户 + CreateAppGrant(ctx context.Context, appURI, username string) (err error) + + // DeleteAppGrant 删除应用授权 + DeleteAppGrant(ctx context.Context, appURI, username string) (err error) + + // ListAppGrantedUsers 列出应用已授权的用户列表 + ListAppGrantedUsers(ctx context.Context, appURI string) (ret []AppGrantedUser, err error) + + // ListGrantedApps 列出已被授权的应用 + ListGrantedApps(ctx context.Context) (ret []AppInfo, err error) + + // GetGrantedAppKey 获取被授权应用的key + GetGrantedAppKey(ctx context.Context, appURI string) (ret GrantedAppKey, err error) } // AccountConfig 包含创建 AccountClient 所需的信息 @@ -178,3 +193,15 @@ type UpdateAlertMethodArgs struct { Nationality string `json:"nationality"` Code string `json:"code"` } + +// AppGrantedUser 包含列出应用被授权的用户信息 +type AppGrantedUser struct { + ID uint32 `json:"id"` + Name string `json:"name"` +} + +// GrantedAppKey 包含被授权应用的key信息 +type GrantedAppKey struct { + Ak string `json:"ak"` + Sk string `json:"sk"` +} diff --git a/kirksdk/account_client.go b/kirksdk/account_client.go index 59496ac..1e24d5c 100644 --- a/kirksdk/account_client.go +++ b/kirksdk/account_client.go @@ -133,6 +133,36 @@ func (p *accountClientImp) UpdateAlertMethod(ctx context.Context, appURI string, return } +func (p *accountClientImp) CreateAppGrant(ctx context.Context, appURI, username string) (err error) { + url := fmt.Sprintf("%s%s/apps/%s/grant/%s", p.host, appVersionPrefix, appURI, username) + err = p.client.Call(ctx, nil, "PUT", url) + return +} + +func (p *accountClientImp) DeleteAppGrant(ctx context.Context, appURI, username string) (err error) { + url := fmt.Sprintf("%s%s/apps/%s/grant/%s", p.host, appVersionPrefix, appURI, username) + err = p.client.Call(ctx, nil, "DELETE", url) + return +} + +func (p *accountClientImp) ListAppGrantedUsers(ctx context.Context, appURI string) (ret []AppGrantedUser, err error) { + url := fmt.Sprintf("%s%s/apps/%s/grants", p.host, appVersionPrefix, appURI) + err = p.client.Call(ctx, &ret, "GET", url) + return +} + +func (p *accountClientImp) ListGrantedApps(ctx context.Context) (ret []AppInfo, err error) { + url := fmt.Sprintf("%s%s/granted", p.host, appVersionPrefix) + err = p.client.Call(ctx, &ret, "GET", url) + return +} + +func (p *accountClientImp) GetGrantedAppKey(ctx context.Context, appURI string) (ret GrantedAppKey, err error) { + url := fmt.Sprintf("%s%s/granted/%s/key", p.host, appVersionPrefix, appURI) + err = p.client.Call(ctx, &ret, "GET", url) + return +} + func (p *accountClientImp) GetIndexClient(ctx context.Context) (client IndexClient, err error) { accountInfo, err := p.GetAccountInfo(ctx) if err != nil { From a42213aa6931191b16be1163e87e7d41b26421a2 Mon Sep 17 00:00:00 2001 From: pqx Date: Wed, 14 Dec 2016 17:24:25 +0800 Subject: [PATCH 4/7] QCOS-3363 fix GetQcosClient --- kirksdk/account_client.go | 52 ++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/kirksdk/account_client.go b/kirksdk/account_client.go index 1e24d5c..27d4e83 100644 --- a/kirksdk/account_client.go +++ b/kirksdk/account_client.go @@ -1,8 +1,10 @@ package kirksdk import ( + "errors" "fmt" "net/http" + "strings" "golang.org/x/net/context" "qiniupkg.com/kirk/kirksdk/mac" @@ -11,6 +13,8 @@ import ( const appVersionPrefix = "/v3" +var ErrInvalidAppURI = errors.New("app uri is invalid") + type accountClientImp struct { accessKey string secretKey string @@ -193,12 +197,21 @@ func (p *accountClientImp) GetQcosClient(ctx context.Context, appURI string) (cl err error } - keyChan := make(chan keyResult) - endpointChan := make(chan endpointResult) + // app uri should follow the format: "username.appname" + // or it will return an invalid app uri + appURIParts := strings.Split(appURI, ".") + if len(appURIParts) < 2 { + return nil, ErrInvalidAppURI + } - // Get app access key & secret key - go func() { - var result keyResult + // check if app is granted + accountInfo, err := p.GetAccountInfo(ctx) + if err != nil { + return + } + isGranted := (accountInfo.Name != appURIParts[0]) + + getAppKeyFunc := func() (result keyResult) { keyPairs, err := p.GetAppKeys(ctx, appURI) if err != nil { result.err = err @@ -212,6 +225,33 @@ func (p *accountClientImp) GetQcosClient(ctx context.Context, appURI string) (cl } } } + return + } + + getGrantedAppKeyFunc := func() (result keyResult) { + keypair, err := p.GetGrantedAppKey(ctx, appURI) + result.err = err + if err == nil { + result.ak = keypair.Ak + result.sk = keypair.Sk + } + return + } + + // set up list apps and get key func + listAppsFunc := p.ListApps + getKeyFunc := getAppKeyFunc + if isGranted { + listAppsFunc = p.ListGrantedApps + getKeyFunc = getGrantedAppKeyFunc + } + + keyChan := make(chan keyResult) + endpointChan := make(chan endpointResult) + + // Get app access key & secret key + go func() { + result := getKeyFunc() if result.ak == "" { result.err = fmt.Errorf("Fail to find keys for app \"%s\"", appURI) @@ -223,7 +263,7 @@ func (p *accountClientImp) GetQcosClient(ctx context.Context, appURI string) (cl // Get qcos end point go func() { var result endpointResult - appInfos, err := p.ListApps(ctx) + appInfos, err := listAppsFunc(ctx) if err != nil { result.err = err endpointChan <- result From 9af6808360b95214a61ab9254fada222b8c153dc Mon Sep 17 00:00:00 2001 From: pqx Date: Wed, 14 Dec 2016 17:33:36 +0800 Subject: [PATCH 5/7] typo fix --- kirksdk/account_client.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kirksdk/account_client.go b/kirksdk/account_client.go index 27d4e83..73b8b7a 100644 --- a/kirksdk/account_client.go +++ b/kirksdk/account_client.go @@ -229,11 +229,11 @@ func (p *accountClientImp) GetQcosClient(ctx context.Context, appURI string) (cl } getGrantedAppKeyFunc := func() (result keyResult) { - keypair, err := p.GetGrantedAppKey(ctx, appURI) + keyPair, err := p.GetGrantedAppKey(ctx, appURI) result.err = err if err == nil { - result.ak = keypair.Ak - result.sk = keypair.Sk + result.ak = keyPair.Ak + result.sk = keyPair.Sk } return } From 30da9341e64fdba7d16e5a7b5727908c8cf2a547 Mon Sep 17 00:00:00 2001 From: Ru5her Date: Wed, 14 Dec 2016 20:54:46 +0800 Subject: [PATCH 6/7] =?UTF-8?q?QCOS-3300=20=E6=B7=BB=E5=8A=A0CollectedAtNa?= =?UTF-8?q?no=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kirksdk/qcos_api.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kirksdk/qcos_api.go b/kirksdk/qcos_api.go index ebf581b..da09375 100644 --- a/kirksdk/qcos_api.go +++ b/kirksdk/qcos_api.go @@ -748,12 +748,13 @@ type LogsSearchResult struct { } type Hit struct { - Log string `json:"log"` - CollectedAt time.Time `json:"collectedAt"` - PodIP string `json:"podIp"` - ProcessName string `json:"processName"` - GateID string `json:"gateId"` - Domain string `json:"domain"` + Log string `json:"log"` + CollectedAt time.Time `json:"collectedAt"` + CollectedAtNano int64 `json:"collectedAtNano"` + PodIP string `json:"podIp"` + ProcessName string `json:"processName"` + GateID string `json:"gateId"` + Domain string `json:"domain"` } var ( From 93ddbd049660e6c5755a01b7090a66871b7118a8 Mon Sep 17 00:00:00 2001 From: Ru5her Date: Wed, 14 Dec 2016 20:59:14 +0800 Subject: [PATCH 7/7] =?UTF-8?q?QCOS-3300=20=E6=B7=BB=E5=8A=A0CollectedAtNa?= =?UTF-8?q?no=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f8fd29..8bf76ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # vNext - Service SCALING 状态拆分为 SCALING-UP SCALING-DOWN +- 日志搜索结果添加CollectedAtNano字段 # Release 1.2.0 - 添加禁用/启用AP端口的API,并在查看/搜索AP的API返回的端口信息中返回端口的启用状态(启用/禁用)。