mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
Merge pull request #10450 from ioito/hotfix/qx-license-upload
fix: add license upload
This commit is contained in:
@@ -15,6 +15,12 @@
|
||||
package misc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
@@ -40,6 +46,40 @@ func init() {
|
||||
return nil
|
||||
})
|
||||
|
||||
type LicenseUploadOptions struct {
|
||||
FILE string
|
||||
}
|
||||
|
||||
R(&LicenseUploadOptions{}, "license-upload", "Upload license", func(s *mcclient.ClientSession, args *LicenseUploadOptions) error {
|
||||
bodyBuf := &bytes.Buffer{}
|
||||
bodyWriter := multipart.NewWriter(bodyBuf)
|
||||
fileWriter, err := bodyWriter.CreateFormFile("license", args.FILE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fh, err := os.Open(args.FILE)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fh.Close()
|
||||
_, err = io.Copy(fileWriter, fh)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
contentType := bodyWriter.FormDataContentType()
|
||||
bodyWriter.Close()
|
||||
|
||||
header := http.Header{}
|
||||
header.Set("Content-Type", contentType)
|
||||
lic, err := modules.License.Upload(s, header, bodyBuf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
printObject(lic)
|
||||
return nil
|
||||
})
|
||||
|
||||
type LicenseShowOptions struct {
|
||||
SERVICE string `help:"service name" choices:"compute|service_tree"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user