Skip to content

Commit

Permalink
Merge pull request #66 from qiniu/develop
Browse files Browse the repository at this point in the history
QCOS-0 Merge develop into master for 2.2.0 release
  • Loading branch information
nowenL authored Jan 12, 2017
2 parents 33e79cd + e50d66b commit 7bb9a50
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ install:
- go get -v github.com/Masterminds/glide
- cd $GOPATH/src/github.com/Masterminds/glide && git checkout 84607742b10f492430762d038e954236bbaf23f7 && go install
- cd $PROJECT_ROOT/kirk
- glide install
- echo $GOPATH
- glide --debug install

script:
- make style
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# vNext

# 2.1.0
# Release 2.2.0
- vendorManaged 应用状态的response 改details为message
- ListRepoTags和GetImageConfig 支持获取imagesize
- spec和app添加Privileges字段
- 为各个 Client 接口添加 GetConfig 方法

# Release 2.1.0
- 新增应用平台user权限的接口
- 修改日志搜索返回结果字段及其Tag

Expand Down
39 changes: 22 additions & 17 deletions kirksdk/account_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (

// AccountClient 包含针对账号 REST API 的各项操作
type AccountClient interface {
// GetConfig 返回用于创建本 Client 实例的 AccountConfig
GetConfig() (ret AccountConfig)

// GetAccountInfo 用于得到 Account 的相关信息
GetAccountInfo(ctx context.Context) (ret AccountInfo, err error)
Expand Down Expand Up @@ -127,10 +129,11 @@ type AccountConfig struct {

// CreateAppArgs 包含创建一个 App 所需的信息
type CreateAppArgs struct {
Title string `json:"title"`
Region string `json:"region"`
SpecURI string `json:"specUri"`
SpecVer uint32 `json:"specVer"`
Title string `json:"title"`
Region string `json:"region"`
SpecURI string `json:"specUri"`
SpecVer uint32 `json:"specVer"`
Privileges []string `json:"privileges"`
}

// AccountInfo 包含 Account 的相关信息
Expand All @@ -153,6 +156,7 @@ type AppInfo struct {
RunMode string `json:"runMode,omitempty"`
CreationTime time.Time `json:"ctime"`
ModificationTime time.Time `json:"mtime"`
Privileges []string `json:"privileges,omitempty"`
AppExtendedInfo
}

Expand Down Expand Up @@ -226,24 +230,25 @@ type GrantedAppKey struct {

// SpecInfo 包含 Spec 的相关信息
type SpecInfo struct {
URI string `json:"uri"`
Owner string `json:"owner"`
Title string `json:"title"`
Ver uint32 `json:"ver"`
Verstr string `json:"verstr"`
Desc string `json:"desc,omitempty"`
Brief string `json:"brief"`
Icon string `json:"icon"`
Seedimg string `json:"seedimg"`
Entryport uint16 `json:"entryport"`
Ctime time.Time `json:"ctime"`
Mtime time.Time `json:"mtime"`
URI string `json:"uri"`
Owner string `json:"owner"`
Title string `json:"title"`
Ver uint32 `json:"ver"`
Verstr string `json:"verstr"`
Desc string `json:"desc,omitempty"`
Brief string `json:"brief"`
Icon string `json:"icon"`
Seedimg string `json:"seedimg"`
Entryport uint16 `json:"entryport"`
Privileges []string `json:"privileges"`
Ctime time.Time `json:"ctime"`
Mtime time.Time `json:"mtime"`
}

// VendorManagedAppStatus 包含应用运行状态信息
type VendorManagedAppStatus struct {
Status string `json:"status"`
Details string `json:"details"`
Message string `json:"message"`
}

// VendorManagedAppEntry 包含应用入口地址
Expand Down
8 changes: 7 additions & 1 deletion kirksdk/account_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const appVersionPrefix = "/v3"
var ErrInvalidAppURI = errors.New("app uri is invalid")

type accountClientImp struct {
config AccountConfig
accessKey string
secretKey string
host string
Expand All @@ -27,6 +28,7 @@ type accountClientImp struct {
func NewAccountClient(cfg AccountConfig) AccountClient {

p := new(accountClientImp)
p.config = cfg
p.host = cleanHost(cfg.Host)
p.transport = cfg.Transport
p.userAgent = cfg.UserAgent
Expand All @@ -44,6 +46,10 @@ func NewAccountClient(cfg AccountConfig) AccountClient {
return p
}

func (p *accountClientImp) GetConfig() (ret AccountConfig) {
return p.config
}

func (p *accountClientImp) GetAccountInfo(ctx context.Context) (ret AccountInfo, err error) {
url := fmt.Sprintf("%s%s/info", p.host, appVersionPrefix)
err = p.client.Call(ctx, &ret, "GET", url)
Expand Down Expand Up @@ -289,7 +295,7 @@ func (p *accountClientImp) GetQcosClient(ctx context.Context, appURI string) (cl
go func() {
result := getKeyFunc()

if result.ak == "" {
if result.ak == "" && result.err == nil {
result.err = fmt.Errorf("Fail to find keys for app \"%s\"", appURI)
}

Expand Down
20 changes: 20 additions & 0 deletions kirksdk/account_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kirksdk

import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)

func TestAccountGetConfig(t *testing.T) {
config := AccountConfig{
AccessKey: "ak",
SecretKey: "sk",
Host: "https://account.test.url",
UserAgent: "account.ua",
Transport: http.DefaultTransport,
}

client := NewAccountClient(config)
assert.EqualValues(t, config, client.GetConfig())
}
8 changes: 6 additions & 2 deletions kirksdk/index_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
)

type IndexAuthClient interface {
GetConfig() (ret IndexAuthConfig)
RequestAuthToken(ctx context.Context, scopes []string) (AuthToken, error)
}

type IndexClient interface {
GetConfig() (ret IndexConfig)
ListRepo(ctx context.Context, username string) (repos []*Repo, err error)
ListRepoTags(ctx context.Context, username, repo string) (tags []*Tag, err error)
ListRepoTagsPage(ctx context.Context, username, repo string, start, size int) (tags []*Tag, err error)
Expand All @@ -37,8 +39,9 @@ type Repo struct {
}

type Tag struct {
Name string `json:"name"`
Created time.Time `json:"created"`
Name string `json:"name"`
Created time.Time `json:"created"`
Detail ImageConfig `json:"detail"`
}

type ImageConfig struct {
Expand All @@ -48,6 +51,7 @@ type ImageConfig struct {
Config map[string]interface{} `json:"config"`
ContainerConfig map[string]interface{} `json:"container_config"`
Created time.Time `json:"created"`
Size int64 `json:"size"`
}

type Digest string
Expand Down
7 changes: 6 additions & 1 deletion kirksdk/index_auth_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ type IndexAuthConfig struct {
}

type indexAuthClientImp struct {
config IndexAuthConfig
Host string
client rpc.Client
}

func NewIndexAuthClient(cfg IndexAuthConfig) IndexAuthClient {

p := new(indexAuthClientImp)

p.config = cfg
p.Host = cleanHost(cfg.Host)

cfg.Transport = newKirksdkTransport(cfg.UserAgent, cfg.Transport)
Expand All @@ -41,6 +42,10 @@ func NewIndexAuthClient(cfg IndexAuthConfig) IndexAuthClient {
return p
}

func (p *indexAuthClientImp) GetConfig() (ret IndexAuthConfig) {
return p.config
}

func (p *indexAuthClientImp) RequestAuthToken(ctx context.Context, scopes []string) (AuthToken, error) {
param := url.Values{"scope": scopes}
token := new(AuthToken)
Expand Down
20 changes: 20 additions & 0 deletions kirksdk/index_auth_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package kirksdk

import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)

func TestIndexAuthGetConfig(t *testing.T) {
config := IndexAuthConfig{
AccessKey: "ak",
SecretKey: "sk",
Host: "https://index.auth.test.url",
UserAgent: "index.ua",
Transport: http.DefaultTransport,
}

client := NewIndexAuthClient(config)
assert.EqualValues(t, config, client.GetConfig())
}
6 changes: 6 additions & 0 deletions kirksdk/index_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ type IndexConfig struct {
}

type indexClientImp struct {
config IndexConfig
host string
client rpc.Client
}

func NewIndexClient(cfg IndexConfig) IndexClient {

p := new(indexClientImp)
p.config = cfg
cfg.Host = cleanHost(cfg.Host)
p.host = cfg.Host

Expand All @@ -37,6 +39,10 @@ func NewIndexClient(cfg IndexConfig) IndexClient {
return p
}

func (p *indexClientImp) GetConfig() (ret IndexConfig) {
return p.config
}

func (p *indexClientImp) ListRepo(ctx context.Context, username string) (repos []*Repo, err error) {
err = p.client.Call(ctx, &repos, "GET", fmt.Sprintf("%s/api/%s/repos", p.host, username))
return
Expand Down
22 changes: 22 additions & 0 deletions kirksdk/index_client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kirksdk

import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
)

func TestIndexGetConfig(t *testing.T) {
config := IndexConfig{
AccessKey: "ak",
SecretKey: "sk",
Host: "https://index.test.url",
RootApp: "root",
AuthHost: "https://index.auth.test.url",
UserAgent: "index.ua",
Transport: http.DefaultTransport,
}

client := NewIndexClient(config)
assert.EqualValues(t, config, client.GetConfig())
}
2 changes: 1 addition & 1 deletion kirksdk/kirksdk.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package kirksdk

const Version = "2.1.0"
const Version = "2.2.0"
2 changes: 2 additions & 0 deletions kirksdk/qcos_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

type QcosClient interface {
GetConfig() (ret QcosConfig)

// GET /v3/stacks
ListStacks(ctx context.Context) (ret []StackInfo, err error)

Expand Down
6 changes: 6 additions & 0 deletions kirksdk/qcos_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type QcosConfig struct {
}

type qcosClientImp struct {
config QcosConfig
host string
logger *logrus.Logger
client rpc.Client
Expand All @@ -46,6 +47,7 @@ type qcosClientImp struct {
func NewQcosClient(cfg QcosConfig) QcosClient {

p := new(qcosClientImp)
p.config = cfg

p.host = cleanHost(cfg.Host)

Expand All @@ -66,6 +68,10 @@ func NewQcosClient(cfg QcosConfig) QcosClient {
return p
}

func (p *qcosClientImp) GetConfig() (ret QcosConfig) {
return p.config
}

// GET /v3/stacks
func (p *qcosClientImp) ListStacks(ctx context.Context) (ret []StackInfo, err error) {

Expand Down
13 changes: 13 additions & 0 deletions kirksdk/qcos_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ import (
"github.com/stretchr/testify/assert"
)

func TestQcosGetConfig(t *testing.T) {
config := QcosConfig{
AccessKey: "ak",
SecretKey: "sk",
Host: "https://test.url",
UserAgent: "ua",
Transport: http.DefaultTransport,
}

client := NewQcosClient(config)
assert.EqualValues(t, config, client.GetConfig())
}

func TestStacks(t *testing.T) {
expectedUrl := "/v3/stacks"
expectedMethod := "GET"
Expand Down

0 comments on commit 7bb9a50

Please sign in to comment.