Merge pull request #668 from wansir/refactor-openpitrix
refactor: openpitrix module
This commit is contained in:
@@ -15,10 +15,13 @@
|
||||
limitations under the License.
|
||||
|
||||
*/
|
||||
package applications
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
appsv1 "k8s.io/api/apps/v1"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
@@ -31,29 +34,20 @@ import (
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/resources"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name" description:"application name"`
|
||||
RepoName string `json:"repoName" description:"repo name"`
|
||||
Runtime string `json:"namespace" description:"namespace name"`
|
||||
RuntimeId string `json:"runtime_id" description:"It is the application runtime in OpenPitrix and represents k8s namespace by annotating the namespace"`
|
||||
Version string `json:"version" description:"application version"`
|
||||
VersionId string `json:"version_id" description:"application version id"`
|
||||
Status string `json:"status" description:"application status"`
|
||||
UpdateTime time.Time `json:"updateTime" description:"the last time this application was updated"`
|
||||
CreateTime time.Time `json:"createTime" description:"application creation time"`
|
||||
App string `json:"app" description:"application template name"`
|
||||
AppId string `json:"app_id" description:"application template id"`
|
||||
Description string `json:"description,omitempty" description:"application description"`
|
||||
WorkLoads *workLoads `json:"workloads,omitempty" description:"application workloads"`
|
||||
Services []v1.Service `json:"services,omitempty" description:"application services"`
|
||||
Ingresses []v1beta1.Ingress `json:"ingresses,omitempty" description:"application ingresses"`
|
||||
ClusterID string `json:"cluster_id" description:"application id"`
|
||||
Name string `json:"name" description:"application name"`
|
||||
Cluster *Cluster `json:"cluster,omitempty" description:"application cluster info"`
|
||||
Version *AppVersion `json:"version,omitempty" description:"application template version info"`
|
||||
App *App `json:"app,omitempty" description:"application template info"`
|
||||
WorkLoads *workLoads `json:"workloads,omitempty" description:"application workloads"`
|
||||
Services []v1.Service `json:"services,omitempty" description:"application services"`
|
||||
Ingresses []v1beta1.Ingress `json:"ingresses,omitempty" description:"application ingresses"`
|
||||
}
|
||||
|
||||
type workLoads struct {
|
||||
@@ -62,92 +56,124 @@ type workLoads struct {
|
||||
Daemonsets []appsv1.DaemonSet `json:"daemonsets,omitempty" description:"daemonset list"`
|
||||
}
|
||||
|
||||
func ListApplication(runtimeId string, conditions *params.Conditions, limit, offset int) (*models.PageableResponse, error) {
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
func ListApplications(conditions *params.Conditions, limit, offset int) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
clusterList, err := openPitrixClient.ListClusters(runtimeId, conditions.Match["keyword"], conditions.Match["status"], limit, offset)
|
||||
describeClustersRequest := &pb.DescribeClustersRequest{
|
||||
Limit: uint32(limit),
|
||||
Offset: uint32(offset)}
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
describeClustersRequest.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if runtimeId := conditions.Match["runtime_id"]; runtimeId != "" {
|
||||
describeClustersRequest.RuntimeId = []string{runtimeId}
|
||||
}
|
||||
if appId := conditions.Match["app_id"]; appId != "" {
|
||||
describeClustersRequest.AppId = []string{appId}
|
||||
}
|
||||
if versionId := conditions.Match["version_id"]; versionId != "" {
|
||||
describeClustersRequest.VersionId = []string{versionId}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
describeClustersRequest.Status = strings.Split(status, "|")
|
||||
}
|
||||
resp, err := client.Cluster().DescribeClusters(openpitrix.SystemContext(), describeClustersRequest)
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
result := models.PageableResponse{TotalCount: clusterList.Total}
|
||||
result := models.PageableResponse{TotalCount: int(resp.TotalCount)}
|
||||
result.Items = make([]interface{}, 0)
|
||||
for _, item := range clusterList.Clusters {
|
||||
var app Application
|
||||
|
||||
app.Name = item.Name
|
||||
app.ClusterID = item.ClusterID
|
||||
app.UpdateTime = item.UpdateTime
|
||||
app.Status = item.Status
|
||||
versionInfo, _ := openPitrixClient.GetVersion(item.VersionID)
|
||||
app.Version = versionInfo
|
||||
app.VersionId = item.VersionID
|
||||
runtimeInfo, _ := openPitrixClient.GetRuntime(item.RunTimeId)
|
||||
app.Runtime = runtimeInfo
|
||||
app.RuntimeId = item.RunTimeId
|
||||
appInfo, _, appId, _ := openPitrixClient.GetAppInfo(item.AppID)
|
||||
app.App = appInfo
|
||||
app.AppId = appId
|
||||
app.Description = item.Description
|
||||
|
||||
for _, cluster := range resp.ClusterSet {
|
||||
app, err := describeApplication(cluster)
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
result.Items = append(result.Items, app)
|
||||
}
|
||||
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func GetApp(clusterId string) (*Application, error) {
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
item, err := openPitrixClient.GetCluster(clusterId)
|
||||
|
||||
func describeApplication(cluster *pb.Cluster) (*Application, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var app Application
|
||||
|
||||
app.Name = item.Name
|
||||
app.ClusterID = item.ClusterID
|
||||
app.UpdateTime = item.UpdateTime
|
||||
app.CreateTime = item.CreateTime
|
||||
app.Status = item.Status
|
||||
versionInfo, _ := openPitrixClient.GetVersion(item.VersionID)
|
||||
app.Version = versionInfo
|
||||
app.VersionId = item.VersionID
|
||||
|
||||
runtimeInfo, _ := openPitrixClient.GetRuntime(item.RunTimeId)
|
||||
app.Runtime = runtimeInfo
|
||||
app.RuntimeId = item.RunTimeId
|
||||
appInfo, repoId, appId, _ := openPitrixClient.GetAppInfo(item.AppID)
|
||||
app.App = appInfo
|
||||
app.AppId = appId
|
||||
app.Description = item.Description
|
||||
|
||||
app.RepoName, _ = openPitrixClient.GetRepo(repoId)
|
||||
|
||||
workloads, err := getWorkLoads(app.Runtime, item.ClusterRoleSets)
|
||||
app.Name = cluster.Name.Value
|
||||
app.Cluster = convertCluster(cluster)
|
||||
versionInfo, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{VersionId: []string{cluster.GetVersionId().GetValue()}})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
app.WorkLoads = workloads
|
||||
workloadLabels := getLabels(app.Runtime, app.WorkLoads)
|
||||
app.Services = getSvcs(app.Runtime, workloadLabels)
|
||||
app.Ingresses = getIng(app.Runtime, app.Services)
|
||||
|
||||
if len(versionInfo.AppVersionSet) > 0 {
|
||||
app.Version = convertAppVersion(versionInfo.AppVersionSet[0])
|
||||
}
|
||||
appInfo, err := op.App().DescribeApps(openpitrix.SystemContext(), &pb.DescribeAppsRequest{AppId: []string{cluster.GetAppId().GetValue()}, Limit: 1})
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
if len(appInfo.AppSet) > 0 {
|
||||
app.App = convertApp(appInfo.GetAppSet()[0])
|
||||
}
|
||||
return &app, nil
|
||||
}
|
||||
|
||||
func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*workLoads, error) {
|
||||
func DescribeApplication(namespace string, clusterId string) (*Application, error) {
|
||||
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
clusters, err := client.Cluster().DescribeClusters(openpitrix.SystemContext(), &pb.DescribeClustersRequest{ClusterId: []string{clusterId}, Limit: 1})
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var cluster *pb.Cluster
|
||||
if len(clusters.ClusterSet) > 0 {
|
||||
cluster = clusters.GetClusterSet()[0]
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
app, err := describeApplication(cluster)
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
workloads, err := getWorkLoads(namespace, cluster.ClusterRoleSet)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
app.WorkLoads = workloads
|
||||
workloadLabels := getLabels(namespace, app.WorkLoads)
|
||||
app.Services = getSvcs(namespace, workloadLabels)
|
||||
app.Ingresses = getIng(namespace, app.Services)
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func getWorkLoads(namespace string, clusterRoles []*pb.ClusterRole) (*workLoads, error) {
|
||||
|
||||
var works workLoads
|
||||
for _, clusterRole := range clusterRoles {
|
||||
workLoadName := clusterRole.Role
|
||||
workLoadName := clusterRole.Role.Value
|
||||
if len(workLoadName) > 0 {
|
||||
if strings.HasSuffix(workLoadName, openpitrix.DeploySuffix) {
|
||||
name := strings.Split(workLoadName, openpitrix.DeploySuffix)[0]
|
||||
@@ -159,7 +185,7 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor
|
||||
if errors.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
klog.Error(err)
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -175,7 +201,7 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor
|
||||
if errors.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
klog.Error(err)
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
works.Daemonsets = append(works.Daemonsets, *item)
|
||||
@@ -190,7 +216,7 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor
|
||||
if errors.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
klog.Error(err)
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
works.Statefulsets = append(works.Statefulsets, *item)
|
||||
@@ -202,9 +228,9 @@ func getWorkLoads(namespace string, clusterRoles []openpitrix.ClusterRole) (*wor
|
||||
}
|
||||
|
||||
func getLabels(namespace string, workloads *workLoads) *[]map[string]string {
|
||||
k8sClient := client.ClientSets().K8s().Kubernetes()
|
||||
k8sClient := cs.ClientSets().K8s().Kubernetes()
|
||||
|
||||
var workloadLables []map[string]string
|
||||
var workloadLabels []map[string]string
|
||||
if workloads == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -214,7 +240,7 @@ func getLabels(namespace string, workloads *workLoads) *[]map[string]string {
|
||||
if errors.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
workloadLables = append(workloadLables, deploy.Labels)
|
||||
workloadLabels = append(workloadLabels, deploy.Labels)
|
||||
}
|
||||
|
||||
for _, workload := range workloads.Daemonsets {
|
||||
@@ -222,7 +248,7 @@ func getLabels(namespace string, workloads *workLoads) *[]map[string]string {
|
||||
if errors.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
workloadLables = append(workloadLables, daemonset.Labels)
|
||||
workloadLabels = append(workloadLabels, daemonset.Labels)
|
||||
}
|
||||
|
||||
for _, workload := range workloads.Statefulsets {
|
||||
@@ -230,10 +256,10 @@ func getLabels(namespace string, workloads *workLoads) *[]map[string]string {
|
||||
if errors.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
workloadLables = append(workloadLables, statefulset.Labels)
|
||||
workloadLabels = append(workloadLabels, statefulset.Labels)
|
||||
}
|
||||
|
||||
return &workloadLables
|
||||
return &workloadLabels
|
||||
}
|
||||
|
||||
func isExist(svcs []v1.Service, svc v1.Service) bool {
|
||||
@@ -249,7 +275,7 @@ func getSvcs(namespace string, workLoadLabels *[]map[string]string) []v1.Service
|
||||
if len(*workLoadLabels) == 0 {
|
||||
return nil
|
||||
}
|
||||
k8sClient := client.ClientSets().K8s().Kubernetes()
|
||||
k8sClient := cs.ClientSets().K8s().Kubernetes()
|
||||
var services []v1.Service
|
||||
for _, label := range *workLoadLabels {
|
||||
labelSelector := labels.Set(label).AsSelector().String()
|
||||
@@ -276,11 +302,10 @@ func getIng(namespace string, services []v1.Service) []v1beta1.Ingress {
|
||||
for _, svc := range services {
|
||||
result, err := resources.ListResources(namespace, "ingress", ¶ms.Conditions{Fuzzy: map[string]string{"serviceName": svc.Name}}, "", false, -1, 0)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
klog.Errorln(err)
|
||||
return nil
|
||||
}
|
||||
|
||||
klog.Error(result)
|
||||
for _, i := range result.Items {
|
||||
ingress := i.(*v1beta1.Ingress)
|
||||
|
||||
@@ -308,31 +333,80 @@ func getIng(namespace string, services []v1.Service) []v1beta1.Ingress {
|
||||
return ings
|
||||
}
|
||||
|
||||
func DeployApplication(namespace string, app openpitrix.CreateClusterRequest) error {
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
func CreateApplication(namespace string, request CreateClusterRequest) error {
|
||||
ns, err := informers.SharedInformerFactory().Core().V1().Namespaces().Lister().Get(namespace)
|
||||
if err != nil {
|
||||
klog.Errorf("deploy application failed: %+v", err)
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if runtimeId := ns.Annotations[constants.OpenPitrixRuntimeAnnotationKey]; runtimeId != "" {
|
||||
app.RuntimeId = runtimeId
|
||||
request.RuntimeId = runtimeId
|
||||
} else {
|
||||
return fmt.Errorf("runtime not init: namespace %s", namespace)
|
||||
}
|
||||
return openPitrixClient.CreateCluster(app)
|
||||
}
|
||||
|
||||
func DeleteApplication(clusterId string) error {
|
||||
openPitrixClient, err := client.ClientSets().OpenPitrix()
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return openPitrixClient.DeleteCluster(openpitrix.DeleteClusterRequest{ClusterId: []string{clusterId}})
|
||||
_, err = client.Cluster().CreateCluster(openpitrix.ContextWithUsername(request.Username), &pb.CreateClusterRequest{
|
||||
AppId: &wrappers.StringValue{Value: request.AppId},
|
||||
VersionId: &wrappers.StringValue{Value: request.VersionId},
|
||||
RuntimeId: &wrappers.StringValue{Value: request.RuntimeId},
|
||||
Conf: &wrappers.StringValue{Value: request.Conf},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchApplication(request *ModifyClusterAttributesRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
modifyClusterAttributesRequest := &pb.ModifyClusterAttributesRequest{ClusterId: &wrappers.StringValue{Value: request.ClusterID}}
|
||||
if request.Name != nil {
|
||||
modifyClusterAttributesRequest.Name = &wrappers.StringValue{Value: *request.Name}
|
||||
}
|
||||
if request.Description != nil {
|
||||
modifyClusterAttributesRequest.Description = &wrappers.StringValue{Value: *request.Description}
|
||||
}
|
||||
|
||||
_, err = op.Cluster().ModifyClusterAttributes(openpitrix.SystemContext(), modifyClusterAttributesRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeleteApplication(clusterId string) error {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = client.Cluster().DeleteClusters(openpitrix.SystemContext(), &pb.DeleteClustersRequest{ClusterId: []string{clusterId}, Force: &wrappers.BoolValue{Value: true}})
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
680
pkg/models/openpitrix/apps.go
Normal file
680
pkg/models/openpitrix/apps.go
Normal file
@@ -0,0 +1,680 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
*
|
||||
* 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 openpitrix
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
describeAppsRequest := &pb.DescribeAppsRequest{}
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
describeAppsRequest.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if appId := conditions.Match["app_id"]; appId != "" {
|
||||
describeAppsRequest.AppId = strings.Split(appId, "|")
|
||||
}
|
||||
if isv := conditions.Match["isv"]; isv != "" {
|
||||
describeAppsRequest.Isv = strings.Split(isv, "|")
|
||||
}
|
||||
if categoryId := conditions.Match["category_id"]; categoryId != "" {
|
||||
describeAppsRequest.CategoryId = strings.Split(categoryId, "|")
|
||||
}
|
||||
if repoId := conditions.Match["repo"]; repoId != "" {
|
||||
describeAppsRequest.RepoId = strings.Split(repoId, "|")
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
describeAppsRequest.Status = strings.Split(status, "|")
|
||||
}
|
||||
if orderBy != "" {
|
||||
describeAppsRequest.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeAppsRequest.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
describeAppsRequest.Limit = uint32(limit)
|
||||
describeAppsRequest.Offset = uint32(offset)
|
||||
resp, err := client.App().DescribeApps(openpitrix.SystemContext(), describeAppsRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppSet {
|
||||
items = append(items, convertApp(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func DescribeApp(id string) (*App, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := op.App().DescribeApps(openpitrix.SystemContext(), &pb.DescribeAppsRequest{
|
||||
AppId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var app *App
|
||||
|
||||
if len(resp.AppSet) > 0 {
|
||||
app = convertApp(resp.AppSet[0])
|
||||
return app, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func DeleteApp(id string) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
_, err = op.App().DeleteApps(openpitrix.SystemContext(), &pb.DeleteAppsRequest{
|
||||
AppId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateApp(request *CreateAppRequest) (*CreateAppResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
createAppRequest := &pb.CreateAppRequest{
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
VersionType: &wrappers.StringValue{Value: request.VersionType},
|
||||
VersionName: &wrappers.StringValue{Value: request.VersionName},
|
||||
}
|
||||
if request.VersionPackage != nil {
|
||||
createAppRequest.VersionPackage = &wrappers.BytesValue{Value: request.VersionPackage}
|
||||
}
|
||||
if request.Icon != nil {
|
||||
createAppRequest.Icon = &wrappers.BytesValue{Value: request.Icon}
|
||||
}
|
||||
if request.Isv != "" {
|
||||
createAppRequest.Isv = &wrappers.StringValue{Value: request.Isv}
|
||||
}
|
||||
resp, err := op.App().CreateApp(openpitrix.SystemContext(), createAppRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateAppResponse{
|
||||
AppID: resp.GetAppId().GetValue(),
|
||||
VersionID: resp.GetVersionId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func PatchApp(appId string, request *ModifyAppRequest) error {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// upload app attachment
|
||||
if request.AttachmentContent != nil {
|
||||
uploadAttachmentRequest := &pb.UploadAppAttachmentRequest{
|
||||
AppId: &wrappers.StringValue{Value: appId},
|
||||
AttachmentContent: &wrappers.BytesValue{Value: request.AttachmentContent},
|
||||
}
|
||||
if request.Type != nil {
|
||||
uploadAttachmentRequest.Type = pb.UploadAppAttachmentRequest_Type(pb.UploadAppAttachmentRequest_Type_value[*request.Type])
|
||||
}
|
||||
if request.Sequence != nil {
|
||||
uploadAttachmentRequest.Sequence = &wrappers.UInt32Value{Value: uint32(*request.Sequence)}
|
||||
}
|
||||
|
||||
_, err := client.App().UploadAppAttachment(openpitrix.SystemContext(), uploadAttachmentRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
// patch app
|
||||
} else {
|
||||
patchAppRequest := &pb.ModifyAppRequest{
|
||||
AppId: &wrappers.StringValue{Value: appId},
|
||||
}
|
||||
|
||||
if request.Abstraction != nil {
|
||||
patchAppRequest.Abstraction = &wrappers.StringValue{Value: *request.Abstraction}
|
||||
}
|
||||
if request.CategoryID != nil {
|
||||
patchAppRequest.CategoryId = &wrappers.StringValue{Value: *request.CategoryID}
|
||||
}
|
||||
if request.Description != nil {
|
||||
patchAppRequest.Description = &wrappers.StringValue{Value: *request.Description}
|
||||
}
|
||||
if request.Home != nil {
|
||||
patchAppRequest.Home = &wrappers.StringValue{Value: *request.Home}
|
||||
}
|
||||
if request.Keywords != nil {
|
||||
patchAppRequest.Keywords = &wrappers.StringValue{Value: *request.Keywords}
|
||||
}
|
||||
if request.Maintainers != nil {
|
||||
patchAppRequest.Maintainers = &wrappers.StringValue{Value: *request.Maintainers}
|
||||
}
|
||||
if request.Name != nil {
|
||||
patchAppRequest.Name = &wrappers.StringValue{Value: *request.Name}
|
||||
}
|
||||
if request.Readme != nil {
|
||||
patchAppRequest.Readme = &wrappers.StringValue{Value: *request.Readme}
|
||||
}
|
||||
if request.Sources != nil {
|
||||
patchAppRequest.Sources = &wrappers.StringValue{Value: *request.Sources}
|
||||
}
|
||||
if request.Tos != nil {
|
||||
patchAppRequest.Tos = &wrappers.StringValue{Value: *request.Tos}
|
||||
}
|
||||
|
||||
_, err = client.App().ModifyApp(openpitrix.SystemContext(), patchAppRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateAppVersion(request *CreateAppVersionRequest) (*CreateAppVersionResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
createAppVersionRequest := &pb.CreateAppVersionRequest{
|
||||
AppId: &wrappers.StringValue{Value: request.AppId},
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
Description: &wrappers.StringValue{Value: request.Description},
|
||||
Type: &wrappers.StringValue{Value: request.Type},
|
||||
}
|
||||
|
||||
if request.Package != nil {
|
||||
createAppVersionRequest.Package = &wrappers.BytesValue{Value: request.Package}
|
||||
}
|
||||
|
||||
resp, err := op.App().CreateAppVersion(openpitrix.SystemContext(), createAppVersionRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateAppVersionResponse{
|
||||
VersionId: resp.GetVersionId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ValidatePackage(request *ValidatePackageRequest) (*ValidatePackageResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := &pb.ValidatePackageRequest{}
|
||||
|
||||
if request.VersionPackage != nil {
|
||||
r.VersionPackage = request.VersionPackage
|
||||
}
|
||||
if request.VersionType != "" {
|
||||
r.VersionType = request.VersionType
|
||||
}
|
||||
|
||||
resp, err := client.App().ValidatePackage(openpitrix.SystemContext(), r)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &ValidatePackageResponse{}
|
||||
|
||||
if resp.Error != nil {
|
||||
result.Error = resp.Error.Value
|
||||
}
|
||||
if resp.Description != nil {
|
||||
result.Description = resp.Description.Value
|
||||
}
|
||||
if resp.Error != nil {
|
||||
result.Error = resp.Error.Value
|
||||
}
|
||||
if resp.ErrorDetails != nil {
|
||||
result.ErrorDetails = resp.ErrorDetails
|
||||
}
|
||||
if resp.Name != nil {
|
||||
result.Name = resp.Name.Value
|
||||
}
|
||||
if resp.Url != nil {
|
||||
result.URL = resp.Url.Value
|
||||
}
|
||||
if resp.VersionName != nil {
|
||||
result.VersionName = resp.VersionName.Value
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func DeleteAppVersion(id string) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
_, err = op.App().DeleteAppVersion(openpitrix.SystemContext(), &pb.DeleteAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: id},
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchAppVersion(id string, request *ModifyAppVersionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
modifyAppVersionRequest := &pb.ModifyAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: id},
|
||||
}
|
||||
|
||||
if request.Name != nil {
|
||||
modifyAppVersionRequest.Name = &wrappers.StringValue{Value: *request.Name}
|
||||
}
|
||||
if request.Description != nil {
|
||||
modifyAppVersionRequest.Description = &wrappers.StringValue{Value: *request.Description}
|
||||
}
|
||||
if request.Package != nil {
|
||||
modifyAppVersionRequest.Package = &wrappers.BytesValue{Value: request.Package}
|
||||
}
|
||||
if request.PackageFiles != nil {
|
||||
modifyAppVersionRequest.PackageFiles = request.PackageFiles
|
||||
}
|
||||
|
||||
_, err = op.App().ModifyAppVersion(openpitrix.SystemContext(), modifyAppVersionRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeAppVersion(id string) (*AppVersion, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
VersionId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var app *AppVersion
|
||||
|
||||
if len(resp.AppVersionSet) > 0 {
|
||||
app = convertAppVersion(resp.AppVersionSet[0])
|
||||
return app, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func GetAppVersionPackage(appId, versionId string) (*GetAppVersionPackageResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := op.App().GetAppVersionPackage(openpitrix.SystemContext(), &pb.GetAppVersionPackageRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
app := &GetAppVersionPackageResponse{
|
||||
AppId: appId,
|
||||
VersionId: versionId,
|
||||
}
|
||||
|
||||
if resp.Package != nil {
|
||||
app.Package = resp.Package
|
||||
}
|
||||
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func DoAppAction(appId string, request *ActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
switch request.Action {
|
||||
|
||||
case "recover":
|
||||
// TODO openpitrix need to implement app recover interface
|
||||
resp, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
AppId: []string{appId},
|
||||
Status: []string{"suspended"},
|
||||
Limit: 200,
|
||||
Offset: 0,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
for _, version := range resp.AppVersionSet {
|
||||
|
||||
_, err = op.App().RecoverAppVersion(openpitrix.SystemContext(), &pb.RecoverAppVersionRequest{
|
||||
VersionId: version.VersionId,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
case "suspend":
|
||||
// TODO openpitrix need to implement app suspend interface
|
||||
resp, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
AppId: []string{appId},
|
||||
Status: []string{"active"},
|
||||
Limit: 200,
|
||||
Offset: 0,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
for _, version := range resp.AppVersionSet {
|
||||
_, err = op.App().SuspendAppVersion(openpitrix.SystemContext(), &pb.SuspendAppVersionRequest{
|
||||
VersionId: version.VersionId,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
err = status.New(codes.InvalidArgument, "action not support").Err()
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DoAppVersionAction(versionId string, request *ActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
switch request.Action {
|
||||
case "cancel":
|
||||
_, err = op.App().CancelAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.CancelAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "pass":
|
||||
_, err = op.App().AdminPassAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.PassAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "recover":
|
||||
_, err = op.App().RecoverAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.RecoverAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "reject":
|
||||
_, err = op.App().AdminRejectAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.RejectAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
Message: &wrappers.StringValue{Value: request.Message},
|
||||
})
|
||||
case "submit":
|
||||
_, err = op.App().SubmitAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.SubmitAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "suspend":
|
||||
_, err = op.App().SuspendAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.SuspendAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "release":
|
||||
_, err = op.App().ReleaseAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.ReleaseAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
default:
|
||||
err = status.New(codes.InvalidArgument, "action not support").Err()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAppVersionFiles(versionId string, request *GetAppVersionFilesRequest) (*GetAppVersionPackageFilesResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
getAppVersionPackageFilesRequest := &pb.GetAppVersionPackageFilesRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
}
|
||||
if request.Files != nil {
|
||||
getAppVersionPackageFilesRequest.Files = request.Files
|
||||
}
|
||||
|
||||
resp, err := op.App().GetAppVersionPackageFiles(openpitrix.SystemContext(), getAppVersionPackageFilesRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
version := &GetAppVersionPackageFilesResponse{
|
||||
VersionId: versionId,
|
||||
}
|
||||
|
||||
if resp.Files != nil {
|
||||
version.Files = make(map[string]strfmt.Base64)
|
||||
for k, v := range resp.Files {
|
||||
version.Files[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return version, nil
|
||||
}
|
||||
|
||||
func ListAppVersionAudits(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
describeAppVersionAudits := &pb.DescribeAppVersionAuditsRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
describeAppVersionAudits.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if appId := conditions.Match["app"]; appId != "" {
|
||||
describeAppVersionAudits.AppId = []string{appId}
|
||||
}
|
||||
if versionId := conditions.Match["version"]; versionId != "" {
|
||||
describeAppVersionAudits.VersionId = []string{versionId}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
describeAppVersionAudits.Status = strings.Split(status, "|")
|
||||
}
|
||||
if orderBy != "" {
|
||||
describeAppVersionAudits.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeAppVersionAudits.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
describeAppVersionAudits.Limit = uint32(limit)
|
||||
describeAppVersionAudits.Offset = uint32(offset)
|
||||
resp, err := client.App().DescribeAppVersionAudits(openpitrix.SystemContext(), describeAppVersionAudits)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionAuditSet {
|
||||
appVersion := convertAppVersionAudit(item)
|
||||
items = append(items, appVersion)
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func ListAppVersionReviews(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
describeAppVersionReviews := &pb.DescribeAppVersionReviewsRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
describeAppVersionReviews.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
describeAppVersionReviews.Status = strings.Split(status, "|")
|
||||
}
|
||||
if orderBy != "" {
|
||||
describeAppVersionReviews.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeAppVersionReviews.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
describeAppVersionReviews.Limit = uint32(limit)
|
||||
describeAppVersionReviews.Offset = uint32(offset)
|
||||
// TODO icon is needed
|
||||
resp, err := client.App().DescribeAppVersionReviews(openpitrix.SystemContext(), describeAppVersionReviews)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionReviewSet {
|
||||
appVersion := convertAppVersionReview(item)
|
||||
items = append(items, appVersion)
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func ListAppVersions(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
describeAppVersionsRequest := &pb.DescribeAppVersionsRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
describeAppVersionsRequest.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if appId := conditions.Match["app"]; appId != "" {
|
||||
describeAppVersionsRequest.AppId = []string{appId}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
describeAppVersionsRequest.Status = strings.Split(status, "|")
|
||||
}
|
||||
if orderBy != "" {
|
||||
describeAppVersionsRequest.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeAppVersionsRequest.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
describeAppVersionsRequest.Limit = uint32(limit)
|
||||
describeAppVersionsRequest.Offset = uint32(offset)
|
||||
resp, err := client.App().DescribeAppVersions(openpitrix.SystemContext(), describeAppVersionsRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionSet {
|
||||
appVersion := convertAppVersion(item)
|
||||
items = append(items, appVersion)
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
50
pkg/models/openpitrix/attachments.go
Normal file
50
pkg/models/openpitrix/attachments.go
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
*
|
||||
* 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 openpitrix
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
)
|
||||
|
||||
func DescribeAttachment(id string) (*Attachment, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := op.Attachment().GetAttachments(openpitrix.SystemContext(), &pb.GetAttachmentsRequest{
|
||||
AttachmentId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
if len(resp.Attachments) > 0 {
|
||||
return convertAttachment(resp.Attachments[id]), nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
163
pkg/models/openpitrix/categories.go
Normal file
163
pkg/models/openpitrix/categories.go
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
*
|
||||
* 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 openpitrix
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
)
|
||||
|
||||
func CreateCategory(request *CreateCategoryRequest) (*CreateCategoryResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
r := &pb.CreateCategoryRequest{
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
Locale: &wrappers.StringValue{Value: request.Locale},
|
||||
Description: &wrappers.StringValue{Value: request.Description},
|
||||
}
|
||||
if request.Icon != nil {
|
||||
r.Icon = &wrappers.BytesValue{Value: request.Icon}
|
||||
}
|
||||
|
||||
resp, err := op.Category().CreateCategory(openpitrix.SystemContext(), r)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateCategoryResponse{
|
||||
CategoryId: resp.GetCategoryId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeleteCategory(id string) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
_, err = op.Category().DeleteCategories(openpitrix.SystemContext(), &pb.DeleteCategoriesRequest{
|
||||
CategoryId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchCategory(id string, request *ModifyCategoryRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
modifyCategoryRequest := &pb.ModifyCategoryRequest{
|
||||
CategoryId: &wrappers.StringValue{Value: id},
|
||||
}
|
||||
if request.Name != nil {
|
||||
modifyCategoryRequest.Name = &wrappers.StringValue{Value: *request.Name}
|
||||
}
|
||||
if request.Locale != nil {
|
||||
modifyCategoryRequest.Locale = &wrappers.StringValue{Value: *request.Locale}
|
||||
}
|
||||
if request.Description != nil {
|
||||
modifyCategoryRequest.Description = &wrappers.StringValue{Value: *request.Description}
|
||||
}
|
||||
if request.Icon != nil {
|
||||
modifyCategoryRequest.Icon = &wrappers.BytesValue{Value: request.Icon}
|
||||
}
|
||||
|
||||
_, err = op.Category().ModifyCategory(openpitrix.SystemContext(), modifyCategoryRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeCategory(id string) (*Category, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := op.Category().DescribeCategories(openpitrix.SystemContext(), &pb.DescribeCategoriesRequest{
|
||||
CategoryId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var category *Category
|
||||
|
||||
if len(resp.CategorySet) > 0 {
|
||||
category = convertCategory(resp.CategorySet[0])
|
||||
return category, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func ListCategories(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := &pb.DescribeCategoriesRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
req.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if orderBy != "" {
|
||||
req.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
req.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
req.Limit = uint32(limit)
|
||||
req.Offset = uint32(offset)
|
||||
resp, err := client.Category().DescribeCategories(openpitrix.SystemContext(), req)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.CategorySet {
|
||||
items = append(items, convertCategory(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
647
pkg/models/openpitrix/convert.go
Normal file
647
pkg/models/openpitrix/convert.go
Normal file
@@ -0,0 +1,647 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
*
|
||||
* 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 openpitrix
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
"time"
|
||||
)
|
||||
|
||||
func convertApp(in *pb.App) *App {
|
||||
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
categorySet := make(AppCategorySet, 0)
|
||||
|
||||
for _, item := range in.CategorySet {
|
||||
category := convertResourceCategory(item)
|
||||
categorySet = append(categorySet, category)
|
||||
}
|
||||
|
||||
out := App{
|
||||
CategorySet: categorySet,
|
||||
}
|
||||
|
||||
if in.Abstraction != nil {
|
||||
out.Abstraction = in.Abstraction.Value
|
||||
}
|
||||
if in.Active != nil {
|
||||
out.Active = in.Active.Value
|
||||
}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
if in.AppVersionTypes != nil {
|
||||
out.AppVersionTypes = in.AppVersionTypes.Value
|
||||
}
|
||||
if in.ChartName != nil {
|
||||
out.ChartName = in.ChartName.Value
|
||||
}
|
||||
if in.CompanyJoinTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CompanyJoinTime.Seconds, 0))
|
||||
out.CompanyJoinTime = &date
|
||||
}
|
||||
if in.CompanyName != nil {
|
||||
out.CompanyName = in.CompanyName.Value
|
||||
}
|
||||
if in.CompanyProfile != nil {
|
||||
out.CompanyProfile = in.CompanyProfile.Value
|
||||
}
|
||||
if in.CompanyWebsite != nil {
|
||||
out.CompanyWebsite = in.CompanyWebsite.Value
|
||||
}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.CompanyWebsite != nil {
|
||||
out.CompanyWebsite = in.CompanyWebsite.Value
|
||||
}
|
||||
if in.Description != nil {
|
||||
out.Description = in.Description.Value
|
||||
}
|
||||
if in.Home != nil {
|
||||
out.Home = in.Home.Value
|
||||
}
|
||||
if in.Icon != nil {
|
||||
out.Icon = in.Icon.Value
|
||||
}
|
||||
if in.Isv != nil {
|
||||
out.Isv = in.Isv.Value
|
||||
}
|
||||
if in.Keywords != nil {
|
||||
out.Keywords = in.Keywords.Value
|
||||
}
|
||||
if in.LatestAppVersion != nil {
|
||||
out.LatestAppVersion = convertAppVersion(in.LatestAppVersion)
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
}
|
||||
if in.Owner != nil {
|
||||
out.Owner = in.Owner.Value
|
||||
}
|
||||
if in.Readme != nil {
|
||||
out.Readme = in.Readme.Value
|
||||
}
|
||||
if in.RepoId != nil {
|
||||
out.RepoId = in.RepoId.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
out.StatusTime = &date
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.Sources != nil {
|
||||
out.Sources = in.Sources.Value
|
||||
}
|
||||
if in.Screenshots != nil {
|
||||
out.Screenshots = in.Screenshots.Value
|
||||
}
|
||||
if in.Tos != nil {
|
||||
out.Tos = in.Tos.Value
|
||||
}
|
||||
if in.UpdateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.UpdateTime.Seconds, 0))
|
||||
out.UpdateTime = &date
|
||||
}
|
||||
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersion(in *pb.AppVersion) *AppVersion {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersion{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
if in.Active != nil {
|
||||
out.Active = in.Active.Value
|
||||
}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.Description != nil {
|
||||
out.Description = in.Description.Value
|
||||
}
|
||||
if in.Home != nil {
|
||||
out.Home = in.Home.Value
|
||||
}
|
||||
if in.Icon != nil {
|
||||
out.Icon = in.Icon.Value
|
||||
}
|
||||
if in.Maintainers != nil {
|
||||
out.Maintainers = in.Maintainers.Value
|
||||
}
|
||||
if in.Message != nil {
|
||||
out.Message = in.Message.Value
|
||||
}
|
||||
if in.Keywords != nil {
|
||||
out.Keywords = in.Keywords.Value
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
}
|
||||
if in.Owner != nil {
|
||||
out.Owner = in.Owner.Value
|
||||
}
|
||||
if in.PackageName != nil {
|
||||
out.PackageName = in.PackageName.Value
|
||||
}
|
||||
if in.Readme != nil {
|
||||
out.Readme = in.Readme.Value
|
||||
}
|
||||
if in.ReviewId != nil {
|
||||
out.ReviewId = in.ReviewId.Value
|
||||
}
|
||||
if in.Screenshots != nil {
|
||||
out.Screenshots = in.Screenshots.Value
|
||||
}
|
||||
if in.Sources != nil {
|
||||
out.Sources = in.Sources.Value
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.Sequence != nil {
|
||||
out.Sequence = int64(in.Sequence.Value)
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
out.StatusTime = &date
|
||||
}
|
||||
if in.Type != nil {
|
||||
out.Type = in.Type.Value
|
||||
}
|
||||
if in.UpdateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.UpdateTime.Seconds, 0))
|
||||
out.UpdateTime = &date
|
||||
}
|
||||
if in.VersionId != nil {
|
||||
out.VersionId = in.VersionId.Value
|
||||
}
|
||||
|
||||
return &out
|
||||
|
||||
}
|
||||
|
||||
func convertResourceCategory(in *pb.ResourceCategory) *ResourceCategory {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := ResourceCategory{}
|
||||
|
||||
if in.CategoryId != nil {
|
||||
out.CategoryId = in.CategoryId.Value
|
||||
}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.Locale != nil {
|
||||
out.Locale = in.Locale.Value
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
out.StatusTime = &date
|
||||
}
|
||||
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertCategory(in *pb.Category) *Category {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Category{}
|
||||
|
||||
if in.CategoryId != nil {
|
||||
out.CategoryID = in.CategoryId.Value
|
||||
}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.Locale != nil {
|
||||
out.Locale = in.Locale.Value
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
}
|
||||
if in.Description != nil {
|
||||
out.Description = in.Description.Value
|
||||
}
|
||||
if in.Icon != nil {
|
||||
out.Icon = in.Icon.Value
|
||||
}
|
||||
if in.Owner != nil {
|
||||
out.Owner = in.Owner.Value
|
||||
}
|
||||
if in.UpdateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.UpdateTime.Seconds, 0))
|
||||
out.UpdateTime = &date
|
||||
}
|
||||
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAttachment(in *pb.Attachment) *Attachment {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Attachment{}
|
||||
|
||||
out.AttachmentID = in.AttachmentId
|
||||
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.AttachmentContent != nil {
|
||||
out.AttachmentContent = make(map[string]strfmt.Base64)
|
||||
for k, v := range in.AttachmentContent {
|
||||
out.AttachmentContent[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepo(in *pb.Repo) *Repo {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Repo{}
|
||||
|
||||
if in.RepoId != nil {
|
||||
out.RepoId = in.RepoId.Value
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
}
|
||||
if in.AppDefaultStatus != nil {
|
||||
out.AppDefaultStatus = in.AppDefaultStatus.Value
|
||||
}
|
||||
if in.Credential != nil {
|
||||
out.Credential = in.Credential.Value
|
||||
}
|
||||
|
||||
categorySet := make(RepoCategorySet, 0)
|
||||
|
||||
for _, item := range in.CategorySet {
|
||||
category := convertResourceCategory(item)
|
||||
categorySet = append(categorySet, category)
|
||||
}
|
||||
|
||||
out.CategorySet = categorySet
|
||||
|
||||
if in.Controller != nil {
|
||||
out.Credential = in.Credential.Value
|
||||
}
|
||||
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
|
||||
if in.Description != nil {
|
||||
out.Description = in.Description.Value
|
||||
}
|
||||
|
||||
labelSet := make(RepoLabels, 0)
|
||||
|
||||
for _, item := range in.Labels {
|
||||
label := convertRepoLabel(item)
|
||||
labelSet = append(labelSet, label)
|
||||
}
|
||||
|
||||
out.Labels = labelSet
|
||||
|
||||
if in.Owner != nil {
|
||||
out.Owner = in.Owner.Value
|
||||
}
|
||||
if in.Providers != nil {
|
||||
out.Providers = in.Providers
|
||||
}
|
||||
if in.RepoId != nil {
|
||||
out.RepoId = in.RepoId.Value
|
||||
}
|
||||
|
||||
selectorSet := make(RepoSelectors, 0)
|
||||
|
||||
for _, item := range in.Selectors {
|
||||
selector := convertRepoSelector(item)
|
||||
selectorSet = append(selectorSet, selector)
|
||||
}
|
||||
|
||||
out.Selectors = selectorSet
|
||||
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
out.StatusTime = strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
}
|
||||
if in.Type != nil {
|
||||
out.Type = in.Type.Value
|
||||
}
|
||||
if in.Url != nil {
|
||||
out.URL = in.Url.Value
|
||||
}
|
||||
if in.Visibility != nil {
|
||||
out.Visibility = in.Visibility.Value
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepoLabel(in *pb.RepoLabel) *RepoLabel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := RepoLabel{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.LabelKey != nil {
|
||||
out.LabelKey = in.LabelKey.Value
|
||||
}
|
||||
if in.LabelValue != nil {
|
||||
out.LabelValue = in.LabelValue.Value
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepoSelector(in *pb.RepoSelector) *RepoSelector {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := RepoSelector{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.SelectorKey != nil {
|
||||
out.SelectorKey = in.SelectorKey.Value
|
||||
}
|
||||
if in.SelectorValue != nil {
|
||||
out.SelectorValue = in.SelectorValue.Value
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersionAudit(in *pb.AppVersionAudit) *AppVersionAudit {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersionAudit{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
if in.AppName != nil {
|
||||
out.AppName = in.AppName.Value
|
||||
}
|
||||
if in.Message != nil {
|
||||
out.Message = in.Message.Value
|
||||
}
|
||||
if in.Operator != nil {
|
||||
out.Operator = in.Operator.Value
|
||||
}
|
||||
if in.OperatorType != nil {
|
||||
out.OperatorType = in.OperatorType.Value
|
||||
}
|
||||
if in.ReviewId != nil {
|
||||
out.ReviewId = in.ReviewId.Value
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
out.StatusTime = &date
|
||||
}
|
||||
if in.VersionId != nil {
|
||||
out.VersionId = in.VersionId.Value
|
||||
}
|
||||
if in.VersionName != nil {
|
||||
out.VersionName = in.VersionName.Value
|
||||
}
|
||||
if in.VersionType != nil {
|
||||
out.VersionType = in.VersionType.Value
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersionReview(in *pb.AppVersionReview) *AppVersionReview {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersionReview{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
if in.AppName != nil {
|
||||
out.AppName = in.AppName.Value
|
||||
}
|
||||
if in.Phase != nil {
|
||||
out.Phase = make(AppVersionReviewPhaseOAIGen)
|
||||
for k, v := range in.Phase {
|
||||
out.Phase[k] = *convertAppVersionReviewPhase(v)
|
||||
}
|
||||
}
|
||||
if in.ReviewId != nil {
|
||||
out.ReviewId = in.ReviewId.Value
|
||||
}
|
||||
if in.Reviewer != nil {
|
||||
out.Reviewer = in.Reviewer.Value
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
out.StatusTime = strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
}
|
||||
if in.VersionId != nil {
|
||||
out.VersionID = in.VersionId.Value
|
||||
}
|
||||
if in.VersionName != nil {
|
||||
out.VersionName = in.VersionName.Value
|
||||
}
|
||||
if in.VersionType != nil {
|
||||
out.VersionType = in.VersionType.Value
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertAppVersionReviewPhase(in *pb.AppVersionReviewPhase) *AppVersionReviewPhase {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := AppVersionReviewPhase{}
|
||||
if in.Message != nil {
|
||||
out.Message = in.Message.Value
|
||||
}
|
||||
if in.OperatorType != nil {
|
||||
out.OperatorType = in.OperatorType.Value
|
||||
}
|
||||
if in.ReviewTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.ReviewTime.Seconds, 0))
|
||||
out.ReviewTime = &date
|
||||
}
|
||||
if in.Operator != nil {
|
||||
out.Operator = in.Operator.Value
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
out.StatusTime = &date
|
||||
}
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertRepoEvent(in *pb.RepoEvent) *RepoEvent {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := RepoEvent{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.Owner != nil {
|
||||
out.Owner = in.Owner.Value
|
||||
}
|
||||
if in.RepoEventId != nil {
|
||||
out.RepoEventId = in.RepoEventId.Value
|
||||
}
|
||||
if in.RepoId != nil {
|
||||
out.RepoId = in.RepoId.Value
|
||||
}
|
||||
if in.Result != nil {
|
||||
out.Result = in.Result.Value
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
out.StatusTime = &date
|
||||
}
|
||||
|
||||
return &out
|
||||
}
|
||||
|
||||
func convertCluster(in *pb.Cluster) *Cluster {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := Cluster{}
|
||||
if in.AdditionalInfo != nil {
|
||||
out.AdditionalInfo = in.AdditionalInfo.Value
|
||||
}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
if in.ClusterId != nil {
|
||||
out.ClusterId = in.ClusterId.Value
|
||||
}
|
||||
if in.ClusterType != nil {
|
||||
out.ClusterType = int64(in.ClusterType.Value)
|
||||
}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
}
|
||||
if in.Debug != nil {
|
||||
out.Debug = in.Debug.Value
|
||||
}
|
||||
if in.Description != nil {
|
||||
out.Description = in.Description.Value
|
||||
}
|
||||
if in.Endpoints != nil {
|
||||
out.Endpoints = in.Endpoints.Value
|
||||
}
|
||||
if in.Env != nil {
|
||||
out.Env = in.Env.Value
|
||||
}
|
||||
if in.FrontgateId != nil {
|
||||
out.FrontgateId = in.FrontgateId.Value
|
||||
}
|
||||
if in.GlobalUuid != nil {
|
||||
out.GlobalUUID = in.GlobalUuid.Value
|
||||
}
|
||||
if in.MetadataRootAccess != nil {
|
||||
out.MetadataRootAccess = in.MetadataRootAccess.Value
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
}
|
||||
if in.Owner != nil {
|
||||
out.Owner = in.Owner.Value
|
||||
}
|
||||
if in.RuntimeId != nil {
|
||||
out.RuntimeId = in.RuntimeId.Value
|
||||
}
|
||||
if in.Status != nil {
|
||||
out.Status = in.Status.Value
|
||||
}
|
||||
if in.StatusTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.StatusTime.Seconds, 0))
|
||||
out.StatusTime = &date
|
||||
}
|
||||
if in.SubnetId != nil {
|
||||
out.SubnetId = in.SubnetId.Value
|
||||
}
|
||||
if in.TransitionStatus != nil {
|
||||
out.TransitionStatus = in.TransitionStatus.Value
|
||||
}
|
||||
if in.UpgradeStatus != nil {
|
||||
out.UpgradeStatus = in.UpgradeStatus.Value
|
||||
}
|
||||
if in.UpgradeTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.UpgradeTime.Seconds, 0))
|
||||
out.UpgradeTime = &date
|
||||
}
|
||||
if in.VersionId != nil {
|
||||
out.VersionId = in.VersionId.Value
|
||||
}
|
||||
if in.VpcId != nil {
|
||||
out.VpcId = in.VpcId.Value
|
||||
}
|
||||
if in.Zone != nil {
|
||||
out.Zone = in.Zone.Value
|
||||
}
|
||||
return &out
|
||||
}
|
||||
296
pkg/models/openpitrix/repos.go
Normal file
296
pkg/models/openpitrix/repos.go
Normal file
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
*
|
||||
* 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 openpitrix
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/server/params"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CreateRepo(request *CreateRepoRequest) (*CreateRepoResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
createRepoRequest := &pb.CreateRepoRequest{
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
Description: &wrappers.StringValue{Value: request.Description},
|
||||
Type: &wrappers.StringValue{Value: request.Type},
|
||||
Url: &wrappers.StringValue{Value: request.URL},
|
||||
Credential: &wrappers.StringValue{Value: request.Credential},
|
||||
Visibility: &wrappers.StringValue{Value: request.Visibility},
|
||||
CategoryId: &wrappers.StringValue{Value: request.CategoryId},
|
||||
AppDefaultStatus: &wrappers.StringValue{Value: request.AppDefaultStatus},
|
||||
}
|
||||
|
||||
if request.Providers != nil {
|
||||
createRepoRequest.Providers = request.Providers
|
||||
}
|
||||
if request.Workspace != nil {
|
||||
createRepoRequest.Labels = &wrappers.StringValue{Value: fmt.Sprintf("workspace=%s", *request.Workspace)}
|
||||
}
|
||||
|
||||
resp, err := op.Repo().CreateRepo(openpitrix.SystemContext(), createRepoRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &CreateRepoResponse{
|
||||
RepoID: resp.GetRepoId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DeleteRepo(id string) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
_, err = op.Repo().DeleteRepos(openpitrix.SystemContext(), &pb.DeleteReposRequest{
|
||||
RepoId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchRepo(id string, request *ModifyRepoRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
modifyRepoRequest := &pb.ModifyRepoRequest{
|
||||
RepoId: &wrappers.StringValue{Value: id},
|
||||
}
|
||||
|
||||
if request.Name != nil {
|
||||
modifyRepoRequest.Name = &wrappers.StringValue{Value: *request.Name}
|
||||
}
|
||||
if request.Description != nil {
|
||||
modifyRepoRequest.Description = &wrappers.StringValue{Value: *request.Description}
|
||||
}
|
||||
if request.Type != nil {
|
||||
modifyRepoRequest.Type = &wrappers.StringValue{Value: *request.Type}
|
||||
}
|
||||
if request.URL != nil {
|
||||
modifyRepoRequest.Url = &wrappers.StringValue{Value: *request.URL}
|
||||
}
|
||||
if request.Credential != nil {
|
||||
modifyRepoRequest.Credential = &wrappers.StringValue{Value: *request.Credential}
|
||||
}
|
||||
if request.Visibility != nil {
|
||||
modifyRepoRequest.Visibility = &wrappers.StringValue{Value: *request.Visibility}
|
||||
}
|
||||
|
||||
if request.CategoryID != nil {
|
||||
modifyRepoRequest.CategoryId = &wrappers.StringValue{Value: *request.CategoryID}
|
||||
}
|
||||
if request.AppDefaultStatus != nil {
|
||||
modifyRepoRequest.AppDefaultStatus = &wrappers.StringValue{Value: *request.AppDefaultStatus}
|
||||
}
|
||||
if request.Providers != nil {
|
||||
modifyRepoRequest.Providers = request.Providers
|
||||
}
|
||||
if request.Workspace != nil {
|
||||
modifyRepoRequest.Labels = &wrappers.StringValue{Value: fmt.Sprintf("workspace=%s", *request.Workspace)}
|
||||
}
|
||||
|
||||
_, err = op.Repo().ModifyRepo(openpitrix.SystemContext(), modifyRepoRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeRepo(id string) (*Repo, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
resp, err := op.Repo().DescribeRepos(openpitrix.SystemContext(), &pb.DescribeReposRequest{
|
||||
RepoId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var repo *Repo
|
||||
|
||||
if len(resp.RepoSet) > 0 {
|
||||
repo = convertRepo(resp.RepoSet[0])
|
||||
return repo, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req := &pb.DescribeReposRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
req.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
req.Status = strings.Split(status, "|")
|
||||
}
|
||||
if typeStr := conditions.Match["type"]; typeStr != "" {
|
||||
req.Type = strings.Split(typeStr, "|")
|
||||
}
|
||||
if visibility := conditions.Match["visibility"]; visibility != "" {
|
||||
req.Visibility = strings.Split(visibility, "|")
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
req.Status = strings.Split(status, "|")
|
||||
}
|
||||
if workspace := conditions.Match["workspace"]; workspace != "" {
|
||||
req.Label = &wrappers.StringValue{Value: fmt.Sprintf("workspace=%s", workspace)}
|
||||
}
|
||||
if orderBy != "" {
|
||||
req.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
req.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
req.Limit = uint32(limit)
|
||||
req.Offset = uint32(offset)
|
||||
resp, err := client.Repo().DescribeRepos(openpitrix.SystemContext(), req)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.RepoSet {
|
||||
items = append(items, convertRepo(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func ValidateRepo(request *ValidateRepoRequest) (*ValidateRepoResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := client.Repo().ValidateRepo(openpitrix.SystemContext(), &pb.ValidateRepoRequest{
|
||||
Type: &wrappers.StringValue{Value: request.Type},
|
||||
Credential: &wrappers.StringValue{Value: request.Credential},
|
||||
Url: &wrappers.StringValue{Value: request.Url},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ValidateRepoResponse{
|
||||
ErrorCode: int64(resp.ErrorCode),
|
||||
Ok: resp.Ok.Value,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DoRepoAction(repoId string, request *RepoActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
switch request.Action {
|
||||
case "index":
|
||||
indexRepoRequest := &pb.IndexRepoRequest{
|
||||
RepoId: &wrappers.StringValue{Value: repoId},
|
||||
}
|
||||
_, err := op.RepoIndexer().IndexRepo(openpitrix.SystemContext(), indexRepoRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
default:
|
||||
err = status.New(codes.InvalidArgument, "action not support").Err()
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
func ListRepoEvents(repoId string, conditions *params.Conditions, limit, offset int) (*models.PageableResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
describeRepoEventsRequest := &pb.DescribeRepoEventsRequest{
|
||||
RepoId: []string{repoId},
|
||||
}
|
||||
if eventId := conditions.Match["repo_event_id"]; eventId != "" {
|
||||
describeRepoEventsRequest.RepoEventId = strings.Split(eventId, "|")
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
describeRepoEventsRequest.Status = strings.Split(status, "|")
|
||||
}
|
||||
describeRepoEventsRequest.Limit = uint32(limit)
|
||||
describeRepoEventsRequest.Offset = uint32(offset)
|
||||
|
||||
resp, err := op.RepoIndexer().DescribeRepoEvents(openpitrix.SystemContext(), describeRepoEventsRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.RepoEventSet {
|
||||
items = append(items, convertRepoEvent(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
833
pkg/models/openpitrix/types.go
Normal file
833
pkg/models/openpitrix/types.go
Normal file
@@ -0,0 +1,833 @@
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
)
|
||||
|
||||
type ModifyAppRequest struct {
|
||||
// content of attachment
|
||||
AttachmentContent []byte `json:"attachment_content,omitempty"`
|
||||
|
||||
// only for screenshot, range: [0, 5]
|
||||
Sequence *int32 `json:"sequence,omitempty"`
|
||||
|
||||
// optional: icon/screenshot
|
||||
Type *string `json:"type,omitempty"`
|
||||
|
||||
// abstraction of app
|
||||
Abstraction *string `json:"abstraction,omitempty"`
|
||||
|
||||
// category id of the app
|
||||
CategoryID *string `json:"category_id,omitempty"`
|
||||
|
||||
// description of the app
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
||||
// home page of the app
|
||||
Home *string `json:"home,omitempty"`
|
||||
|
||||
// key words of the app
|
||||
Keywords *string `json:"keywords,omitempty"`
|
||||
|
||||
// maintainers who maintainer the app
|
||||
Maintainers *string `json:"maintainers,omitempty"`
|
||||
|
||||
// name of the app
|
||||
Name *string `json:"name,omitempty"`
|
||||
|
||||
// instructions of the app
|
||||
Readme *string `json:"readme,omitempty"`
|
||||
|
||||
// sources of app
|
||||
Sources *string `json:"sources,omitempty"`
|
||||
|
||||
// tos of app
|
||||
Tos *string `json:"tos,omitempty"`
|
||||
}
|
||||
|
||||
type ModifyAppVersionRequest struct {
|
||||
// app description
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
||||
// app name
|
||||
Name *string `json:"name,omitempty"`
|
||||
|
||||
// package of app to replace other
|
||||
Package []byte `json:"package,omitempty"`
|
||||
|
||||
// filename map to file_content
|
||||
PackageFiles map[string][]byte `json:"package_files,omitempty"`
|
||||
|
||||
// required, version id of app to modify
|
||||
VersionID *string `json:"version_id,omitempty"`
|
||||
}
|
||||
type AppVersionAudit struct {
|
||||
|
||||
// id of specific version app
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
// name of specific version app
|
||||
AppName string `json:"app_name,omitempty"`
|
||||
|
||||
// audit message
|
||||
Message string `json:"message,omitempty"`
|
||||
|
||||
// user of auditer
|
||||
Operator string `json:"operator,omitempty"`
|
||||
|
||||
// operator of auditer eg.[global_admin|developer|business|technical|isv]
|
||||
OperatorType string `json:"operator_type,omitempty"`
|
||||
|
||||
// review id
|
||||
ReviewId string `json:"review_id,omitempty"`
|
||||
|
||||
// audit status, eg.[draft|submitted|passed|rejected|active|in-review|deleted|suspended]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime *strfmt.DateTime `json:"status_time,omitempty"`
|
||||
|
||||
// id of version to audit
|
||||
VersionId string `json:"version_id,omitempty"`
|
||||
|
||||
// version name
|
||||
VersionName string `json:"version_name,omitempty"`
|
||||
|
||||
// version type
|
||||
VersionType string `json:"version_type,omitempty"`
|
||||
}
|
||||
|
||||
type ValidatePackageRequest struct {
|
||||
|
||||
// required, version package eg.[the wordpress-0.0.1.tgz will be encoded to bytes]
|
||||
VersionPackage strfmt.Base64 `json:"version_package,omitempty"`
|
||||
|
||||
// optional, vmbased/helm
|
||||
VersionType string `json:"version_type,omitempty"`
|
||||
}
|
||||
type App struct {
|
||||
|
||||
// abstraction of app
|
||||
Abstraction string `json:"abstraction,omitempty"`
|
||||
|
||||
// whether there is a released version in the app
|
||||
Active bool `json:"active,omitempty"`
|
||||
|
||||
// app id
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
// app version types eg.[vmbased|helm]
|
||||
AppVersionTypes string `json:"app_version_types,omitempty"`
|
||||
|
||||
// category set
|
||||
CategorySet AppCategorySet `json:"category_set"`
|
||||
|
||||
// chart name of app
|
||||
ChartName string `json:"chart_name,omitempty"`
|
||||
|
||||
// company join time
|
||||
CompanyJoinTime *strfmt.DateTime `json:"company_join_time,omitempty"`
|
||||
|
||||
// company name
|
||||
CompanyName string `json:"company_name,omitempty"`
|
||||
|
||||
// company profile
|
||||
CompanyProfile string `json:"company_profile,omitempty"`
|
||||
|
||||
// company website
|
||||
CompanyWebsite string `json:"company_website,omitempty"`
|
||||
|
||||
// the time when app create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// app description
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// app home page
|
||||
Home string `json:"home,omitempty"`
|
||||
|
||||
// app icon
|
||||
Icon string `json:"icon,omitempty"`
|
||||
|
||||
// the isv user who create the app
|
||||
Isv string `json:"isv,omitempty"`
|
||||
|
||||
// app key words
|
||||
Keywords string `json:"keywords,omitempty"`
|
||||
|
||||
// latest version of app
|
||||
LatestAppVersion *AppVersion `json:"latest_app_version,omitempty"`
|
||||
|
||||
// app maintainers
|
||||
Maintainers string `json:"maintainers,omitempty"`
|
||||
|
||||
// app name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// owner of app
|
||||
Owner string `json:"owner,omitempty"`
|
||||
|
||||
// app instructions
|
||||
Readme string `json:"readme,omitempty"`
|
||||
|
||||
// repository(store app package) id
|
||||
RepoId string `json:"repo_id,omitempty"`
|
||||
|
||||
// app screenshots
|
||||
Screenshots string `json:"screenshots,omitempty"`
|
||||
|
||||
// sources of app
|
||||
Sources string `json:"sources,omitempty"`
|
||||
|
||||
// status eg.[modify|submit|review|cancel|release|delete|pass|reject|suspend|recover]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime *strfmt.DateTime `json:"status_time,omitempty"`
|
||||
|
||||
// tos of app
|
||||
Tos string `json:"tos,omitempty"`
|
||||
|
||||
// the time when app update
|
||||
UpdateTime *strfmt.DateTime `json:"update_time,omitempty"`
|
||||
|
||||
ClusterTotal *int `json:"cluster_total,omitempty"`
|
||||
}
|
||||
type AppVersionReviewPhase struct {
|
||||
|
||||
// review message
|
||||
Message string `json:"message,omitempty"`
|
||||
|
||||
// user of reviewer
|
||||
Operator string `json:"operator,omitempty"`
|
||||
|
||||
// operator type of reviewer eg.[global_admin|developer|business|technical|isv]
|
||||
OperatorType string `json:"operator_type,omitempty"`
|
||||
|
||||
// app version review time
|
||||
ReviewTime *strfmt.DateTime `json:"review_time,omitempty"`
|
||||
|
||||
// review status of app version eg.[isv-in-review|isv-passed|isv-rejected|isv-draft|business-in-review|business-passed|business-rejected|develop-draft|develop-in-review|develop-passed|develop-rejected|develop-draft]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime *strfmt.DateTime `json:"status_time,omitempty"`
|
||||
}
|
||||
|
||||
type AppVersionReviewPhaseOAIGen map[string]AppVersionReviewPhase
|
||||
|
||||
type GetAppVersionPackageResponse struct {
|
||||
|
||||
// app id of package
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
// package of specific app version
|
||||
Package strfmt.Base64 `json:"package,omitempty"`
|
||||
|
||||
// version id of package
|
||||
VersionId string `json:"version_id,omitempty"`
|
||||
}
|
||||
|
||||
type GetAppVersionPackageFilesResponse struct {
|
||||
|
||||
// filename map to content
|
||||
Files map[string]strfmt.Base64 `json:"files,omitempty"`
|
||||
|
||||
// version id
|
||||
VersionId string `json:"version_id,omitempty"`
|
||||
}
|
||||
type AppVersionReview struct {
|
||||
|
||||
// app id
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
// app name
|
||||
AppName string `json:"app_name,omitempty"`
|
||||
|
||||
// phase
|
||||
Phase AppVersionReviewPhaseOAIGen `json:"phase,omitempty"`
|
||||
|
||||
// review id
|
||||
ReviewId string `json:"review_id,omitempty"`
|
||||
|
||||
// user who review the app version
|
||||
Reviewer string `json:"reviewer,omitempty"`
|
||||
|
||||
// review status eg.[isv-in-review|isv-passed|isv-rejected|isv-draft|business-in-review|business-passed|business-rejected|develop-draft|develop-in-review|develop-passed|develop-rejected|develop-draft]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime strfmt.DateTime `json:"status_time,omitempty"`
|
||||
|
||||
// id of app version
|
||||
VersionID string `json:"version_id,omitempty"`
|
||||
|
||||
// version name of specific app version
|
||||
VersionName string `json:"version_name,omitempty"`
|
||||
|
||||
// version type
|
||||
VersionType string `json:"version_type,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAppRequest struct {
|
||||
|
||||
// app icon
|
||||
Icon strfmt.Base64 `json:"icon,omitempty"`
|
||||
|
||||
// isv
|
||||
Isv string `json:"isv,omitempty"`
|
||||
|
||||
// required, app name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// required, version name of the app
|
||||
VersionName string `json:"version_name,omitempty"`
|
||||
|
||||
// required, version with specific app package
|
||||
VersionPackage strfmt.Base64 `json:"version_package,omitempty"`
|
||||
|
||||
// optional, vmbased/helm
|
||||
VersionType string `json:"version_type,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAppResponse struct {
|
||||
|
||||
// app id
|
||||
AppID string `json:"app_id,omitempty"`
|
||||
|
||||
// version id of the app
|
||||
VersionID string `json:"version_id,omitempty"`
|
||||
}
|
||||
|
||||
type AppVersion struct {
|
||||
|
||||
// active or not
|
||||
Active bool `json:"active,omitempty"`
|
||||
|
||||
// app id
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
// the time when app version create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// description of app of specific version
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// home of app of specific version
|
||||
Home string `json:"home,omitempty"`
|
||||
|
||||
// icon of app of specific version
|
||||
Icon string `json:"icon,omitempty"`
|
||||
|
||||
// keywords of app of specific version
|
||||
Keywords string `json:"keywords,omitempty"`
|
||||
|
||||
// maintainers of app of specific version
|
||||
Maintainers string `json:"maintainers,omitempty"`
|
||||
|
||||
// message path of app of specific version
|
||||
Message string `json:"message,omitempty"`
|
||||
|
||||
// version name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// owner
|
||||
Owner string `json:"owner,omitempty"`
|
||||
|
||||
// package name of app of specific version
|
||||
PackageName string `json:"package_name,omitempty"`
|
||||
|
||||
// readme of app of specific version
|
||||
Readme string `json:"readme,omitempty"`
|
||||
|
||||
// review id of app of specific version
|
||||
ReviewId string `json:"review_id,omitempty"`
|
||||
|
||||
// screenshots of app of specific version
|
||||
Screenshots string `json:"screenshots,omitempty"`
|
||||
|
||||
// sequence of app of specific version
|
||||
Sequence int64 `json:"sequence,omitempty"`
|
||||
|
||||
// sources of app of specific version
|
||||
Sources string `json:"sources,omitempty"`
|
||||
|
||||
// status of app of specific version eg.[draft|submitted|passed|rejected|active|in-review|deleted|suspended]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime *strfmt.DateTime `json:"status_time,omitempty"`
|
||||
|
||||
// type of app of specific version
|
||||
Type string `json:"type,omitempty"`
|
||||
|
||||
// the time when app version update
|
||||
UpdateTime *strfmt.DateTime `json:"update_time,omitempty"`
|
||||
|
||||
// version id of app
|
||||
VersionId string `json:"version_id,omitempty"`
|
||||
|
||||
ClusterTotal *int `json:"cluster_total,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAppVersionResponse struct {
|
||||
|
||||
// version id
|
||||
VersionId string `json:"version_id,omitempty"`
|
||||
}
|
||||
|
||||
type ValidatePackageResponse struct {
|
||||
|
||||
// app description
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// error eg.[json error]
|
||||
Error string `json:"error,omitempty"`
|
||||
|
||||
// filename map to detail
|
||||
ErrorDetails map[string]string `json:"error_details,omitempty"`
|
||||
|
||||
// app name eg.[wordpress|mysql|...]
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// app url
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// app version name.eg.[0.1.0]
|
||||
VersionName string `json:"version_name,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAppVersionRequest struct {
|
||||
|
||||
// required, id of app to create new version
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
// description of app of specific version
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// required, version name eg.[0.1.0|0.1.3|...]
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// package of app of specific version
|
||||
Package strfmt.Base64 `json:"package,omitempty"`
|
||||
|
||||
// optional: vmbased/helm
|
||||
Type string `json:"type,omitempty"`
|
||||
}
|
||||
|
||||
type GetAppVersionFilesRequest struct {
|
||||
Files []string `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
type ActionRequest struct {
|
||||
Action string `json:"action"`
|
||||
Message string `json:"message,omitempty"`
|
||||
Username string `json:"-"`
|
||||
}
|
||||
|
||||
type Attachment struct {
|
||||
|
||||
// filename map to content
|
||||
AttachmentContent map[string]strfmt.Base64 `json:"attachment_content,omitempty"`
|
||||
|
||||
// attachment id
|
||||
AttachmentID string `json:"attachment_id,omitempty"`
|
||||
|
||||
// the time attachment create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
}
|
||||
|
||||
type CreateCategoryRequest struct {
|
||||
|
||||
// category description
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// category icon
|
||||
Icon strfmt.Base64 `json:"icon,omitempty"`
|
||||
|
||||
// the i18n of this category, json format, sample: {"zh_cn": "数据库", "en": "database"}
|
||||
Locale string `json:"locale,omitempty"`
|
||||
|
||||
// required, category name
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
type ModifyCategoryRequest struct {
|
||||
// category description
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
||||
// category icon
|
||||
Icon []byte `json:"icon,omitempty"`
|
||||
|
||||
// the i18n of this category, json format, sample: {"zh_cn": "数据库", "en": "database"}
|
||||
Locale *string `json:"locale,omitempty"`
|
||||
|
||||
// category name
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type AppCategorySet []*ResourceCategory
|
||||
|
||||
type ResourceCategory struct {
|
||||
|
||||
// category id
|
||||
CategoryId string `json:"category_id,omitempty"`
|
||||
|
||||
// create time
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// locale
|
||||
Locale string `json:"locale,omitempty"`
|
||||
|
||||
// name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// status
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// status time
|
||||
StatusTime *strfmt.DateTime `json:"status_time,omitempty"`
|
||||
}
|
||||
|
||||
type Category struct {
|
||||
|
||||
// category id
|
||||
CategoryID string `json:"category_id,omitempty"`
|
||||
|
||||
// the time when category create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// category description
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// category icon
|
||||
Icon string `json:"icon,omitempty"`
|
||||
|
||||
// the i18n of this category, json format, sample: {"zh_cn": "数据库", "en": "database"}
|
||||
Locale string `json:"locale,omitempty"`
|
||||
|
||||
// category name,app belong to a category,eg.[AI|Firewall|cache|...]
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// owner
|
||||
Owner string `json:"owner,omitempty"`
|
||||
|
||||
AppTotal *int `json:"app_total,omitempty"`
|
||||
|
||||
// the time when category update
|
||||
UpdateTime *strfmt.DateTime `json:"update_time,omitempty"`
|
||||
}
|
||||
|
||||
type CreateCategoryResponse struct {
|
||||
|
||||
// id of category created
|
||||
CategoryId string `json:"category_id,omitempty"`
|
||||
}
|
||||
|
||||
type RepoEvent struct {
|
||||
// repository event create time
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// owner
|
||||
Owner string `json:"owner,omitempty"`
|
||||
|
||||
// repository event id
|
||||
RepoEventId string `json:"repo_event_id,omitempty"`
|
||||
|
||||
// repository id
|
||||
RepoId string `json:"repo_id,omitempty"`
|
||||
|
||||
// result
|
||||
Result string `json:"result,omitempty"`
|
||||
|
||||
// repository event status eg.[failed|successful|working|pending]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime *strfmt.DateTime `json:"status_time,omitempty"`
|
||||
}
|
||||
|
||||
type CreateRepoRequest struct {
|
||||
// required app default status.eg:[draft|active]
|
||||
AppDefaultStatus string `json:"app_default_status,omitempty"`
|
||||
|
||||
// category id
|
||||
CategoryId string `json:"category_id,omitempty"`
|
||||
|
||||
// required, credential of visiting the repository
|
||||
Credential string `json:"credential,omitempty"`
|
||||
|
||||
// repository description
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// workspace
|
||||
Workspace *string `json:"workspace,omitempty"`
|
||||
|
||||
// required, repository name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// required, runtime provider eg.[qingcloud|aliyun|aws|kubernetes]
|
||||
Providers []string `json:"providers"`
|
||||
|
||||
// repository type
|
||||
Type string `json:"type,omitempty"`
|
||||
|
||||
// required, url of visiting the repository
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// required, visibility eg:[public|private]
|
||||
Visibility string `json:"visibility,omitempty"`
|
||||
}
|
||||
|
||||
type RepoCategorySet []*ResourceCategory
|
||||
|
||||
type ModifyRepoRequest struct {
|
||||
// app default status eg:[draft|active]
|
||||
AppDefaultStatus *string `json:"app_default_status,omitempty"`
|
||||
|
||||
// category id
|
||||
CategoryID *string `json:"category_id,omitempty"`
|
||||
|
||||
// credential of visiting the repository
|
||||
Credential *string `json:"credential,omitempty"`
|
||||
|
||||
// repository description
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
||||
Workspace *string `json:"workspace,omitempty"`
|
||||
|
||||
// repository name
|
||||
Name *string `json:"name,omitempty"`
|
||||
|
||||
// runtime provider eg.[qingcloud|aliyun|aws|kubernetes]
|
||||
Providers []string `json:"providers"`
|
||||
|
||||
// repository type
|
||||
Type *string `json:"type,omitempty"`
|
||||
|
||||
// url of visiting the repository
|
||||
URL *string `json:"url,omitempty"`
|
||||
|
||||
// visibility eg:[public|private]
|
||||
Visibility *string `json:"visibility,omitempty"`
|
||||
}
|
||||
|
||||
type RepoActionRequest struct {
|
||||
Action string `json:"action"`
|
||||
}
|
||||
|
||||
type ValidateRepoRequest struct {
|
||||
Type string `json:"type"`
|
||||
Credential string `json:"credential"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type RepoSelector struct {
|
||||
// the time when repository selector create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// selector key
|
||||
SelectorKey string `json:"selector_key,omitempty"`
|
||||
|
||||
// selector value
|
||||
SelectorValue string `json:"selector_value,omitempty"`
|
||||
}
|
||||
type RepoLabel struct {
|
||||
// the time when repository label create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// label key
|
||||
LabelKey string `json:"label_key,omitempty"`
|
||||
|
||||
// label value
|
||||
LabelValue string `json:"label_value,omitempty"`
|
||||
}
|
||||
|
||||
type RepoLabels []*RepoLabel
|
||||
type RepoSelectors []*RepoSelector
|
||||
|
||||
type Repo struct {
|
||||
// app default status eg[active|draft]
|
||||
AppDefaultStatus string `json:"app_default_status,omitempty"`
|
||||
|
||||
// category set
|
||||
CategorySet RepoCategorySet `json:"category_set"`
|
||||
|
||||
// controller, value 0 for self resource, value 1 for openpitrix resource
|
||||
Controller int32 `json:"controller,omitempty"`
|
||||
|
||||
// the time when repository create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// credential of visiting the repository
|
||||
Credential string `json:"credential,omitempty"`
|
||||
|
||||
// repository description
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// labels
|
||||
Labels RepoLabels `json:"labels"`
|
||||
|
||||
// repository name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// owner
|
||||
Owner string `json:"owner,omitempty"`
|
||||
|
||||
// runtime provider eg.[qingcloud|aliyun|aws|kubernetes]
|
||||
Providers []string `json:"providers"`
|
||||
|
||||
// repository id
|
||||
RepoId string `json:"repo_id,omitempty"`
|
||||
|
||||
// selectors
|
||||
Selectors RepoSelectors `json:"selectors"`
|
||||
|
||||
// status eg.[active|deleted]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime strfmt.DateTime `json:"status_time,omitempty"`
|
||||
|
||||
// type of repository eg.[http|https|s3]
|
||||
Type string `json:"type,omitempty"`
|
||||
|
||||
// url of visiting the repository
|
||||
URL string `json:"url,omitempty"`
|
||||
|
||||
// visibility.eg:[public|private]
|
||||
Visibility string `json:"visibility,omitempty"`
|
||||
}
|
||||
|
||||
type CreateRepoResponse struct {
|
||||
|
||||
// id of repository created
|
||||
RepoID string `json:"repo_id,omitempty"`
|
||||
}
|
||||
|
||||
type ValidateRepoResponse struct {
|
||||
|
||||
// if validate error,return error code
|
||||
ErrorCode int64 `json:"errorCode,omitempty"`
|
||||
|
||||
// validate repository ok or not
|
||||
Ok bool `json:"ok,omitempty"`
|
||||
}
|
||||
|
||||
type CreateClusterRequest struct {
|
||||
|
||||
// advanced param
|
||||
AdvancedParam []string `json:"advanced_param"`
|
||||
|
||||
// required, id of app to run in cluster
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
// required, conf a json string, include cpu, memory info of cluster
|
||||
Conf string `json:"conf,omitempty"`
|
||||
|
||||
// required, id of runtime
|
||||
RuntimeId string `json:"runtime_id,omitempty"`
|
||||
|
||||
// required, id of app version
|
||||
VersionId string `json:"version_id,omitempty"`
|
||||
|
||||
Username string `json:"-"`
|
||||
}
|
||||
|
||||
type Cluster struct {
|
||||
|
||||
// additional info
|
||||
AdditionalInfo string `json:"additional_info,omitempty"`
|
||||
|
||||
// id of app run in cluster
|
||||
AppId string `json:"app_id,omitempty"`
|
||||
|
||||
//// cluster common set
|
||||
//ClusterCommonSet OpenpitrixClusterClusterCommonSet `json:"cluster_common_set"`
|
||||
|
||||
// cluster id
|
||||
ClusterId string `json:"cluster_id,omitempty"`
|
||||
|
||||
// cluster type, frontgate or normal cluster
|
||||
ClusterType int64 `json:"cluster_type,omitempty"`
|
||||
|
||||
// the time when cluster create
|
||||
CreateTime *strfmt.DateTime `json:"create_time,omitempty"`
|
||||
|
||||
// cluster used to debug or not
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
|
||||
// cluster description
|
||||
Description string `json:"description,omitempty"`
|
||||
|
||||
// endpoint of cluster
|
||||
Endpoints string `json:"endpoints,omitempty"`
|
||||
|
||||
// cluster env
|
||||
Env string `json:"env,omitempty"`
|
||||
|
||||
// frontgate id, a proxy for vpc to communicate
|
||||
FrontgateId string `json:"frontgate_id,omitempty"`
|
||||
|
||||
// global uuid
|
||||
GlobalUUID string `json:"global_uuid,omitempty"`
|
||||
|
||||
// metadata root access
|
||||
MetadataRootAccess bool `json:"metadata_root_access,omitempty"`
|
||||
|
||||
// cluster name
|
||||
Name string `json:"name,omitempty"`
|
||||
|
||||
// owner
|
||||
Owner string `json:"owner,omitempty"`
|
||||
|
||||
// cluster runtime id
|
||||
RuntimeId string `json:"runtime_id,omitempty"`
|
||||
|
||||
// cluster status eg.[active|used|enabled|disabled|deleted|stopped|ceased]
|
||||
Status string `json:"status,omitempty"`
|
||||
|
||||
// record status changed time
|
||||
StatusTime *strfmt.DateTime `json:"status_time,omitempty"`
|
||||
|
||||
// subnet id, cluster run in a subnet
|
||||
SubnetId string `json:"subnet_id,omitempty"`
|
||||
|
||||
// cluster transition status eg.[creating|deleting|upgrading|updating|rollbacking|stopping|starting|recovering|ceasing|resizing|scaling]
|
||||
TransitionStatus string `json:"transition_status,omitempty"`
|
||||
|
||||
// upgrade status, unused
|
||||
UpgradeStatus string `json:"upgrade_status,omitempty"`
|
||||
|
||||
// cluster upgraded time
|
||||
UpgradeTime *strfmt.DateTime `json:"upgrade_time,omitempty"`
|
||||
|
||||
// id of version of app run in cluster
|
||||
VersionId string `json:"version_id,omitempty"`
|
||||
|
||||
// vpc id, a vpc contain one more subnet
|
||||
VpcId string `json:"vpc_id,omitempty"`
|
||||
|
||||
// zone of cluster eg.[pek3a|pek3b]
|
||||
Zone string `json:"zone,omitempty"`
|
||||
}
|
||||
|
||||
type Runtime struct {
|
||||
// runtime id
|
||||
RuntimeId string `protobuf:"bytes,1,opt,name=runtime_id,json=runtimeId,proto3" json:"runtime_id,omitempty"`
|
||||
// runtime name,create by owner.
|
||||
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
|
||||
// runtime description
|
||||
Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"`
|
||||
}
|
||||
|
||||
type ModifyClusterAttributesRequest struct {
|
||||
|
||||
// required, id of cluster to modify
|
||||
ClusterID string `json:"cluster_id,omitempty"`
|
||||
|
||||
// cluster description
|
||||
Description *string `json:"description,omitempty"`
|
||||
|
||||
// cluster name
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
@@ -121,12 +121,12 @@ func GetResource(namespace, resource, name string) (interface{}, error) {
|
||||
if searcher, ok := resources[resource]; ok {
|
||||
resource, err := searcher.get(namespace, name)
|
||||
if err != nil {
|
||||
klog.Errorln("get resource", namespace, resource, name, err)
|
||||
klog.Errorf("resource %s.%s.%s not found: %s", namespace, resource, name, err)
|
||||
return nil, err
|
||||
}
|
||||
return resource, nil
|
||||
}
|
||||
return nil, fmt.Errorf("resource %s not found", resource)
|
||||
return nil, fmt.Errorf("resource %s.%s.%s not found", namespace, resource, name)
|
||||
}
|
||||
|
||||
func ListResources(namespace, resource string, conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
@@ -136,19 +136,21 @@ func ListResources(namespace, resource string, conditions *params.Conditions, or
|
||||
|
||||
// none namespace resource
|
||||
if namespace != "" && sliceutil.HasString(clusterResources, resource) {
|
||||
klog.Errorln("resources not found", resource)
|
||||
return nil, fmt.Errorf("not found")
|
||||
err = fmt.Errorf("namespaced resource %s not found", resource)
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if searcher, ok := resources[resource]; ok {
|
||||
result, err = searcher.search(namespace, conditions, orderBy, reverse)
|
||||
} else {
|
||||
klog.Errorln("resources not found", resource)
|
||||
return nil, fmt.Errorf("not found")
|
||||
err = fmt.Errorf("namespaced resource %s not found", resource)
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln("resources search", err)
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user