diff --git a/.travis.yml b/.travis.yml index 646d949..72c62d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index 062ff03..ba62fd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/kirksdk/account_api.go b/kirksdk/account_api.go index 9a53493..c37eae3 100644 --- a/kirksdk/account_api.go +++ b/kirksdk/account_api.go @@ -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) @@ -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 的相关信息 @@ -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 } @@ -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 包含应用入口地址 diff --git a/kirksdk/account_client.go b/kirksdk/account_client.go index ccc77fe..0c180cc 100644 --- a/kirksdk/account_client.go +++ b/kirksdk/account_client.go @@ -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 @@ -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 @@ -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) @@ -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) } diff --git a/kirksdk/account_client_test.go b/kirksdk/account_client_test.go new file mode 100644 index 0000000..29e32bc --- /dev/null +++ b/kirksdk/account_client_test.go @@ -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()) +} diff --git a/kirksdk/index_api.go b/kirksdk/index_api.go index e08ee74..d03ea17 100644 --- a/kirksdk/index_api.go +++ b/kirksdk/index_api.go @@ -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) @@ -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 { @@ -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 diff --git a/kirksdk/index_auth_client.go b/kirksdk/index_auth_client.go index 3966e2c..7ed35ee 100644 --- a/kirksdk/index_auth_client.go +++ b/kirksdk/index_auth_client.go @@ -19,6 +19,7 @@ type IndexAuthConfig struct { } type indexAuthClientImp struct { + config IndexAuthConfig Host string client rpc.Client } @@ -26,7 +27,7 @@ type indexAuthClientImp struct { func NewIndexAuthClient(cfg IndexAuthConfig) IndexAuthClient { p := new(indexAuthClientImp) - + p.config = cfg p.Host = cleanHost(cfg.Host) cfg.Transport = newKirksdkTransport(cfg.UserAgent, cfg.Transport) @@ -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) diff --git a/kirksdk/index_auth_client_test.go b/kirksdk/index_auth_client_test.go new file mode 100644 index 0000000..b9b8825 --- /dev/null +++ b/kirksdk/index_auth_client_test.go @@ -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()) +} diff --git a/kirksdk/index_client.go b/kirksdk/index_client.go index 6203fa6..e486e00 100644 --- a/kirksdk/index_client.go +++ b/kirksdk/index_client.go @@ -20,6 +20,7 @@ type IndexConfig struct { } type indexClientImp struct { + config IndexConfig host string client rpc.Client } @@ -27,6 +28,7 @@ type indexClientImp struct { func NewIndexClient(cfg IndexConfig) IndexClient { p := new(indexClientImp) + p.config = cfg cfg.Host = cleanHost(cfg.Host) p.host = cfg.Host @@ -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 diff --git a/kirksdk/index_client_test.go b/kirksdk/index_client_test.go new file mode 100644 index 0000000..8d0dae8 --- /dev/null +++ b/kirksdk/index_client_test.go @@ -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()) +} diff --git a/kirksdk/kirksdk.go b/kirksdk/kirksdk.go index 314fa8a..2c94e78 100644 --- a/kirksdk/kirksdk.go +++ b/kirksdk/kirksdk.go @@ -1,3 +1,3 @@ package kirksdk -const Version = "2.1.0" +const Version = "2.2.0" diff --git a/kirksdk/qcos_api.go b/kirksdk/qcos_api.go index cc75a7a..dce37ed 100644 --- a/kirksdk/qcos_api.go +++ b/kirksdk/qcos_api.go @@ -9,6 +9,8 @@ import ( ) type QcosClient interface { + GetConfig() (ret QcosConfig) + // GET /v3/stacks ListStacks(ctx context.Context) (ret []StackInfo, err error) diff --git a/kirksdk/qcos_client.go b/kirksdk/qcos_client.go index cb0e498..ce46e39 100644 --- a/kirksdk/qcos_client.go +++ b/kirksdk/qcos_client.go @@ -37,6 +37,7 @@ type QcosConfig struct { } type qcosClientImp struct { + config QcosConfig host string logger *logrus.Logger client rpc.Client @@ -46,6 +47,7 @@ type qcosClientImp struct { func NewQcosClient(cfg QcosConfig) QcosClient { p := new(qcosClientImp) + p.config = cfg p.host = cleanHost(cfg.Host) @@ -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) { diff --git a/kirksdk/qcos_client_test.go b/kirksdk/qcos_client_test.go index 6781389..bb49a09 100644 --- a/kirksdk/qcos_client_test.go +++ b/kirksdk/qcos_client_test.go @@ -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"