diff --git a/cmd/climc/shell/buckets.go b/cmd/climc/shell/buckets.go index 59099ac5fe..9d2da9473f 100644 --- a/cmd/climc/shell/buckets.go +++ b/cmd/climc/shell/buckets.go @@ -1,10 +1,25 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import ( - "yunion.io/x/jsonutils" - "io" "os" + + "yunion.io/x/jsonutils" + "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/onecloud/pkg/mcclient/modules" "yunion.io/x/onecloud/pkg/mcclient/options" @@ -102,7 +117,7 @@ func init() { return err } - arrays, _ := result.(*jsonutils.JSONArray).GetArray() + arrays, _ := result.GetArray("objects") listResult := modules.ListResult{Data: arrays} printList(&listResult, []string{}) return nil @@ -113,11 +128,22 @@ func init() { KEYS []string `help:"List of objects to delete"` } R(&BucketDeleteObjectsOptions{}, "bucket-object-delete", "Delete objects in a bucket", func(s *mcclient.ClientSession, args *BucketDeleteObjectsOptions) error { - params, err := options.StructToParams(args) + params := jsonutils.Marshal(args) + result, err := modules.Buckets.PerformAction(s, args.ID, "delete", params) if err != nil { return err } - result, err := modules.Buckets.PerformAction(s, args.ID, "delete", params) + printObject(result) + return nil + }) + + type BucketMakeDirOptions struct { + ID string `help:"ID or name of bucket" json:"-"` + KEY string `help:"DIR key to create"` + } + R(&BucketMakeDirOptions{}, "bucket-mkdir", "Mkdir in a bucket", func(s *mcclient.ClientSession, args *BucketMakeDirOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Buckets.PerformAction(s, args.ID, "makedir", params) if err != nil { return err } diff --git a/cmd/climc/shell/cloudaccounts.go b/cmd/climc/shell/cloudaccounts.go index fcf385f25b..f7d6428e9c 100644 --- a/cmd/climc/shell/cloudaccounts.go +++ b/cmd/climc/shell/cloudaccounts.go @@ -178,6 +178,17 @@ func init() { return nil }) + R(&options.SS3CloudAccountCreateOptions{}, "cloud-account-create-s3", "Create a generaic S3 object storage account", func(s *mcclient.ClientSession, args *options.SS3CloudAccountCreateOptions) error { + params := jsonutils.Marshal(args) + params.(*jsonutils.JSONDict).Add(jsonutils.NewString("S3"), "provider") + result, err := modules.Cloudaccounts.Create(s, params) + if err != nil { + return err + } + printObject(result) + return nil + }) + type CloudaccountUpdateOptions struct { ID string `help:"ID or Name of cloud account"` Name string `help:"New name to update"` @@ -316,6 +327,19 @@ func init() { return nil }) + R(&options.SUcloudCloudAccountUpdateOptions{}, "cloud-account-update-ucloud", "update a Ucloud cloud account", func(s *mcclient.ClientSession, args *options.SUcloudCloudAccountUpdateOptions) error { + params := jsonutils.Marshal(args).(*jsonutils.JSONDict) + if params.Size() == 0 { + return InvalidUpdateError() + } + result, err := modules.Cloudaccounts.Update(s, args.ID, params) + if err != nil { + return err + } + printObject(result) + return nil + }) + R(&options.SZStackCloudAccountUpdateOptions{}, "cloud-account-update-zstack", "update a ZStack cloud account", func(s *mcclient.ClientSession, args *options.SZStackCloudAccountUpdateOptions) error { params := jsonutils.Marshal(args).(*jsonutils.JSONDict) if params.Size() == 0 { @@ -329,6 +353,19 @@ func init() { return nil }) + R(&options.SS3CloudAccountUpdateOptions{}, "cloud-account-update-s3", "update a generic S3 cloud account", func(s *mcclient.ClientSession, args *options.SS3CloudAccountUpdateOptions) error { + params := jsonutils.Marshal(args).(*jsonutils.JSONDict) + if params.Size() == 0 { + return InvalidUpdateError() + } + result, err := modules.Cloudaccounts.Update(s, args.ID, params) + if err != nil { + return err + } + printObject(result) + return nil + }) + type CloudaccountShowOptions struct { ID string `help:"ID or Name of cloud account"` } @@ -483,6 +520,36 @@ func init() { return nil }) + R(&options.SUcloudCloudAccountUpdateCredentialOptions{}, "cloud-account-update-credential-ucloud", "Update credential of a Ucloud cloud account", func(s *mcclient.ClientSession, args *options.SUcloudCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "update-credential", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SZStackCloudAccountUpdateCredentialOptions{}, "cloud-account-update-credential-zstack", "Update credential of a ZStack cloud account", func(s *mcclient.ClientSession, args *options.SZStackCloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "update-credential", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + + R(&options.SS3CloudAccountUpdateCredentialOptions{}, "cloud-account-update-credential-s3", "Update credential of a generic S3 cloud account", func(s *mcclient.ClientSession, args *options.SS3CloudAccountUpdateCredentialOptions) error { + params := jsonutils.Marshal(args) + result, err := modules.Cloudaccounts.PerformAction(s, args.ID, "update-credential", params) + if err != nil { + return err + } + printObject(result) + return nil + }) + type CloudaccountSyncOptions struct { ID string `help:"ID or Name of cloud account"` Force bool `help:"Force sync no matter what"` diff --git a/cmd/s3cli/main.go b/cmd/s3cli/main.go index 7116deea50..abaf54d531 100644 --- a/cmd/s3cli/main.go +++ b/cmd/s3cli/main.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package main import ( diff --git a/cmd/s3gateway/main.go b/cmd/s3gateway/main.go index 0b29160c4b..6a149d9e51 100644 --- a/cmd/s3gateway/main.go +++ b/cmd/s3gateway/main.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package main import ( diff --git a/docs/bucket/bucket.yaml b/docs/bucket/bucket.yaml new file mode 100644 index 0000000000..2887840117 --- /dev/null +++ b/docs/bucket/bucket.yaml @@ -0,0 +1,40 @@ +get: + summary: 获得指定对象存储桶的详情 + parameters: + - $ref: '../parameters/bucket.yaml#/bucket_name' + responses: + 200: + description: 对象存储桶信息 + schema: + $ref: "../schemas/bucket.yaml#/BucketGetResponse" + tags: + - buckets + +put: + summary: 更新指定对象存储桶的信息 + parameters: + - $ref: '../parameters/bucket.yaml#/bucket_name' + - name: bucket + in: body + required: true + schema: + $ref: "../schemas/bucket.yaml#/BucketPutRequestInput" + responses: + 200: + description: 对象存储桶信息 + schema: + $ref: "../schemas/bucket.yaml#/BucketGetResponse" + tags: + - buckets + +delete: + summary: 删除指定的对象存储桶 + parameters: + - $ref: '../parameters/bucket.yaml#/bucket_name' + responses: + 200: + description: 被删除的对象存储桶信息 + schema: + $ref: "../schemas/bucket.yaml#/BucketGetResponse" + tags: + - buckets diff --git a/docs/bucket/buckets.yaml b/docs/bucket/buckets.yaml new file mode 100644 index 0000000000..8cea76367a --- /dev/null +++ b/docs/bucket/buckets.yaml @@ -0,0 +1,32 @@ +get: + summary: 按指定条件列出对象存储桶 + parameters: + - $ref: '../parameters/common.yaml#/offset' + - $ref: '../parameters/common.yaml#/limit' + - $ref: '../parameters/common.yaml#/provider' + - $ref: '../parameters/common.yaml#/brand' + - $ref: '../parameters/common.yaml#/region' + - $ref: '../parameters/common.yaml#/account' + responses: + 200: + description: 对象存储桶列表信息 + schema: + $ref: "../schemas/bucket.yaml#/BucketListResponse" + tags: + - buckets + +post: + summary: 新建对象存储桶 + parameters: + - name: bucket + in: body + required: true + schema: + $ref: "../schemas/bucket.yaml#/BucketCreateInput" + response: + 200: + description: 对象存储桶信息 + schema: + $ref: "../schemas/bucket.yaml#/BucketGetResponse" + tags: + - buckets diff --git a/docs/bucket/deleteobjects.yaml b/docs/bucket/deleteobjects.yaml new file mode 100644 index 0000000000..387d965e95 --- /dev/null +++ b/docs/bucket/deleteobjects.yaml @@ -0,0 +1,16 @@ +post: + summary: 删除指定桶下的指定对象 + parameters: + - $ref: '../parameters/bucket.yaml#/bucket_name' + - name: bucket + in: body + required: true + schema: + $ref: "../schemas/bucket.yaml#/BucketObjectDeleteInput" + responses: + 200: + description: 对象删除结果 + schema: + $ref: "../schemas/bucket.yaml#/BucketObjectDeleteResponse" + tags: + - buckets diff --git a/docs/bucket/listobjects.yaml b/docs/bucket/listobjects.yaml new file mode 100644 index 0000000000..e48e8e9213 --- /dev/null +++ b/docs/bucket/listobjects.yaml @@ -0,0 +1,13 @@ +get: + summary: 获得指定对象存储桶的对象列表 + parameters: + - $ref: '../parameters/bucket.yaml#/bucket_name' + - $ref: '../parameters/bucket.yaml#/prefix' + - $ref: '../parameters/bucket.yaml#/recursive' + responses: + 200: + description: 对象存储桶的对象列表信息 + schema: + $ref: "../schemas/bucket.yaml#/BucketObjectListResponse" + tags: + - buckets diff --git a/docs/bucket/makedir.yaml b/docs/bucket/makedir.yaml new file mode 100644 index 0000000000..c810dcbc81 --- /dev/null +++ b/docs/bucket/makedir.yaml @@ -0,0 +1,14 @@ +post: + summary: 创建一个大小为0的对象,用来做目录的占位 + parameters: + - $ref: '../parameters/bucket.yaml#/bucket_name' + - name: bucket + in: body + required: true + schema: + $ref: "../schemas/bucket.yaml#/BucketMakedirInput" + responses: + 200: + description: 创建成功 + tags: + - buckets diff --git a/docs/bucket/tempurl.yaml b/docs/bucket/tempurl.yaml new file mode 100644 index 0000000000..1c2a2af173 --- /dev/null +++ b/docs/bucket/tempurl.yaml @@ -0,0 +1,16 @@ +post: + summary: 生成访问指定对象的临时URL + parameters: + - $ref: '../parameters/bucket.yaml#/bucket_name' + - name: bucket + in: body + required: true + schema: + $ref: "../schemas/bucket.yaml#/BucketObjectTempUrlInput" + responses: + 200: + description: 指定对象的临时URL响应 + schema: + $ref: "../schemas/bucket.yaml#/BucketObjectTempUrlResponse" + tags: + - buckets diff --git a/docs/bucket/uploadobject.yaml b/docs/bucket/uploadobject.yaml new file mode 100644 index 0000000000..17c58f4a9e --- /dev/null +++ b/docs/bucket/uploadobject.yaml @@ -0,0 +1,12 @@ +post: + summary: 上传对象 + parameters: + - $ref: "../parameters/bucket.yaml#/bucket_name" + - $ref: "../parameters/bucket.yaml#/x-bucket-object-key" + - $ref: "../parameters/bucket.yaml#/x-bucket-content-type" + - $ref: "../parameters/bucket.yaml#/x-bucket-storage-class" + responses: + 200: + description: 上传成功 + tags: + - buckets diff --git a/docs/image/image.yaml b/docs/image/image.yaml index c70f209fba..f35e0149b2 100644 --- a/docs/image/image.yaml +++ b/docs/image/image.yaml @@ -107,6 +107,7 @@ put: $ref: "../schemas/image.yaml#/ImageResponse" tags: - images + get: parameters: - in: query diff --git a/docs/index.yaml b/docs/index.yaml index e85b80c329..1767c76fb7 100644 --- a/docs/index.yaml +++ b/docs/index.yaml @@ -353,3 +353,18 @@ paths: $ref: "./networkinterface/networkinterfaces.yaml" /networkinterfaces/{networkinterfaceId}: $ref: "./networkinterface/networkinterface.yaml" + + /buckets: + $ref: "./bucket/buckets.yaml" + /buckets/{bucketName}: + $ref: "./bucket/bucket.yaml" + /buckets/{bucketName}/objects: + $ref: "./bucket/listobjects.yaml" + /buckets/{bucketName}/delete: + $ref: "./bucket/deleteobjects.yaml" + /buckets/{bucketName}/makedir: + $ref: "./bucket/makedir.yaml" + /buckets/{bucketName}/upload: + $ref: "./bucket/uploadobject.yaml" + /buckets/{bucketName}/tempurl: + $ref: "./bucket/tempurl.yaml" diff --git a/docs/parameters/bucket.yaml b/docs/parameters/bucket.yaml new file mode 100644 index 0000000000..aee480aa02 --- /dev/null +++ b/docs/parameters/bucket.yaml @@ -0,0 +1,36 @@ +bucket_name: + name: bucket_name + type: string + required: true + in: path + description: 存储桶的名称 + +prefix: + name: prefix + type: string + in: query + description: 对象的前缀过滤 + +recursive: + name: recursive + type: bool + in: query + description: 是否展开对象列表,false则只显示当前目录层级下的对象,true则显示匹配前缀的所有对象 + +x-bucket-object-key: + name: x-bucket-object-key + type: string + in: header + description: 对象的key + +x-bucket-content-type: + name: x-bucket-content-type + type: string + in: header + description: 对象的content-type + +x-bucket-storage-class: + name: x-bucket-storage-class + type: string + in: header + description: 对象的storage_class diff --git a/docs/schemas/bucket.yaml b/docs/schemas/bucket.yaml new file mode 100644 index 0000000000..3d58f4654d --- /dev/null +++ b/docs/schemas/bucket.yaml @@ -0,0 +1,175 @@ +BucketListResponse: + type: object + properties: + limit: + type: integer + example: 20 + offset: + type: integer + example: 0 + total: + type: integer + description: 总量 + buckets: + type: array + items: + $ref: "#/Bucket" + +BucketObjectListResponse: + type: object + properties: + bucket: + type: object + properties: + objects: + type: array + items: + $ref: '#/BucketObject' + +BucketObject: + type: object + properties: + key: + type: string + description: 对象的key, 如果key以"/"结尾,则该key一般是目录占位对象 + size_bytes: + type: integer + description: 对象大小 + last_modified: + type: string + description: 该对象的最近修改时间 + etag: + type: string + description: 该对象的md5 checksum + storage_class: + type: string + description: 该对象的存储等级字符串 + +BucketGetResponse: + type: object + properties: + bucket: + type: object + $ref: "#/Bucket" + +BucketPutRequestInput: + type: object + properties: + name: + type: string + description: 存储桶的名称 + description: + type: string + description: 存储桶的描述 + +BucketCreateInput: + type: object + properties: + name: + type: string + required: true + description: 存储桶的名称 + cloudregion: + type: string + required: true + description: 存储桶所在cloudregion的名称或ID,对于on premise的通用s3存储,cloudregion为default + manager: + type: string + required: true + description: 存储桶归属的账号订阅(cloudprovider)的名称或ID + storage_class: + type: string + description: 存储桶的存储类型,可能值为:standard, ia和archive + description: + type: string + description: 存储桶的描述 + +Bucket: + type: object + description: 存储桶的描述信息 + properties: + id: + type: string + description: 存储桶的ID + readOnly: true + name: + type: string + description: 对象存储桶的名称,全局唯一。并且名字唯一性受到所在云供应商的桶名字空间唯一性的约束。 + can_delete: + type: boolean + description: 是否可以删除 + storage_class: + type: string + description: 存储桶的默认存储类型 + tenant_id: + type: string + description: 存储桶归属的项目ID + domain_id: + type: string + description: 存储桶归属的项目的域ID + location: + type: string + description: 存储桶的所在区域信息 + account_id: + type: string + description: 存储桶的云账号的ID + +BucketObjectDeleteInput: + type: object + properties: + keys: + type: array + items: + type: string + description: 待删除的对象Key + +BucketObjectDeleteResponse: + type: object + properties: + bucket: + type: array + items: + $ref: "" + +BucketObjectDeleteInfo: + type: object + properties: + id: + type: string + description: 对象key + status: + type: integer + description: 删除结果,200为成功,400为失败 + data: + type: string + description: 如果status为400,则data为错误原因 + +BucketObjectTempUrlInput: + type: object + properties: + key: + type: string + description: 对象key + method: + type: string + description: 请求对象的HTTP方法,例如:GET|PUT|DELETE + expire_seconds: + type: integer + description: 该临时URL的超时时间,单位为秒 + +BucketObjectTempUrlResponse: + type: object + properties: + bucket: + type: object + properties: + url: + type: string + description: 生成的临时URL + +BucketMakedirInput: + type: object + properties: + key: + type: string + description: 目录的名称,必需以"/"结尾 diff --git a/pkg/apis/compute/bucket.go b/pkg/apis/compute/bucket.go index 44ed26491b..b03ff11fdc 100644 --- a/pkg/apis/compute/bucket.go +++ b/pkg/apis/compute/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package compute const ( diff --git a/pkg/apis/s3gateway/consts.go b/pkg/apis/s3gateway/consts.go index 9042c56a4a..4c3500436d 100644 --- a/pkg/apis/s3gateway/consts.go +++ b/pkg/apis/s3gateway/consts.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package s3gateway const ( diff --git a/pkg/apis/s3gateway/doc.go b/pkg/apis/s3gateway/doc.go index c040a40a81..ebeea0ded5 100644 --- a/pkg/apis/s3gateway/doc.go +++ b/pkg/apis/s3gateway/doc.go @@ -1 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package s3gateway // import "yunion.io/x/onecloud/pkg/apis/s3gateway" diff --git a/pkg/cloudprovider/objectstore.go b/pkg/cloudprovider/objectstore.go index cfc1e8a0cf..54e8807c60 100644 --- a/pkg/cloudprovider/objectstore.go +++ b/pkg/cloudprovider/objectstore.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package cloudprovider import ( @@ -44,7 +58,7 @@ type ICloudBucket interface { ListObjects(prefix string, marker string, delimiter string, maxCount int) (SListObjectResult, error) GetIObjects(prefix string, isRecursive bool) ([]ICloudObject, error) - PutObject(ctx context.Context, key string, input io.ReadSeeker, contType string, storageClass string) error + PutObject(ctx context.Context, key string, input io.Reader, contType string, storageClass string) error DeleteObject(ctx context.Context, keys string) error GetTempUrl(method string, key string, expire time.Duration) (string, error) // ObjectExist(key string) (bool, error) diff --git a/pkg/compute/models/buckets.go b/pkg/compute/models/buckets.go index d38b521976..4e8534d4ef 100644 --- a/pkg/compute/models/buckets.go +++ b/pkg/compute/models/buckets.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package models import ( @@ -15,7 +29,6 @@ import ( "yunion.io/x/pkg/util/compare" "yunion.io/x/sqlchemy" - "io" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/appsrv" "yunion.io/x/onecloud/pkg/cloudcommon/db" @@ -271,15 +284,19 @@ func (bucket *SBucket) GetRegion() (*SCloudregion, error) { } func (bucket *SBucket) GetIRegion() (cloudprovider.ICloudRegion, error) { - region, err := bucket.GetRegion() - if err != nil { - return nil, errors.Wrap(err, "bucket.GetRegion") - } provider, err := bucket.GetDriver() if err != nil { return nil, err } - return provider.GetIRegionById(region.GetExternalId()) + if provider.GetFactory().IsOnPremise() { + return provider.GetOnPremiseIRegion() + } else { + region, err := bucket.GetRegion() + if err != nil { + return nil, errors.Wrap(err, "bucket.GetRegion") + } + return provider.GetIRegionById(region.GetExternalId()) + } } func (bucket *SBucket) GetIBucket() (cloudprovider.ICloudBucket, error) { @@ -452,7 +469,9 @@ func (bucket *SBucket) GetDetailsObjects( for i := range objects { retArray.Add(jsonutils.Marshal(cloudprovider.ICloudObject2BaseCloudObject(objects[i]))) } - return retArray, nil + ret := jsonutils.NewDict() + ret.Add(retArray, "objects") + return ret, nil } func (bucket *SBucket) AllowPerformTempUrl(ctx context.Context, @@ -600,7 +619,7 @@ func (bucket *SBucket) PerformUpload( contType := appParams.Request.Header.Get("Content-Type") storageClass := appParams.Request.Header.Get(api.BUCKET_UPLOAD_OBJECT_STORAGECLASS_HEADER) - err = iBucket.PutObject(ctx, key, appParams.Request.Body.(io.ReadSeeker), contType, storageClass) + err = iBucket.PutObject(ctx, key, appParams.Request.Body, contType, storageClass) if err != nil { return nil, httperrors.NewInternalServerError("put object error %s", err) } diff --git a/pkg/compute/service/service.go b/pkg/compute/service/service.go index 05b892c466..f329cdf7b2 100644 --- a/pkg/compute/service/service.go +++ b/pkg/compute/service/service.go @@ -34,6 +34,7 @@ import ( _ "yunion.io/x/onecloud/pkg/compute/regiondrivers" _ "yunion.io/x/onecloud/pkg/compute/storagedrivers" _ "yunion.io/x/onecloud/pkg/compute/tasks" + _ "yunion.io/x/onecloud/pkg/multicloud/objectstore/provider" _ "yunion.io/x/onecloud/pkg/util/aliyun/provider" _ "yunion.io/x/onecloud/pkg/util/aws/provider" _ "yunion.io/x/onecloud/pkg/util/azure/provider" diff --git a/pkg/compute/tasks/bucket_create_task.go b/pkg/compute/tasks/bucket_create_task.go index 0c82899ee8..32ec6acb80 100644 --- a/pkg/compute/tasks/bucket_create_task.go +++ b/pkg/compute/tasks/bucket_create_task.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package tasks import ( diff --git a/pkg/compute/tasks/bucket_delete_task.go b/pkg/compute/tasks/bucket_delete_task.go index 1a02865bc4..86a059ae06 100644 --- a/pkg/compute/tasks/bucket_delete_task.go +++ b/pkg/compute/tasks/bucket_delete_task.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package tasks import ( diff --git a/pkg/hostman/hostdeployer/apis/deploy.pb.go b/pkg/hostman/hostdeployer/apis/deploy.pb.go index 08c431d5c4..e420bc0600 100644 --- a/pkg/hostman/hostdeployer/apis/deploy.pb.go +++ b/pkg/hostman/hostdeployer/apis/deploy.pb.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // Code generated by protoc-gen-go. DO NOT EDIT. // source: deploy.proto diff --git a/pkg/mcclient/options/cloudaccounts.go b/pkg/mcclient/options/cloudaccounts.go index 8bb723b14f..0f1350e43f 100644 --- a/pkg/mcclient/options/cloudaccounts.go +++ b/pkg/mcclient/options/cloudaccounts.go @@ -131,6 +131,12 @@ type SZStackCloudAccountCreateOptions struct { AuthURL string `help:"ZStack auth_url" positional:"true" json:"auth_url"` } +type SS3CloudAccountCreateOptions struct { + SCloudAccountCreateBaseOptions + SAccessKeyCredential + Endpoint string `help:"S3 endpoint" poisitional:"true" json:"endpoint"` +} + // update credential options type SCloudAccountUpdateCredentialBaseOptions struct { @@ -172,6 +178,21 @@ type SHuaweiCloudAccountUpdateCredentialOptions struct { SAccessKeyCredential } +type SUcloudCloudAccountUpdateCredentialOptions struct { + SCloudAccountUpdateCredentialBaseOptions + SAccessKeyCredential +} + +type SZStackCloudAccountUpdateCredentialOptions struct { + SCloudAccountUpdateCredentialBaseOptions + SUserPasswordCredential +} + +type SS3CloudAccountUpdateCredentialOptions struct { + SCloudAccountUpdateCredentialBaseOptions + SAccessKeyCredential +} + // update type SCloudAccountUpdateBaseOptions struct { @@ -218,7 +239,14 @@ type SHuaweiCloudAccountUpdateOptions struct { SCloudAccountUpdateBaseOptions } +type SUcloudCloudAccountUpdateOptions struct { + SCloudAccountUpdateBaseOptions +} + type SZStackCloudAccountUpdateOptions struct { SCloudAccountUpdateBaseOptions - SUserPasswordCredential +} + +type SS3CloudAccountUpdateOptions struct { + SCloudAccountUpdateBaseOptions } diff --git a/pkg/multicloud/no_storage_region.go b/pkg/multicloud/no_storage_region.go index cee40885f3..2e0d6f7761 100644 --- a/pkg/multicloud/no_storage_region.go +++ b/pkg/multicloud/no_storage_region.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package multicloud import "yunion.io/x/onecloud/pkg/cloudprovider" diff --git a/pkg/multicloud/objectstore/buckets.go b/pkg/multicloud/objectstore/buckets.go index c91ffe11dd..70924d03c7 100644 --- a/pkg/multicloud/objectstore/buckets.go +++ b/pkg/multicloud/objectstore/buckets.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package objectstore import ( @@ -102,7 +116,7 @@ func (bucket *SBucket) GetIObjects(prefix string, isRecursive bool) ([]cloudprov return ret, nil } -func (bucket *SBucket) PutObject(ctx context.Context, key string, input io.ReadSeeker, contType string, storageClass string) error { +func (bucket *SBucket) PutObject(ctx context.Context, key string, input io.Reader, contType string, storageClass string) error { opts := minio.PutObjectOptions{} if len(contType) > 0 { opts.ContentType = contType diff --git a/pkg/multicloud/objectstore/doc.go b/pkg/multicloud/objectstore/doc.go index 1dff29c7f6..1f75c24a3a 100644 --- a/pkg/multicloud/objectstore/doc.go +++ b/pkg/multicloud/objectstore/doc.go @@ -1 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package objectstore // import "yunion.io/x/onecloud/pkg/multicloud/objectstore" diff --git a/pkg/multicloud/objectstore/object.go b/pkg/multicloud/objectstore/object.go index 61eb78f264..23cd1c0b0a 100644 --- a/pkg/multicloud/objectstore/object.go +++ b/pkg/multicloud/objectstore/object.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package objectstore import ( diff --git a/pkg/multicloud/objectstore/objectstore.go b/pkg/multicloud/objectstore/objectstore.go index 59e0bad569..bcd9e209b5 100644 --- a/pkg/multicloud/objectstore/objectstore.go +++ b/pkg/multicloud/objectstore/objectstore.go @@ -1,15 +1,29 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package objectstore import ( "net/url" + "time" "github.com/minio/minio-go" - "github.com/pkg/errors" "yunion.io/x/jsonutils" + "yunion.io/x/pkg/errors" "yunion.io/x/pkg/util/secrules" - "time" api "yunion.io/x/onecloud/pkg/apis/compute" "yunion.io/x/onecloud/pkg/cloudcommon/object" "yunion.io/x/onecloud/pkg/cloudprovider" diff --git a/pkg/multicloud/objectstore/provider/doc.go b/pkg/multicloud/objectstore/provider/doc.go index ed4a02e131..2ce176816e 100644 --- a/pkg/multicloud/objectstore/provider/doc.go +++ b/pkg/multicloud/objectstore/provider/doc.go @@ -1 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package provider // import "yunion.io/x/onecloud/pkg/multicloud/objectstore/provider" diff --git a/pkg/multicloud/objectstore/provider/provider.go b/pkg/multicloud/objectstore/provider/provider.go index ee3cb5869e..ae07687fe8 100644 --- a/pkg/multicloud/objectstore/provider/provider.go +++ b/pkg/multicloud/objectstore/provider/provider.go @@ -39,13 +39,13 @@ func (self *SObjectStoreProviderFactory) GetName() string { } func (self *SObjectStoreProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error { - accessKeyID, _ := data.GetString("access_key") + accessKeyID, _ := data.GetString("access_key_id") if len(accessKeyID) == 0 { - return httperrors.NewMissingParameterError("access_key") + return httperrors.NewMissingParameterError("access_key_id") } - accessKeySecret, _ := data.GetString("secret_key") + accessKeySecret, _ := data.GetString("access_key_secret") if len(accessKeySecret) == 0 { - return httperrors.NewMissingParameterError("secret_key") + return httperrors.NewMissingParameterError("access_key_secret") } endpointURL, _ := data.GetString("endpoint") if len(endpointURL) == 0 { @@ -53,18 +53,18 @@ func (self *SObjectStoreProviderFactory) ValidateCreateCloudaccountData(ctx cont } data.Set("account", jsonutils.NewString(accessKeyID)) data.Set("secret", jsonutils.NewString(accessKeySecret)) - data.Set("url", jsonutils.NewString(endpointURL)) + data.Set("access_url", jsonutils.NewString(endpointURL)) return nil } func (self *SObjectStoreProviderFactory) ValidateUpdateCloudaccountCredential(ctx context.Context, userCred mcclient.TokenCredential, data jsonutils.JSONObject, cloudaccount string) (*cloudprovider.SCloudaccount, error) { - accessKeyID, _ := data.GetString("access_key") + accessKeyID, _ := data.GetString("access_key_id") if len(accessKeyID) == 0 { - return nil, httperrors.NewMissingParameterError("access_key") + return nil, httperrors.NewMissingParameterError("access_key_id") } - accessKeySecret, _ := data.GetString("secret_key") + accessKeySecret, _ := data.GetString("access_key_secret") if len(accessKeySecret) == 0 { - return nil, httperrors.NewMissingParameterError("secret_key") + return nil, httperrors.NewMissingParameterError("access_key_secret") } account := &cloudprovider.SCloudaccount{ Account: accessKeyID, diff --git a/pkg/multicloud/objectstore/shell.go b/pkg/multicloud/objectstore/shell.go index 9486454984..e02c9d3708 100644 --- a/pkg/multicloud/objectstore/shell.go +++ b/pkg/multicloud/objectstore/shell.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package objectstore import ( @@ -63,7 +77,7 @@ func S3Shell() { return err } if result.IsTruncated { - fmt.Println("NextMarker: %s IsTruncated: %v", result.NextMarker, result.IsTruncated) + fmt.Printf("NextMarker: %s IsTruncated: %v\n", result.NextMarker, result.IsTruncated) } fmt.Println("Common prefixes:") printutils.PrintGetterList(result.CommonPrefixes, []string{"key", "size_bytes"}) diff --git a/pkg/multicloud/objectstore/shell/bucket.go b/pkg/multicloud/objectstore/shell/bucket.go index df5a4c18fa..f44f1c4081 100644 --- a/pkg/multicloud/objectstore/shell/bucket.go +++ b/pkg/multicloud/objectstore/shell/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import "yunion.io/x/onecloud/pkg/multicloud/objectstore" diff --git a/pkg/multicloud/objectstore/shell/doc.go b/pkg/multicloud/objectstore/shell/doc.go index 02f653e99c..48acf30c38 100644 --- a/pkg/multicloud/objectstore/shell/doc.go +++ b/pkg/multicloud/objectstore/shell/doc.go @@ -1 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell // import "yunion.io/x/onecloud/pkg/multicloud/objectstore/shell" diff --git a/pkg/multicloud/objectstore/shell/printutils.go b/pkg/multicloud/objectstore/shell/printutils.go index 1fbb2cdfbb..94b9f1fc45 100644 --- a/pkg/multicloud/objectstore/shell/printutils.go +++ b/pkg/multicloud/objectstore/shell/printutils.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import "yunion.io/x/onecloud/pkg/util/printutils" diff --git a/pkg/s3gateway/models/doc.go b/pkg/s3gateway/models/doc.go index 34a9313299..ebefc3d149 100644 --- a/pkg/s3gateway/models/doc.go +++ b/pkg/s3gateway/models/doc.go @@ -1 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package models // import "yunion.io/x/onecloud/pkg/s3gateway/models" diff --git a/pkg/s3gateway/models/initdb.go b/pkg/s3gateway/models/initdb.go index 04b39991a6..358ff3535b 100644 --- a/pkg/s3gateway/models/initdb.go +++ b/pkg/s3gateway/models/initdb.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package models import ( diff --git a/pkg/s3gateway/options/doc.go b/pkg/s3gateway/options/doc.go index 64521a2764..05900f9a10 100644 --- a/pkg/s3gateway/options/doc.go +++ b/pkg/s3gateway/options/doc.go @@ -1 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package options // import "yunion.io/x/onecloud/pkg/s3gateway/options" diff --git a/pkg/s3gateway/options/options.go b/pkg/s3gateway/options/options.go index 39cdd277bf..b1b5513deb 100644 --- a/pkg/s3gateway/options/options.go +++ b/pkg/s3gateway/options/options.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package options import ( diff --git a/pkg/s3gateway/service/doc.go b/pkg/s3gateway/service/doc.go index 6119b972de..1386d5d4a5 100644 --- a/pkg/s3gateway/service/doc.go +++ b/pkg/s3gateway/service/doc.go @@ -1 +1,15 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package service // import "yunion.io/x/onecloud/pkg/s3gateway/service" diff --git a/pkg/s3gateway/service/handlers.go b/pkg/s3gateway/service/handlers.go index 2decf3567e..c09a7c2fbd 100644 --- a/pkg/s3gateway/service/handlers.go +++ b/pkg/s3gateway/service/handlers.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package service import ( diff --git a/pkg/s3gateway/service/service.go b/pkg/s3gateway/service/service.go index 92822438d4..67e6e36fc8 100644 --- a/pkg/s3gateway/service/service.go +++ b/pkg/s3gateway/service/service.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package service import ( diff --git a/pkg/scheduler/algorithm/predicates/predicates.go b/pkg/scheduler/algorithm/predicates/predicates.go index 29a6a9a0ca..7ce8f008a3 100644 --- a/pkg/scheduler/algorithm/predicates/predicates.go +++ b/pkg/scheduler/algorithm/predicates/predicates.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at diff --git a/pkg/util/aliyun/bucket.go b/pkg/util/aliyun/bucket.go index 00862debad..be0e83d187 100644 --- a/pkg/util/aliyun/bucket.go +++ b/pkg/util/aliyun/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package aliyun import ( @@ -128,7 +142,7 @@ func (b *SBucket) GetIObjects(prefix string, isRecursive bool) ([]cloudprovider. return cloudprovider.GetIObjects(b, prefix, isRecursive) } -func (b *SBucket) PutObject(ctx context.Context, key string, input io.ReadSeeker, contType string, storageClassStr string) error { +func (b *SBucket) PutObject(ctx context.Context, key string, input io.Reader, contType string, storageClassStr string) error { osscli, err := b.region.GetOssClient() if err != nil { return errors.Wrap(err, "GetOssClient") diff --git a/pkg/util/aliyun/objects.go b/pkg/util/aliyun/objects.go index 173201ae04..6b94b35233 100644 --- a/pkg/util/aliyun/objects.go +++ b/pkg/util/aliyun/objects.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package aliyun import ( diff --git a/pkg/util/aliyun/shell/bucket.go b/pkg/util/aliyun/shell/bucket.go index df5a4c18fa..f44f1c4081 100644 --- a/pkg/util/aliyun/shell/bucket.go +++ b/pkg/util/aliyun/shell/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import "yunion.io/x/onecloud/pkg/multicloud/objectstore" diff --git a/pkg/util/aws/bucket.go b/pkg/util/aws/bucket.go index 612abe630a..a5bf933cb4 100644 --- a/pkg/util/aws/bucket.go +++ b/pkg/util/aws/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package aws import ( @@ -6,8 +20,11 @@ import ( "io" "time" + "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/request" + "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" + "github.com/aws/aws-sdk-go/service/s3/s3manager" "yunion.io/x/pkg/errors" @@ -128,25 +145,30 @@ func (b *SBucket) GetIObjects(prefix string, isRecursive bool) ([]cloudprovider. return cloudprovider.GetIObjects(b, prefix, isRecursive) } -func (b *SBucket) PutObject(ctx context.Context, key string, reader io.ReadSeeker, contType string, storageClassStr string) error { - s3cli, err := b.region.GetS3Client() +func (b *SBucket) PutObject(ctx context.Context, key string, reader io.Reader, contType string, storageClassStr string) error { + sess, err := session.NewSession(&aws.Config{Region: aws.String(b.region.GetId())}) if err != nil { - return errors.Wrap(err, "GetS3Client") + return errors.Wrap(err, "session.NewSession") } - input := &s3.PutObjectInput{} - input.SetBucket(b.Name) - input.SetKey(key) - input.SetBody(reader) - if len(storageClassStr) > 0 { - input.SetStorageClass(storageClassStr) + + svc := s3manager.NewUploader(sess) + input := &s3manager.UploadInput{ + Bucket: aws.String(b.Name), + Key: aws.String(key), + Body: reader, } if len(contType) > 0 { - input.SetContentType(contType) + input.ContentType = aws.String(contType) } - _, err = s3cli.PutObjectWithContext(ctx, input) + if len(storageClassStr) > 0 { + input.StorageClass = aws.String(storageClassStr) + } + + _, err = svc.Upload(input) if err != nil { - return errors.Wrap(err, "PutObjectWithContext") + return errors.Wrap(err, "svc.Upload") } + return nil } diff --git a/pkg/util/aws/s3object.go b/pkg/util/aws/s3object.go index 7bf181e7e0..e006d832da 100644 --- a/pkg/util/aws/s3object.go +++ b/pkg/util/aws/s3object.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package aws import "yunion.io/x/onecloud/pkg/cloudprovider" diff --git a/pkg/util/aws/shell/bucket.go b/pkg/util/aws/shell/bucket.go index df5a4c18fa..f44f1c4081 100644 --- a/pkg/util/aws/shell/bucket.go +++ b/pkg/util/aws/shell/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import "yunion.io/x/onecloud/pkg/multicloud/objectstore" diff --git a/pkg/util/azure/blobobject.go b/pkg/util/azure/blobobject.go index 509314d08e..fd7c953a0f 100644 --- a/pkg/util/azure/blobobject.go +++ b/pkg/util/azure/blobobject.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package azure import "yunion.io/x/onecloud/pkg/cloudprovider" diff --git a/pkg/util/azure/shell/bucket.go b/pkg/util/azure/shell/bucket.go index ae85368d81..9482e9f16d 100644 --- a/pkg/util/azure/shell/bucket.go +++ b/pkg/util/azure/shell/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import ( diff --git a/pkg/util/azure/storageaccount.go b/pkg/util/azure/storageaccount.go index dfbd361496..e3d0a905db 100644 --- a/pkg/util/azure/storageaccount.go +++ b/pkg/util/azure/storageaccount.go @@ -508,7 +508,7 @@ func (self *SContainer) CopySnapshot(snapshotId, fileName string) (*storage.Blob return blobRef, blobRef.GetProperties(&storage.GetBlobPropertiesOptions{}) } -func (self *SContainer) UploadStream(key string, reader io.ReadSeeker, contType string) error { +func (self *SContainer) UploadStream(key string, reader io.Reader, contType string) error { storageaccount := self.storageaccount client, err := storage.NewBasicClientOnSovereignCloud(storageaccount.Name, storageaccount.accountKey, storageaccount.region.client.env) if err != nil { @@ -640,7 +640,7 @@ func (self *SStorageAccount) getOrCreateContainer(containerName string, create b return container, nil } -func (self *SStorageAccount) UploadStream(containerName string, key string, reader io.ReadSeeker, contType string) error { +func (self *SStorageAccount) UploadStream(containerName string, key string, reader io.Reader, contType string) error { container, err := self.getOrCreateContainer(containerName, true) if err != nil { return errors.Wrap(err, "getOrCreateContainer") @@ -849,7 +849,7 @@ func splitKey(key string) (string, string, error) { return containerName, key, nil } -func (b *SStorageAccount) PutObject(ctx context.Context, key string, reader io.ReadSeeker, contType string, storageClassStr string) error { +func (b *SStorageAccount) PutObject(ctx context.Context, key string, reader io.Reader, contType string, storageClassStr string) error { containerName, blob, err := splitKey(key) if err != nil { return errors.Wrap(err, "splitKey") diff --git a/pkg/util/huawei/bucket.go b/pkg/util/huawei/bucket.go index 9f5850658e..b260397673 100644 --- a/pkg/util/huawei/bucket.go +++ b/pkg/util/huawei/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package huawei import ( @@ -139,7 +153,7 @@ func (b *SBucket) ListObjects(prefix string, marker string, delimiter string, ma return result, nil } -func (b *SBucket) PutObject(ctx context.Context, key string, reader io.ReadSeeker, contType string, storageClassStr string) error { +func (b *SBucket) PutObject(ctx context.Context, key string, reader io.Reader, contType string, storageClassStr string) error { obscli, err := b.region.getOBSClient() if err != nil { return errors.Wrap(err, "GetOBSClient") diff --git a/pkg/util/huawei/object.go b/pkg/util/huawei/object.go index 6bd0bb6c46..e4ca71912b 100644 --- a/pkg/util/huawei/object.go +++ b/pkg/util/huawei/object.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package huawei import "yunion.io/x/onecloud/pkg/cloudprovider" diff --git a/pkg/util/huawei/shell/bucket.go b/pkg/util/huawei/shell/bucket.go index ae85368d81..9482e9f16d 100644 --- a/pkg/util/huawei/shell/bucket.go +++ b/pkg/util/huawei/shell/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import ( diff --git a/pkg/util/huawei/shell/obs.go b/pkg/util/huawei/shell/obs.go index 79bc38c8e1..ebfce457c4 100644 --- a/pkg/util/huawei/shell/obs.go +++ b/pkg/util/huawei/shell/obs.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import ( diff --git a/pkg/util/qcloud/bucket.go b/pkg/util/qcloud/bucket.go index 584bf73fb8..00e5fce9b0 100644 --- a/pkg/util/qcloud/bucket.go +++ b/pkg/util/qcloud/bucket.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package qcloud import ( @@ -133,7 +147,7 @@ func (b *SBucket) ListObjects(prefix string, marker string, delimiter string, ma return result, nil } -func (b *SBucket) PutObject(ctx context.Context, key string, reader io.ReadSeeker, contType string, storageClassStr string) error { +func (b *SBucket) PutObject(ctx context.Context, key string, reader io.Reader, contType string, storageClassStr string) error { coscli, err := b.region.GetCosClient(b) if err != nil { return errors.Wrap(err, "GetCosClient") diff --git a/pkg/util/qcloud/object.go b/pkg/util/qcloud/object.go index b9e9218c5c..f91b4dffd7 100644 --- a/pkg/util/qcloud/object.go +++ b/pkg/util/qcloud/object.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package qcloud import "yunion.io/x/onecloud/pkg/cloudprovider" diff --git a/pkg/util/ucloud/shell/ufile.go b/pkg/util/ucloud/shell/ufile.go index ae85368d81..9482e9f16d 100644 --- a/pkg/util/ucloud/shell/ufile.go +++ b/pkg/util/ucloud/shell/ufile.go @@ -1,3 +1,17 @@ +// Copyright 2019 Yunion +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package shell import ( diff --git a/pkg/util/ucloud/ufile.go b/pkg/util/ucloud/ufile.go index 82711bda62..b8c973b02a 100644 --- a/pkg/util/ucloud/ufile.go +++ b/pkg/util/ucloud/ufile.go @@ -218,7 +218,7 @@ func (b *SBucket) ListObjects(prefix string, marker string, delimiter string, ma return result, cloudprovider.ErrNotSupported } -func (b *SBucket) PutObject(ctx context.Context, key string, reader io.ReadSeeker, contType string, storageClassStr string) error { +func (b *SBucket) PutObject(ctx context.Context, key string, reader io.Reader, contType string, storageClassStr string) error { return cloudprovider.ErrNotSupported }