[WIP] API refactor (#1737)
* refactor openpitrix API Signed-off-by: hongming <talonwan@yunify.com> * add openpitrix mock client Signed-off-by: hongming <talonwan@yunify.com> * refactor tenant API Signed-off-by: hongming <talonwan@yunify.com> * refactor IAM API Signed-off-by: hongming <talonwan@yunify.com> * refactor IAM API Signed-off-by: hongming <talonwan@yunify.com>
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
/*
|
||||
|
||||
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 application
|
||||
*
|
||||
* Copyright 2020 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"
|
||||
@@ -26,46 +26,39 @@ import (
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/api/extensions/v1beta1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/constants"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"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"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
List(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error)
|
||||
Get(namespace, clusterID string) (*Application, error)
|
||||
Create(namespace string, request types.CreateClusterRequest) error
|
||||
Patch(request types.ModifyClusterAttributesRequest) error
|
||||
Delete(id string) error
|
||||
type ApplicationInterface interface {
|
||||
ListApplications(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error)
|
||||
DescribeApplication(namespace, clusterId string) (*Application, error)
|
||||
CreateApplication(namespace string, request CreateClusterRequest) error
|
||||
ModifyApplication(request ModifyClusterAttributesRequest) error
|
||||
DeleteApplication(id string) error
|
||||
}
|
||||
|
||||
type applicationOperator struct {
|
||||
informers informers.SharedInformerFactory
|
||||
opClient pb.ClusterManagerClient
|
||||
opClient openpitrix.Client
|
||||
}
|
||||
|
||||
func NewApplicaitonOperator(informers informers.SharedInformerFactory, client pb.ClusterManagerClient) Interface {
|
||||
return &applicationOperator{
|
||||
informers: informers,
|
||||
opClient: client,
|
||||
}
|
||||
func newApplicationOperator(informers informers.SharedInformerFactory, opClient openpitrix.Client) ApplicationInterface {
|
||||
return &applicationOperator{informers: informers, opClient: opClient}
|
||||
}
|
||||
|
||||
type Application struct {
|
||||
Name string `json:"name" description:"application name"`
|
||||
Cluster *types.Cluster `json:"cluster,omitempty" description:"application cluster info"`
|
||||
Version *types.AppVersion `json:"version,omitempty" description:"application template version info"`
|
||||
App *types.App `json:"app,omitempty" description:"application template info"`
|
||||
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"`
|
||||
@@ -77,35 +70,30 @@ type workLoads struct {
|
||||
Daemonsets []appsv1.DaemonSet `json:"daemonsets,omitempty" description:"daemonset list"`
|
||||
}
|
||||
|
||||
func (c *applicationOperator) List(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
func (c *applicationOperator) ListApplications(conditions *params.Conditions, limit, offset int, orderBy string, reverse bool) (*models.PageableResponse, error) {
|
||||
describeClustersRequest := &pb.DescribeClustersRequest{
|
||||
Limit: uint32(limit),
|
||||
Offset: uint32(offset)}
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
if keyword := conditions.Match[Keyword]; keyword != "" {
|
||||
describeClustersRequest.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if runtimeId := conditions.Match["runtime_id"]; runtimeId != "" {
|
||||
if runtimeId := conditions.Match[RuntimeId]; runtimeId != "" {
|
||||
describeClustersRequest.RuntimeId = []string{runtimeId}
|
||||
}
|
||||
if appId := conditions.Match["app_id"]; appId != "" {
|
||||
if appId := conditions.Match[AppId]; appId != "" {
|
||||
describeClustersRequest.AppId = []string{appId}
|
||||
}
|
||||
if versionId := conditions.Match["version_id"]; versionId != "" {
|
||||
if versionId := conditions.Match[VersionId]; versionId != "" {
|
||||
describeClustersRequest.VersionId = []string{versionId}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
if status := conditions.Match[Status]; status != "" {
|
||||
describeClustersRequest.Status = strings.Split(status, "|")
|
||||
}
|
||||
if orderBy != "" {
|
||||
describeClustersRequest.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeClustersRequest.Reverse = &wrappers.BoolValue{Value: !reverse}
|
||||
resp, err := client.Cluster().DescribeClusters(openpitrix.SystemContext(), describeClustersRequest)
|
||||
describeClustersRequest.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
resp, err := c.opClient.DescribeClusters(openpitrix.SystemContext(), describeClustersRequest)
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
@@ -125,34 +113,29 @@ func (c *applicationOperator) List(conditions *params.Conditions, limit, offset
|
||||
}
|
||||
|
||||
func (c *applicationOperator) 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 = cluster.Name.Value
|
||||
app.Cluster = utils.ConvertCluster(cluster)
|
||||
versionInfo, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{VersionId: []string{cluster.GetVersionId().GetValue()}})
|
||||
app.Cluster = convertCluster(cluster)
|
||||
versionInfo, err := c.opClient.DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{VersionId: []string{cluster.GetVersionId().GetValue()}})
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return nil, err
|
||||
}
|
||||
if len(versionInfo.AppVersionSet) > 0 {
|
||||
app.Version = utils.ConvertAppVersion(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})
|
||||
appInfo, err := c.opClient.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 = utils.ConvertApp(appInfo.GetAppSet()[0])
|
||||
app.App = convertApp(appInfo.GetAppSet()[0])
|
||||
}
|
||||
return &app, nil
|
||||
}
|
||||
|
||||
func (c *applicationOperator) Get(namespace string, clusterId string) (*Application, error) {
|
||||
func (c *applicationOperator) DescribeApplication(namespace string, clusterId string) (*Application, error) {
|
||||
|
||||
clusters, err := c.opClient.DescribeClusters(openpitrix.SystemContext(), &pb.DescribeClustersRequest{ClusterId: []string{clusterId}, Limit: 1})
|
||||
|
||||
@@ -280,7 +263,7 @@ func (c *applicationOperator) getLabels(namespace string, workloads *workLoads)
|
||||
return &workloadLabels
|
||||
}
|
||||
|
||||
func (c *applicationOperator) isExist(svcs []v1.Service, svc v1.Service) bool {
|
||||
func (c *applicationOperator) isExist(svcs []v1.Service, svc *v1.Service) bool {
|
||||
for _, item := range svcs {
|
||||
if item.Name == svc.Name && item.Namespace == svc.Namespace {
|
||||
return true
|
||||
@@ -293,17 +276,16 @@ func (c *applicationOperator) getSvcs(namespace string, workLoadLabels *[]map[st
|
||||
if len(*workLoadLabels) == 0 {
|
||||
return nil
|
||||
}
|
||||
k8sClient := cs.ClientSets().K8s().Kubernetes()
|
||||
var services []v1.Service
|
||||
for _, label := range *workLoadLabels {
|
||||
labelSelector := labels.Set(label).AsSelector().String()
|
||||
svcs, err := k8sClient.CoreV1().Services(namespace).List(metav1.ListOptions{LabelSelector: labelSelector})
|
||||
labelSelector := labels.Set(label).AsSelector()
|
||||
svcs, err := c.informers.Core().V1().Services().Lister().Services(namespace).List(labelSelector)
|
||||
if err != nil {
|
||||
klog.Errorf("get app's svc failed, reason: %v", err)
|
||||
}
|
||||
for _, item := range svcs.Items {
|
||||
for _, item := range svcs {
|
||||
if !c.isExist(services, item) {
|
||||
services = append(services, item)
|
||||
services = append(services, *item)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -352,7 +334,7 @@ func (c *applicationOperator) getIng(namespace string, services []v1.Service) []
|
||||
return ings
|
||||
}
|
||||
|
||||
func (c *applicationOperator) Create(namespace string, request types.CreateClusterRequest) error {
|
||||
func (c *applicationOperator) CreateApplication(namespace string, request CreateClusterRequest) error {
|
||||
ns, err := c.informers.Core().V1().Namespaces().Lister().Get(namespace)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -365,14 +347,7 @@ func (c *applicationOperator) Create(namespace string, request types.CreateClust
|
||||
return fmt.Errorf("runtime not init: namespace %s", namespace)
|
||||
}
|
||||
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = client.Cluster().CreateCluster(openpitrix.ContextWithUsername(request.Username), &pb.CreateClusterRequest{
|
||||
_, err = c.opClient.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},
|
||||
@@ -387,13 +362,7 @@ func (c *applicationOperator) Create(namespace string, request types.CreateClust
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *applicationOperator) Patch(request types.ModifyClusterAttributesRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
func (c *applicationOperator) ModifyApplication(request ModifyClusterAttributesRequest) error {
|
||||
|
||||
modifyClusterAttributesRequest := &pb.ModifyClusterAttributesRequest{ClusterId: &wrappers.StringValue{Value: request.ClusterID}}
|
||||
if request.Name != nil {
|
||||
@@ -403,16 +372,17 @@ func (c *applicationOperator) Patch(request types.ModifyClusterAttributesRequest
|
||||
modifyClusterAttributesRequest.Description = &wrappers.StringValue{Value: *request.Description}
|
||||
}
|
||||
|
||||
_, err = op.Cluster().ModifyClusterAttributes(openpitrix.SystemContext(), modifyClusterAttributesRequest)
|
||||
_, err := c.opClient.ModifyClusterAttributes(openpitrix.SystemContext(), modifyClusterAttributesRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Errorln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *applicationOperator) Delete(clusterId string) error {
|
||||
func (c *applicationOperator) DeleteApplication(clusterId string) error {
|
||||
_, err := c.opClient.DeleteClusters(openpitrix.SystemContext(), &pb.DeleteClustersRequest{ClusterId: []string{clusterId}, Force: &wrappers.BoolValue{Value: true}})
|
||||
|
||||
if err != nil {
|
||||
114
pkg/models/openpitrix/applications_test.go
Normal file
114
pkg/models/openpitrix/applications_test.go
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2020 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/mock/gomock"
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
"k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func namespacesToRuntimeObjects(namespaces ...*v1.Namespace) []runtime.Object {
|
||||
var objs []runtime.Object
|
||||
for _, deploy := range namespaces {
|
||||
objs = append(objs, deploy)
|
||||
}
|
||||
|
||||
return objs
|
||||
}
|
||||
|
||||
func TestApplicationOperator_CreateApplication(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
existNamespaces []*v1.Namespace
|
||||
targetNamespace string
|
||||
createClusterRequest CreateClusterRequest
|
||||
expected error
|
||||
}{
|
||||
{
|
||||
description: "create application test",
|
||||
existNamespaces: []*v1.Namespace{{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "test", Annotations: map[string]string{openpitrix.RuntimeAnnotationKey: "runtime-ncafface"}},
|
||||
}},
|
||||
targetNamespace: "test",
|
||||
createClusterRequest: CreateClusterRequest{
|
||||
Conf: "app-agwerl",
|
||||
RuntimeId: "runtime-ncafface",
|
||||
VersionId: "version-acklmalkds",
|
||||
Username: "system",
|
||||
},
|
||||
expected: nil,
|
||||
},
|
||||
{
|
||||
description: "create application test2",
|
||||
existNamespaces: []*v1.Namespace{},
|
||||
targetNamespace: "test2",
|
||||
createClusterRequest: CreateClusterRequest{
|
||||
Conf: "app-agwerl",
|
||||
RuntimeId: "runtime-ncafface",
|
||||
VersionId: "version-acklmalkds",
|
||||
Username: "system",
|
||||
},
|
||||
expected: errors.NewNotFound(schema.GroupResource{Group: "", Resource: "namespace"}, "test2"),
|
||||
},
|
||||
}
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
op := openpitrix.NewMockClient(ctrl)
|
||||
objs := namespacesToRuntimeObjects(test.existNamespaces...)
|
||||
k8s := fake.NewSimpleClientset(objs...)
|
||||
informer := informers.NewSharedInformerFactory(k8s, 0)
|
||||
stopChan := make(chan struct{}, 0)
|
||||
informer.Core().V1().Namespaces().Lister()
|
||||
informer.Start(stopChan)
|
||||
informer.WaitForCacheSync(stopChan)
|
||||
|
||||
applicationOperator := newApplicationOperator(informer, op)
|
||||
|
||||
// setup expect response
|
||||
// op.EXPECT().CreateCluster(gomock.Any(), gomock.Any()).Return(&pb.CreateClusterResponse{}, nil).AnyTimes()
|
||||
op.EXPECT().CreateCluster(openpitrix.ContextWithUsername(test.createClusterRequest.Username), &pb.CreateClusterRequest{
|
||||
AppId: &wrappers.StringValue{Value: test.createClusterRequest.AppId},
|
||||
VersionId: &wrappers.StringValue{Value: test.createClusterRequest.VersionId},
|
||||
RuntimeId: &wrappers.StringValue{Value: test.createClusterRequest.RuntimeId},
|
||||
Conf: &wrappers.StringValue{Value: test.createClusterRequest.Conf},
|
||||
}).Return(&pb.CreateClusterResponse{}, nil).AnyTimes()
|
||||
|
||||
t.Run(test.description, func(t *testing.T) {
|
||||
|
||||
err := applicationOperator.CreateApplication(test.targetNamespace, test.createClusterRequest)
|
||||
|
||||
if err != nil && err.Error() != test.expected.Error() {
|
||||
t.Error(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
* Copyright 2020 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.
|
||||
@@ -16,7 +16,7 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package app
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
@@ -25,41 +25,58 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"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"
|
||||
)
|
||||
|
||||
const (
|
||||
BuiltinRepoId = "repo-helm"
|
||||
StatusActive = "active"
|
||||
)
|
||||
type AppTemplateInterface interface {
|
||||
ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error)
|
||||
DescribeApp(id string) (*App, error)
|
||||
DeleteApp(id string) error
|
||||
CreateApp(request *CreateAppRequest) (*CreateAppResponse, error)
|
||||
ModifyApp(appId string, request *ModifyAppRequest) error
|
||||
DeleteAppVersion(id string) error
|
||||
ModifyAppVersion(id string, request *ModifyAppVersionRequest) error
|
||||
DescribeAppVersion(id string) (*AppVersion, error)
|
||||
CreateAppVersion(request *CreateAppVersionRequest) (*CreateAppVersionResponse, error)
|
||||
ValidatePackage(request *ValidatePackageRequest) (*ValidatePackageResponse, error)
|
||||
GetAppVersionPackage(appId, versionId string) (*GetAppVersionPackageResponse, error)
|
||||
DoAppAction(appId string, request *ActionRequest) error
|
||||
DoAppVersionAction(versionId string, request *ActionRequest) error
|
||||
GetAppVersionFiles(versionId string, request *GetAppVersionFilesRequest) (*GetAppVersionPackageFilesResponse, error)
|
||||
ListAppVersionAudits(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error)
|
||||
ListAppVersionReviews(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error)
|
||||
ListAppVersions(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error)
|
||||
}
|
||||
|
||||
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
|
||||
type appTemplateOperator struct {
|
||||
opClient openpitrix.Client
|
||||
}
|
||||
|
||||
func newAppTemplateOperator(opClient openpitrix.Client) AppTemplateInterface {
|
||||
return &appTemplateOperator{
|
||||
opClient: opClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
|
||||
describeAppsRequest := &pb.DescribeAppsRequest{}
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
if keyword := conditions.Match[Keyword]; keyword != "" {
|
||||
describeAppsRequest.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if appId := conditions.Match["app_id"]; appId != "" {
|
||||
if appId := conditions.Match[AppId]; appId != "" {
|
||||
describeAppsRequest.AppId = strings.Split(appId, "|")
|
||||
}
|
||||
if isv := conditions.Match["isv"]; isv != "" {
|
||||
if isv := conditions.Match[ISV]; isv != "" {
|
||||
describeAppsRequest.Isv = strings.Split(isv, "|")
|
||||
}
|
||||
if categoryId := conditions.Match["category_id"]; categoryId != "" {
|
||||
if categoryId := conditions.Match[CategoryId]; categoryId != "" {
|
||||
describeAppsRequest.CategoryId = strings.Split(categoryId, "|")
|
||||
}
|
||||
if repoId := conditions.Match["repo"]; repoId != "" {
|
||||
if repoId := conditions.Match[RepoId]; repoId != "" {
|
||||
// hard code, app template in built-in repo has no repo_id attribute
|
||||
if repoId == BuiltinRepoId {
|
||||
describeAppsRequest.RepoId = []string{"\u0000"}
|
||||
@@ -67,7 +84,7 @@ func ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit
|
||||
describeAppsRequest.RepoId = strings.Split(repoId, "|")
|
||||
}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
if status := conditions.Match[Status]; status != "" {
|
||||
describeAppsRequest.Status = strings.Split(status, "|")
|
||||
}
|
||||
if orderBy != "" {
|
||||
@@ -76,7 +93,7 @@ func ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit
|
||||
describeAppsRequest.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
describeAppsRequest.Limit = uint32(limit)
|
||||
describeAppsRequest.Offset = uint32(offset)
|
||||
resp, err := client.App().DescribeApps(openpitrix.SystemContext(), describeAppsRequest)
|
||||
resp, err := c.opClient.DescribeApps(openpitrix.SystemContext(), describeAppsRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
@@ -85,19 +102,14 @@ func ListApps(conditions *params.Conditions, orderBy string, reverse bool, limit
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppSet {
|
||||
items = append(items, utils.ConvertApp(item))
|
||||
items = append(items, convertApp(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func DescribeApp(id string) (*types.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{
|
||||
func (c *appTemplateOperator) DescribeApp(id string) (*App, error) {
|
||||
resp, err := c.opClient.DescribeApps(openpitrix.SystemContext(), &pb.DescribeAppsRequest{
|
||||
AppId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
@@ -106,10 +118,10 @@ func DescribeApp(id string) (*types.App, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var app *types.App
|
||||
var app *App
|
||||
|
||||
if len(resp.AppSet) > 0 {
|
||||
app = utils.ConvertApp(resp.AppSet[0])
|
||||
app = convertApp(resp.AppSet[0])
|
||||
return app, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -118,13 +130,8 @@ func DescribeApp(id string) (*types.App, error) {
|
||||
}
|
||||
}
|
||||
|
||||
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{
|
||||
func (c *appTemplateOperator) DeleteApp(id string) error {
|
||||
_, err := c.opClient.DeleteApps(openpitrix.SystemContext(), &pb.DeleteAppsRequest{
|
||||
AppId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -134,12 +141,7 @@ func DeleteApp(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateApp(request *types.CreateAppRequest) (*types.CreateAppResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
func (c *appTemplateOperator) CreateApp(request *CreateAppRequest) (*CreateAppResponse, error) {
|
||||
createAppRequest := &pb.CreateAppRequest{
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
VersionType: &wrappers.StringValue{Value: request.VersionType},
|
||||
@@ -154,25 +156,18 @@ func CreateApp(request *types.CreateAppRequest) (*types.CreateAppResponse, error
|
||||
if request.Isv != "" {
|
||||
createAppRequest.Isv = &wrappers.StringValue{Value: request.Isv}
|
||||
}
|
||||
resp, err := op.App().CreateApp(openpitrix.ContextWithUsername(request.Username), createAppRequest)
|
||||
resp, err := c.opClient.CreateApp(openpitrix.ContextWithUsername(request.Username), createAppRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &types.CreateAppResponse{
|
||||
return &CreateAppResponse{
|
||||
AppID: resp.GetAppId().GetValue(),
|
||||
VersionID: resp.GetVersionId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func PatchApp(appId string, request *types.ModifyAppRequest) error {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) ModifyApp(appId string, request *ModifyAppRequest) error {
|
||||
// upload app attachment
|
||||
if request.AttachmentContent != nil {
|
||||
uploadAttachmentRequest := &pb.UploadAppAttachmentRequest{
|
||||
@@ -186,7 +181,7 @@ func PatchApp(appId string, request *types.ModifyAppRequest) error {
|
||||
uploadAttachmentRequest.Sequence = &wrappers.UInt32Value{Value: uint32(*request.Sequence)}
|
||||
}
|
||||
|
||||
_, err := client.App().UploadAppAttachment(openpitrix.SystemContext(), uploadAttachmentRequest)
|
||||
_, err := c.opClient.UploadAppAttachment(openpitrix.SystemContext(), uploadAttachmentRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -229,7 +224,7 @@ func PatchApp(appId string, request *types.ModifyAppRequest) error {
|
||||
patchAppRequest.Tos = &wrappers.StringValue{Value: *request.Tos}
|
||||
}
|
||||
|
||||
_, err = client.App().ModifyApp(openpitrix.SystemContext(), patchAppRequest)
|
||||
_, err := c.opClient.ModifyApp(openpitrix.SystemContext(), patchAppRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -239,12 +234,7 @@ func PatchApp(appId string, request *types.ModifyAppRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func CreateAppVersion(request *types.CreateAppVersionRequest) (*types.CreateAppVersionResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
func (c *appTemplateOperator) CreateAppVersion(request *CreateAppVersionRequest) (*CreateAppVersionResponse, error) {
|
||||
createAppVersionRequest := &pb.CreateAppVersionRequest{
|
||||
AppId: &wrappers.StringValue{Value: request.AppId},
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
@@ -256,24 +246,17 @@ func CreateAppVersion(request *types.CreateAppVersionRequest) (*types.CreateAppV
|
||||
createAppVersionRequest.Package = &wrappers.BytesValue{Value: request.Package}
|
||||
}
|
||||
|
||||
resp, err := op.App().CreateAppVersion(openpitrix.ContextWithUsername(request.Username), createAppVersionRequest)
|
||||
resp, err := c.opClient.CreateAppVersion(openpitrix.ContextWithUsername(request.Username), createAppVersionRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &types.CreateAppVersionResponse{
|
||||
return &CreateAppVersionResponse{
|
||||
VersionId: resp.GetVersionId().GetValue(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ValidatePackage(request *types.ValidatePackageRequest) (*types.ValidatePackageResponse, error) {
|
||||
client, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) ValidatePackage(request *ValidatePackageRequest) (*ValidatePackageResponse, error) {
|
||||
r := &pb.ValidatePackageRequest{}
|
||||
|
||||
if request.VersionPackage != nil {
|
||||
@@ -283,14 +266,14 @@ func ValidatePackage(request *types.ValidatePackageRequest) (*types.ValidatePack
|
||||
r.VersionType = request.VersionType
|
||||
}
|
||||
|
||||
resp, err := client.App().ValidatePackage(openpitrix.SystemContext(), r)
|
||||
resp, err := c.opClient.ValidatePackage(openpitrix.SystemContext(), r)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result := &types.ValidatePackageResponse{}
|
||||
result := &ValidatePackageResponse{}
|
||||
|
||||
if resp.Error != nil {
|
||||
result.Error = resp.Error.Value
|
||||
@@ -316,13 +299,8 @@ func ValidatePackage(request *types.ValidatePackageRequest) (*types.ValidatePack
|
||||
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{
|
||||
func (c *appTemplateOperator) DeleteAppVersion(id string) error {
|
||||
_, err := c.opClient.DeleteAppVersion(openpitrix.SystemContext(), &pb.DeleteAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: id},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -332,12 +310,7 @@ func DeleteAppVersion(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchAppVersion(id string, request *types.ModifyAppVersionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
func (c *appTemplateOperator) ModifyAppVersion(id string, request *ModifyAppVersionRequest) error {
|
||||
modifyAppVersionRequest := &pb.ModifyAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: id},
|
||||
}
|
||||
@@ -355,7 +328,7 @@ func PatchAppVersion(id string, request *types.ModifyAppVersionRequest) error {
|
||||
modifyAppVersionRequest.PackageFiles = request.PackageFiles
|
||||
}
|
||||
|
||||
_, err = op.App().ModifyAppVersion(openpitrix.SystemContext(), modifyAppVersionRequest)
|
||||
_, err := c.opClient.ModifyAppVersion(openpitrix.SystemContext(), modifyAppVersionRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
@@ -363,13 +336,8 @@ func PatchAppVersion(id string, request *types.ModifyAppVersionRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeAppVersion(id string) (*types.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{
|
||||
func (c *appTemplateOperator) DescribeAppVersion(id string) (*AppVersion, error) {
|
||||
resp, err := c.opClient.DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
VersionId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
@@ -378,10 +346,10 @@ func DescribeAppVersion(id string) (*types.AppVersion, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var app *types.AppVersion
|
||||
var app *AppVersion
|
||||
|
||||
if len(resp.AppVersionSet) > 0 {
|
||||
app = utils.ConvertAppVersion(resp.AppVersionSet[0])
|
||||
app = convertAppVersion(resp.AppVersionSet[0])
|
||||
return app, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -390,13 +358,8 @@ func DescribeAppVersion(id string) (*types.AppVersion, error) {
|
||||
}
|
||||
}
|
||||
|
||||
func GetAppVersionPackage(appId, versionId string) (*types.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{
|
||||
func (c *appTemplateOperator) GetAppVersionPackage(appId, versionId string) (*GetAppVersionPackageResponse, error) {
|
||||
resp, err := c.opClient.GetAppVersionPackage(openpitrix.SystemContext(), &pb.GetAppVersionPackageRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -404,7 +367,7 @@ func GetAppVersionPackage(appId, versionId string) (*types.GetAppVersionPackageR
|
||||
return nil, err
|
||||
}
|
||||
|
||||
app := &types.GetAppVersionPackageResponse{
|
||||
app := &GetAppVersionPackageResponse{
|
||||
AppId: appId,
|
||||
VersionId: versionId,
|
||||
}
|
||||
@@ -416,21 +379,14 @@ func GetAppVersionPackage(appId, versionId string) (*types.GetAppVersionPackageR
|
||||
return app, nil
|
||||
}
|
||||
|
||||
func DoAppAction(appId string, request *types.ActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) DoAppAction(appId string, request *ActionRequest) error {
|
||||
switch request.Action {
|
||||
|
||||
case "recover":
|
||||
case ActionRecover:
|
||||
// TODO openpitrix need to implement app recover interface
|
||||
resp, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
resp, err := c.opClient.DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
AppId: []string{appId},
|
||||
Status: []string{"suspended"},
|
||||
Status: []string{StatusSuspended},
|
||||
Limit: 200,
|
||||
Offset: 0,
|
||||
})
|
||||
@@ -440,7 +396,7 @@ func DoAppAction(appId string, request *types.ActionRequest) error {
|
||||
}
|
||||
for _, version := range resp.AppVersionSet {
|
||||
|
||||
_, err = op.App().RecoverAppVersion(openpitrix.SystemContext(), &pb.RecoverAppVersionRequest{
|
||||
_, err = c.opClient.RecoverAppVersion(openpitrix.SystemContext(), &pb.RecoverAppVersionRequest{
|
||||
VersionId: version.VersionId,
|
||||
})
|
||||
if err != nil {
|
||||
@@ -449,11 +405,11 @@ func DoAppAction(appId string, request *types.ActionRequest) error {
|
||||
}
|
||||
}
|
||||
|
||||
case "suspend":
|
||||
case ActionSuspend:
|
||||
// TODO openpitrix need to implement app suspend interface
|
||||
resp, err := op.App().DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
resp, err := c.opClient.DescribeAppVersions(openpitrix.SystemContext(), &pb.DescribeAppVersionsRequest{
|
||||
AppId: []string{appId},
|
||||
Status: []string{"active"},
|
||||
Status: []string{StatusActive},
|
||||
Limit: 200,
|
||||
Offset: 0,
|
||||
})
|
||||
@@ -462,7 +418,7 @@ func DoAppAction(appId string, request *types.ActionRequest) error {
|
||||
return err
|
||||
}
|
||||
for _, version := range resp.AppVersionSet {
|
||||
_, err = op.App().SuspendAppVersion(openpitrix.SystemContext(), &pb.SuspendAppVersionRequest{
|
||||
_, err = c.opClient.SuspendAppVersion(openpitrix.SystemContext(), &pb.SuspendAppVersionRequest{
|
||||
VersionId: version.VersionId,
|
||||
})
|
||||
|
||||
@@ -473,7 +429,7 @@ func DoAppAction(appId string, request *types.ActionRequest) error {
|
||||
}
|
||||
|
||||
default:
|
||||
err = status.New(codes.InvalidArgument, "action not support").Err()
|
||||
err := status.New(codes.InvalidArgument, "action not support").Err()
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
@@ -481,42 +437,36 @@ func DoAppAction(appId string, request *types.ActionRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DoAppVersionAction(versionId string, request *types.ActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) DoAppVersionAction(versionId string, request *ActionRequest) error {
|
||||
var err error
|
||||
switch request.Action {
|
||||
case "cancel":
|
||||
_, err = op.App().CancelAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.CancelAppVersionRequest{
|
||||
case ActionCancel:
|
||||
_, err = c.opClient.CancelAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.CancelAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "pass":
|
||||
_, err = op.App().AdminPassAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.PassAppVersionRequest{
|
||||
case ActionPass:
|
||||
_, err = c.opClient.AdminPassAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.PassAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "recover":
|
||||
_, err = op.App().RecoverAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.RecoverAppVersionRequest{
|
||||
case ActionRecover:
|
||||
_, err = c.opClient.RecoverAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.RecoverAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "reject":
|
||||
_, err = op.App().AdminRejectAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.RejectAppVersionRequest{
|
||||
case ActionReject:
|
||||
_, err = c.opClient.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{
|
||||
case ActionSubmit:
|
||||
_, err = c.opClient.SubmitAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.SubmitAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "suspend":
|
||||
_, err = op.App().SuspendAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.SuspendAppVersionRequest{
|
||||
case ActionSuspend:
|
||||
_, err = c.opClient.SuspendAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.SuspendAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
case "release":
|
||||
_, err = op.App().ReleaseAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.ReleaseAppVersionRequest{
|
||||
case ActionRelease:
|
||||
_, err = c.opClient.ReleaseAppVersion(openpitrix.ContextWithUsername(request.Username), &pb.ReleaseAppVersionRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
})
|
||||
default:
|
||||
@@ -531,12 +481,7 @@ func DoAppVersionAction(versionId string, request *types.ActionRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAppVersionFiles(versionId string, request *types.GetAppVersionFilesRequest) (*types.GetAppVersionPackageFilesResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
func (c *appTemplateOperator) GetAppVersionFiles(versionId string, request *GetAppVersionFilesRequest) (*GetAppVersionPackageFilesResponse, error) {
|
||||
getAppVersionPackageFilesRequest := &pb.GetAppVersionPackageFilesRequest{
|
||||
VersionId: &wrappers.StringValue{Value: versionId},
|
||||
}
|
||||
@@ -544,13 +489,13 @@ func GetAppVersionFiles(versionId string, request *types.GetAppVersionFilesReque
|
||||
getAppVersionPackageFilesRequest.Files = request.Files
|
||||
}
|
||||
|
||||
resp, err := op.App().GetAppVersionPackageFiles(openpitrix.SystemContext(), getAppVersionPackageFilesRequest)
|
||||
resp, err := c.opClient.GetAppVersionPackageFiles(openpitrix.SystemContext(), getAppVersionPackageFilesRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
version := &types.GetAppVersionPackageFilesResponse{
|
||||
version := &GetAppVersionPackageFilesResponse{
|
||||
VersionId: versionId,
|
||||
}
|
||||
|
||||
@@ -564,14 +509,7 @@ func GetAppVersionFiles(versionId string, request *types.GetAppVersionFilesReque
|
||||
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
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) ListAppVersionAudits(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
describeAppVersionAudits := &pb.DescribeAppVersionAuditsRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
@@ -589,10 +527,10 @@ func ListAppVersionAudits(conditions *params.Conditions, orderBy string, reverse
|
||||
if orderBy != "" {
|
||||
describeAppVersionAudits.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeAppVersionAudits.Reverse = &wrappers.BoolValue{Value: !reverse}
|
||||
describeAppVersionAudits.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
describeAppVersionAudits.Limit = uint32(limit)
|
||||
describeAppVersionAudits.Offset = uint32(offset)
|
||||
resp, err := client.App().DescribeAppVersionAudits(openpitrix.SystemContext(), describeAppVersionAudits)
|
||||
resp, err := c.opClient.DescribeAppVersionAudits(openpitrix.SystemContext(), describeAppVersionAudits)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -602,21 +540,14 @@ func ListAppVersionAudits(conditions *params.Conditions, orderBy string, reverse
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionAuditSet {
|
||||
appVersion := utils.ConvertAppVersionAudit(item)
|
||||
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
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) ListAppVersionReviews(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
describeAppVersionReviews := &pb.DescribeAppVersionReviewsRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
@@ -628,11 +559,11 @@ func ListAppVersionReviews(conditions *params.Conditions, orderBy string, revers
|
||||
if orderBy != "" {
|
||||
describeAppVersionReviews.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeAppVersionReviews.Reverse = &wrappers.BoolValue{Value: !reverse}
|
||||
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)
|
||||
resp, err := c.opClient.DescribeAppVersionReviews(openpitrix.SystemContext(), describeAppVersionReviews)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -642,21 +573,14 @@ func ListAppVersionReviews(conditions *params.Conditions, orderBy string, revers
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionReviewSet {
|
||||
appVersion := utils.ConvertAppVersionReview(item)
|
||||
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
|
||||
}
|
||||
|
||||
func (c *appTemplateOperator) ListAppVersions(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
describeAppVersionsRequest := &pb.DescribeAppVersionsRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
@@ -671,10 +595,10 @@ func ListAppVersions(conditions *params.Conditions, orderBy string, reverse bool
|
||||
if orderBy != "" {
|
||||
describeAppVersionsRequest.SortKey = &wrappers.StringValue{Value: orderBy}
|
||||
}
|
||||
describeAppVersionsRequest.Reverse = &wrappers.BoolValue{Value: !reverse}
|
||||
describeAppVersionsRequest.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
describeAppVersionsRequest.Limit = uint32(limit)
|
||||
describeAppVersionsRequest.Offset = uint32(offset)
|
||||
resp, err := client.App().DescribeAppVersions(openpitrix.SystemContext(), describeAppVersionsRequest)
|
||||
resp, err := c.opClient.DescribeAppVersions(openpitrix.SystemContext(), describeAppVersionsRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -684,7 +608,7 @@ func ListAppVersions(conditions *params.Conditions, orderBy string, reverse bool
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.AppVersionSet {
|
||||
appVersion := utils.ConvertAppVersion(item)
|
||||
appVersion := convertAppVersion(item)
|
||||
items = append(items, appVersion)
|
||||
}
|
||||
|
||||
@@ -16,26 +16,32 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package attachment
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
cs "kubesphere.io/kubesphere/pkg/simple/client"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
)
|
||||
|
||||
func DescribeAttachment(id string) (*types.Attachment, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
type AttachmentInterface interface {
|
||||
DescribeAttachment(id string) (*Attachment, error)
|
||||
}
|
||||
|
||||
type attachmentOperator struct {
|
||||
opClient openpitrix.Client
|
||||
}
|
||||
|
||||
func newAttachmentOperator(opClient openpitrix.Client) AttachmentInterface {
|
||||
return &attachmentOperator{
|
||||
opClient: opClient,
|
||||
}
|
||||
resp, err := op.Attachment().GetAttachments(openpitrix.SystemContext(), &pb.GetAttachmentsRequest{
|
||||
}
|
||||
|
||||
func (c *attachmentOperator) DescribeAttachment(id string) (*Attachment, error) {
|
||||
resp, err := c.opClient.GetAttachments(openpitrix.SystemContext(), &pb.GetAttachmentsRequest{
|
||||
AttachmentId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -43,7 +49,7 @@ func DescribeAttachment(id string) (*types.Attachment, error) {
|
||||
return nil, err
|
||||
}
|
||||
if len(resp.Attachments) > 0 {
|
||||
return utils.ConvertAttachment(resp.Attachments[id]), nil
|
||||
return convertAttachment(resp.Attachments[id]), nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
klog.Error(err)
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
* Copyright 2020 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.
|
||||
@@ -16,7 +16,7 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package category
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"github.com/golang/protobuf/ptypes/wrappers"
|
||||
@@ -24,20 +24,30 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"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 *types.CreateCategoryRequest) (*types.CreateCategoryResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
type CategoryInterface interface {
|
||||
CreateCategory(request *CreateCategoryRequest) (*CreateCategoryResponse, error)
|
||||
DeleteCategory(id string) error
|
||||
ModifyCategory(id string, request *ModifyCategoryRequest) error
|
||||
ListCategories(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error)
|
||||
DescribeCategory(id string) (*Category, error)
|
||||
}
|
||||
|
||||
type categoryOperator struct {
|
||||
opClient openpitrix.Client
|
||||
}
|
||||
|
||||
func newCategoryOperator(opClient openpitrix.Client) CategoryInterface {
|
||||
return &categoryOperator{
|
||||
opClient: opClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *categoryOperator) CreateCategory(request *CreateCategoryRequest) (*CreateCategoryResponse, error) {
|
||||
r := &pb.CreateCategoryRequest{
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
Locale: &wrappers.StringValue{Value: request.Locale},
|
||||
@@ -47,23 +57,18 @@ func CreateCategory(request *types.CreateCategoryRequest) (*types.CreateCategory
|
||||
r.Icon = &wrappers.BytesValue{Value: request.Icon}
|
||||
}
|
||||
|
||||
resp, err := op.Category().CreateCategory(openpitrix.SystemContext(), r)
|
||||
resp, err := c.opClient.CreateCategory(openpitrix.SystemContext(), r)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &types.CreateCategoryResponse{
|
||||
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{
|
||||
func (c *categoryOperator) DeleteCategory(id string) error {
|
||||
_, err := c.opClient.DeleteCategories(openpitrix.SystemContext(), &pb.DeleteCategoriesRequest{
|
||||
CategoryId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -73,12 +78,7 @@ func DeleteCategory(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchCategory(id string, request *types.ModifyCategoryRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
func (c *categoryOperator) ModifyCategory(id string, request *ModifyCategoryRequest) error {
|
||||
modifyCategoryRequest := &pb.ModifyCategoryRequest{
|
||||
CategoryId: &wrappers.StringValue{Value: id},
|
||||
}
|
||||
@@ -95,7 +95,7 @@ func PatchCategory(id string, request *types.ModifyCategoryRequest) error {
|
||||
modifyCategoryRequest.Icon = &wrappers.BytesValue{Value: request.Icon}
|
||||
}
|
||||
|
||||
_, err = op.Category().ModifyCategory(openpitrix.SystemContext(), modifyCategoryRequest)
|
||||
_, err := c.opClient.ModifyCategory(openpitrix.SystemContext(), modifyCategoryRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
@@ -103,13 +103,8 @@ func PatchCategory(id string, request *types.ModifyCategoryRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeCategory(id string) (*types.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{
|
||||
func (c *categoryOperator) DescribeCategory(id string) (*Category, error) {
|
||||
resp, err := c.opClient.DescribeCategories(openpitrix.SystemContext(), &pb.DescribeCategoriesRequest{
|
||||
CategoryId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
@@ -118,10 +113,10 @@ func DescribeCategory(id string) (*types.Category, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var category *types.Category
|
||||
var category *Category
|
||||
|
||||
if len(resp.CategorySet) > 0 {
|
||||
category = utils.ConvertCategory(resp.CategorySet[0])
|
||||
category = convertCategory(resp.CategorySet[0])
|
||||
return category, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -130,26 +125,19 @@ func DescribeCategory(id string) (*types.Category, error) {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (c *categoryOperator) ListCategories(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
req := &pb.DescribeCategoriesRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
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.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
req.Limit = uint32(limit)
|
||||
req.Offset = uint32(offset)
|
||||
resp, err := client.Category().DescribeCategories(openpitrix.SystemContext(), req)
|
||||
resp, err := c.opClient.DescribeCategories(openpitrix.SystemContext(), req)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
@@ -158,7 +146,7 @@ func ListCategories(conditions *params.Conditions, orderBy string, reverse bool,
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.CategorySet {
|
||||
items = append(items, utils.ConvertCategory(item))
|
||||
items = append(items, convertCategory(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
49
pkg/models/openpitrix/interface.go
Normal file
49
pkg/models/openpitrix/interface.go
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2020 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 (
|
||||
"k8s.io/client-go/informers"
|
||||
"kubesphere.io/kubesphere/pkg/simple/client/openpitrix"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
ApplicationInterface
|
||||
AppTemplateInterface
|
||||
AttachmentInterface
|
||||
CategoryInterface
|
||||
RepoInterface
|
||||
}
|
||||
type openpitrixOperator struct {
|
||||
ApplicationInterface
|
||||
AppTemplateInterface
|
||||
AttachmentInterface
|
||||
CategoryInterface
|
||||
RepoInterface
|
||||
}
|
||||
|
||||
func NewOpenpitrixOperator(informers informers.SharedInformerFactory, opClient openpitrix.Client) Interface {
|
||||
return &openpitrixOperator{
|
||||
ApplicationInterface: newApplicationOperator(informers, opClient),
|
||||
AppTemplateInterface: newAppTemplateOperator(opClient),
|
||||
AttachmentInterface: newAttachmentOperator(opClient),
|
||||
CategoryInterface: newCategoryOperator(opClient),
|
||||
RepoInterface: newRepoOperator(opClient),
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
*
|
||||
* Copyright 2019 The KubeSphere Authors.
|
||||
* Copyright 2020 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.
|
||||
@@ -16,7 +16,7 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package repo
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -25,21 +25,34 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog"
|
||||
"kubesphere.io/kubesphere/pkg/models"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/utils"
|
||||
"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 *types.CreateRepoRequest) (*types.CreateRepoResponse, error) {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
type RepoInterface interface {
|
||||
CreateRepo(request *CreateRepoRequest) (*CreateRepoResponse, error)
|
||||
DeleteRepo(id string) error
|
||||
ModifyRepo(id string, request *ModifyRepoRequest) error
|
||||
DescribeRepo(id string) (*Repo, error)
|
||||
ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error)
|
||||
ValidateRepo(request *ValidateRepoRequest) (*ValidateRepoResponse, error)
|
||||
DoRepoAction(repoId string, request *RepoActionRequest) error
|
||||
ListRepoEvents(repoId string, conditions *params.Conditions, limit, offset int) (*models.PageableResponse, error)
|
||||
}
|
||||
|
||||
type repoOperator struct {
|
||||
opClient openpitrix.Client
|
||||
}
|
||||
|
||||
func newRepoOperator(opClient openpitrix.Client) RepoInterface {
|
||||
return &repoOperator{
|
||||
opClient: opClient,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *repoOperator) CreateRepo(request *CreateRepoRequest) (*CreateRepoResponse, error) {
|
||||
createRepoRequest := &pb.CreateRepoRequest{
|
||||
Name: &wrappers.StringValue{Value: request.Name},
|
||||
Description: &wrappers.StringValue{Value: request.Description},
|
||||
@@ -58,23 +71,18 @@ func CreateRepo(request *types.CreateRepoRequest) (*types.CreateRepoResponse, er
|
||||
createRepoRequest.Labels = &wrappers.StringValue{Value: fmt.Sprintf("workspace=%s", *request.Workspace)}
|
||||
}
|
||||
|
||||
resp, err := op.Repo().CreateRepo(openpitrix.SystemContext(), createRepoRequest)
|
||||
resp, err := c.opClient.CreateRepo(openpitrix.SystemContext(), createRepoRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
return &types.CreateRepoResponse{
|
||||
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{
|
||||
func (c *repoOperator) DeleteRepo(id string) error {
|
||||
_, err := c.opClient.DeleteRepos(openpitrix.SystemContext(), &pb.DeleteReposRequest{
|
||||
RepoId: []string{id},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -84,12 +92,7 @@ func DeleteRepo(id string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PatchRepo(id string, request *types.ModifyRepoRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
func (c *repoOperator) ModifyRepo(id string, request *ModifyRepoRequest) error {
|
||||
modifyRepoRequest := &pb.ModifyRepoRequest{
|
||||
RepoId: &wrappers.StringValue{Value: id},
|
||||
}
|
||||
@@ -126,7 +129,7 @@ func PatchRepo(id string, request *types.ModifyRepoRequest) error {
|
||||
modifyRepoRequest.Labels = &wrappers.StringValue{Value: fmt.Sprintf("workspace=%s", *request.Workspace)}
|
||||
}
|
||||
|
||||
_, err = op.Repo().ModifyRepo(openpitrix.SystemContext(), modifyRepoRequest)
|
||||
_, err := c.opClient.ModifyRepo(openpitrix.SystemContext(), modifyRepoRequest)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
@@ -134,13 +137,8 @@ func PatchRepo(id string, request *types.ModifyRepoRequest) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DescribeRepo(id string) (*types.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{
|
||||
func (c *repoOperator) DescribeRepo(id string) (*Repo, error) {
|
||||
resp, err := c.opClient.DescribeRepos(openpitrix.SystemContext(), &pb.DescribeReposRequest{
|
||||
RepoId: []string{id},
|
||||
Limit: 1,
|
||||
})
|
||||
@@ -149,10 +147,10 @@ func DescribeRepo(id string) (*types.Repo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var repo *types.Repo
|
||||
var repo *Repo
|
||||
|
||||
if len(resp.RepoSet) > 0 {
|
||||
repo = utils.ConvertRepo(resp.RepoSet[0])
|
||||
repo = convertRepo(resp.RepoSet[0])
|
||||
return repo, nil
|
||||
} else {
|
||||
err := status.New(codes.NotFound, "resource not found").Err()
|
||||
@@ -161,41 +159,34 @@ func DescribeRepo(id string) (*types.Repo, error) {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (c *repoOperator) ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limit, offset int) (*models.PageableResponse, error) {
|
||||
req := &pb.DescribeReposRequest{}
|
||||
|
||||
if keyword := conditions.Match["keyword"]; keyword != "" {
|
||||
if keyword := conditions.Match[Keyword]; keyword != "" {
|
||||
req.SearchWord = &wrappers.StringValue{Value: keyword}
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
if status := conditions.Match[Status]; status != "" {
|
||||
req.Status = strings.Split(status, "|")
|
||||
}
|
||||
if typeStr := conditions.Match["type"]; typeStr != "" {
|
||||
if typeStr := conditions.Match[Type]; typeStr != "" {
|
||||
req.Type = strings.Split(typeStr, "|")
|
||||
}
|
||||
if visibility := conditions.Match["visibility"]; visibility != "" {
|
||||
if visibility := conditions.Match[Visibility]; visibility != "" {
|
||||
req.Visibility = strings.Split(visibility, "|")
|
||||
}
|
||||
if status := conditions.Match["status"]; status != "" {
|
||||
if status := conditions.Match[Status]; status != "" {
|
||||
req.Status = strings.Split(status, "|")
|
||||
}
|
||||
if workspace := conditions.Match["workspace"]; workspace != "" {
|
||||
if workspace := conditions.Match[WorkspaceLabel]; 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.Reverse = &wrappers.BoolValue{Value: reverse}
|
||||
req.Limit = uint32(limit)
|
||||
req.Offset = uint32(offset)
|
||||
resp, err := client.Repo().DescribeRepos(openpitrix.SystemContext(), req)
|
||||
resp, err := c.opClient.DescribeRepos(openpitrix.SystemContext(), req)
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return nil, err
|
||||
@@ -204,21 +195,14 @@ func ListRepos(conditions *params.Conditions, orderBy string, reverse bool, limi
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.RepoSet {
|
||||
items = append(items, utils.ConvertRepo(item))
|
||||
items = append(items, convertRepo(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
}
|
||||
|
||||
func ValidateRepo(request *types.ValidateRepoRequest) (*types.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{
|
||||
func (c *repoOperator) ValidateRepo(request *ValidateRepoRequest) (*ValidateRepoResponse, error) {
|
||||
resp, err := c.opClient.ValidateRepo(openpitrix.SystemContext(), &pb.ValidateRepoRequest{
|
||||
Type: &wrappers.StringValue{Value: request.Type},
|
||||
Credential: &wrappers.StringValue{Value: request.Credential},
|
||||
Url: &wrappers.StringValue{Value: request.Url},
|
||||
@@ -229,25 +213,20 @@ func ValidateRepo(request *types.ValidateRepoRequest) (*types.ValidateRepoRespon
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &types.ValidateRepoResponse{
|
||||
return &ValidateRepoResponse{
|
||||
ErrorCode: int64(resp.ErrorCode),
|
||||
Ok: resp.Ok.Value,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func DoRepoAction(repoId string, request *types.RepoActionRequest) error {
|
||||
op, err := cs.ClientSets().OpenPitrix()
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *repoOperator) DoRepoAction(repoId string, request *RepoActionRequest) error {
|
||||
var err error
|
||||
switch request.Action {
|
||||
case "index":
|
||||
case ActionIndex:
|
||||
indexRepoRequest := &pb.IndexRepoRequest{
|
||||
RepoId: &wrappers.StringValue{Value: repoId},
|
||||
}
|
||||
_, err := op.RepoIndexer().IndexRepo(openpitrix.SystemContext(), indexRepoRequest)
|
||||
_, err := c.opClient.IndexRepo(openpitrix.SystemContext(), indexRepoRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -262,13 +241,7 @@ func DoRepoAction(repoId string, request *types.RepoActionRequest) error {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func (c *repoOperator) ListRepoEvents(repoId string, conditions *params.Conditions, limit, offset int) (*models.PageableResponse, error) {
|
||||
describeRepoEventsRequest := &pb.DescribeRepoEventsRequest{
|
||||
RepoId: []string{repoId},
|
||||
}
|
||||
@@ -281,7 +254,7 @@ func ListRepoEvents(repoId string, conditions *params.Conditions, limit, offset
|
||||
describeRepoEventsRequest.Limit = uint32(limit)
|
||||
describeRepoEventsRequest.Offset = uint32(offset)
|
||||
|
||||
resp, err := op.RepoIndexer().DescribeRepoEvents(openpitrix.SystemContext(), describeRepoEventsRequest)
|
||||
resp, err := c.opClient.DescribeRepoEvents(openpitrix.SystemContext(), describeRepoEventsRequest)
|
||||
|
||||
if err != nil {
|
||||
klog.Error(err)
|
||||
@@ -291,7 +264,7 @@ func ListRepoEvents(repoId string, conditions *params.Conditions, limit, offset
|
||||
items := make([]interface{}, 0)
|
||||
|
||||
for _, item := range resp.RepoEventSet {
|
||||
items = append(items, utils.ConvertRepoEvent(item))
|
||||
items = append(items, convertRepoEvent(item))
|
||||
}
|
||||
|
||||
return &models.PageableResponse{Items: items, TotalCount: int(resp.TotalCount)}, nil
|
||||
@@ -1,4 +1,4 @@
|
||||
package types
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
@@ -835,3 +835,30 @@ type ModifyClusterAttributesRequest struct {
|
||||
// cluster name
|
||||
Name *string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
CreateTime = "create_time"
|
||||
StatusTime = "status_time"
|
||||
RuntimeId = "runtime_id"
|
||||
VersionId = "version_id"
|
||||
RepoId = "repo_id"
|
||||
CategoryId = "category_id"
|
||||
Status = "status"
|
||||
Type = "type"
|
||||
Visibility = "visibility"
|
||||
AppId = "app_id"
|
||||
Keyword = "keyword"
|
||||
ISV = "isv"
|
||||
WorkspaceLabel = "workspace"
|
||||
BuiltinRepoId = "repo-helm"
|
||||
StatusActive = "active"
|
||||
StatusSuspended = "suspended"
|
||||
ActionRecover = "recover"
|
||||
ActionSuspend = "suspend"
|
||||
ActionCancel = "cancel"
|
||||
ActionPass = "pass"
|
||||
ActionReject = "reject"
|
||||
ActionSubmit = "submit"
|
||||
ActionRelease = "release"
|
||||
ActionIndex = "index"
|
||||
)
|
||||
@@ -16,29 +16,28 @@
|
||||
* /
|
||||
*/
|
||||
|
||||
package utils
|
||||
package openpitrix
|
||||
|
||||
import (
|
||||
"github.com/go-openapi/strfmt"
|
||||
"kubesphere.io/kubesphere/pkg/models/openpitrix/type"
|
||||
"openpitrix.io/openpitrix/pkg/pb"
|
||||
"time"
|
||||
)
|
||||
|
||||
func ConvertApp(in *pb.App) *types.App {
|
||||
func convertApp(in *pb.App) *App {
|
||||
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
categorySet := make(types.AppCategorySet, 0)
|
||||
categorySet := make(AppCategorySet, 0)
|
||||
|
||||
for _, item := range in.CategorySet {
|
||||
category := ConvertResourceCategory(item)
|
||||
category := convertResourceCategory(item)
|
||||
categorySet = append(categorySet, category)
|
||||
}
|
||||
|
||||
out := types.App{
|
||||
out := App{
|
||||
CategorySet: categorySet,
|
||||
}
|
||||
|
||||
@@ -93,7 +92,7 @@ func ConvertApp(in *pb.App) *types.App {
|
||||
out.Keywords = in.Keywords.Value
|
||||
}
|
||||
if in.LatestAppVersion != nil {
|
||||
out.LatestAppVersion = ConvertAppVersion(in.LatestAppVersion)
|
||||
out.LatestAppVersion = convertAppVersion(in.LatestAppVersion)
|
||||
}
|
||||
if in.Name != nil {
|
||||
out.Name = in.Name.Value
|
||||
@@ -131,11 +130,11 @@ func ConvertApp(in *pb.App) *types.App {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertAppVersion(in *pb.AppVersion) *types.AppVersion {
|
||||
func convertAppVersion(in *pb.AppVersion) *AppVersion {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.AppVersion{}
|
||||
out := AppVersion{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
@@ -210,11 +209,11 @@ func ConvertAppVersion(in *pb.AppVersion) *types.AppVersion {
|
||||
|
||||
}
|
||||
|
||||
func ConvertResourceCategory(in *pb.ResourceCategory) *types.ResourceCategory {
|
||||
func convertResourceCategory(in *pb.ResourceCategory) *ResourceCategory {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.ResourceCategory{}
|
||||
out := ResourceCategory{}
|
||||
|
||||
if in.CategoryId != nil {
|
||||
out.CategoryId = in.CategoryId.Value
|
||||
@@ -240,11 +239,11 @@ func ConvertResourceCategory(in *pb.ResourceCategory) *types.ResourceCategory {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertCategory(in *pb.Category) *types.Category {
|
||||
func convertCategory(in *pb.Category) *Category {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.Category{}
|
||||
out := Category{}
|
||||
|
||||
if in.CategoryId != nil {
|
||||
out.CategoryID = in.CategoryId.Value
|
||||
@@ -276,11 +275,11 @@ func ConvertCategory(in *pb.Category) *types.Category {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertAttachment(in *pb.Attachment) *types.Attachment {
|
||||
func convertAttachment(in *pb.Attachment) *Attachment {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.Attachment{}
|
||||
out := Attachment{}
|
||||
|
||||
out.AttachmentID = in.AttachmentId
|
||||
|
||||
@@ -298,11 +297,11 @@ func ConvertAttachment(in *pb.Attachment) *types.Attachment {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertRepo(in *pb.Repo) *types.Repo {
|
||||
func convertRepo(in *pb.Repo) *Repo {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.Repo{}
|
||||
out := Repo{}
|
||||
|
||||
if in.RepoId != nil {
|
||||
out.RepoId = in.RepoId.Value
|
||||
@@ -317,10 +316,10 @@ func ConvertRepo(in *pb.Repo) *types.Repo {
|
||||
out.Credential = in.Credential.Value
|
||||
}
|
||||
|
||||
categorySet := make(types.RepoCategorySet, 0)
|
||||
categorySet := make(RepoCategorySet, 0)
|
||||
|
||||
for _, item := range in.CategorySet {
|
||||
category := ConvertResourceCategory(item)
|
||||
category := convertResourceCategory(item)
|
||||
categorySet = append(categorySet, category)
|
||||
}
|
||||
|
||||
@@ -339,10 +338,10 @@ func ConvertRepo(in *pb.Repo) *types.Repo {
|
||||
out.Description = in.Description.Value
|
||||
}
|
||||
|
||||
labelSet := make(types.RepoLabels, 0)
|
||||
labelSet := make(RepoLabels, 0)
|
||||
|
||||
for _, item := range in.Labels {
|
||||
label := ConvertRepoLabel(item)
|
||||
label := convertRepoLabel(item)
|
||||
labelSet = append(labelSet, label)
|
||||
}
|
||||
|
||||
@@ -358,10 +357,10 @@ func ConvertRepo(in *pb.Repo) *types.Repo {
|
||||
out.RepoId = in.RepoId.Value
|
||||
}
|
||||
|
||||
selectorSet := make(types.RepoSelectors, 0)
|
||||
selectorSet := make(RepoSelectors, 0)
|
||||
|
||||
for _, item := range in.Selectors {
|
||||
selector := ConvertRepoSelector(item)
|
||||
selector := convertRepoSelector(item)
|
||||
selectorSet = append(selectorSet, selector)
|
||||
}
|
||||
|
||||
@@ -385,11 +384,11 @@ func ConvertRepo(in *pb.Repo) *types.Repo {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertRepoLabel(in *pb.RepoLabel) *types.RepoLabel {
|
||||
func convertRepoLabel(in *pb.RepoLabel) *RepoLabel {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.RepoLabel{}
|
||||
out := RepoLabel{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
@@ -403,11 +402,11 @@ func ConvertRepoLabel(in *pb.RepoLabel) *types.RepoLabel {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertRepoSelector(in *pb.RepoSelector) *types.RepoSelector {
|
||||
func convertRepoSelector(in *pb.RepoSelector) *RepoSelector {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.RepoSelector{}
|
||||
out := RepoSelector{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
@@ -421,11 +420,11 @@ func ConvertRepoSelector(in *pb.RepoSelector) *types.RepoSelector {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertAppVersionAudit(in *pb.AppVersionAudit) *types.AppVersionAudit {
|
||||
func convertAppVersionAudit(in *pb.AppVersionAudit) *AppVersionAudit {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.AppVersionAudit{}
|
||||
out := AppVersionAudit{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
@@ -463,11 +462,11 @@ func ConvertAppVersionAudit(in *pb.AppVersionAudit) *types.AppVersionAudit {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertAppVersionReview(in *pb.AppVersionReview) *types.AppVersionReview {
|
||||
func convertAppVersionReview(in *pb.AppVersionReview) *AppVersionReview {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.AppVersionReview{}
|
||||
out := AppVersionReview{}
|
||||
if in.AppId != nil {
|
||||
out.AppId = in.AppId.Value
|
||||
}
|
||||
@@ -475,9 +474,9 @@ func ConvertAppVersionReview(in *pb.AppVersionReview) *types.AppVersionReview {
|
||||
out.AppName = in.AppName.Value
|
||||
}
|
||||
if in.Phase != nil {
|
||||
out.Phase = make(types.AppVersionReviewPhaseOAIGen)
|
||||
out.Phase = make(AppVersionReviewPhaseOAIGen)
|
||||
for k, v := range in.Phase {
|
||||
out.Phase[k] = *ConvertAppVersionReviewPhase(v)
|
||||
out.Phase[k] = *convertAppVersionReviewPhase(v)
|
||||
}
|
||||
}
|
||||
if in.ReviewId != nil {
|
||||
@@ -504,11 +503,11 @@ func ConvertAppVersionReview(in *pb.AppVersionReview) *types.AppVersionReview {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertAppVersionReviewPhase(in *pb.AppVersionReviewPhase) *types.AppVersionReviewPhase {
|
||||
func convertAppVersionReviewPhase(in *pb.AppVersionReviewPhase) *AppVersionReviewPhase {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.AppVersionReviewPhase{}
|
||||
out := AppVersionReviewPhase{}
|
||||
if in.Message != nil {
|
||||
out.Message = in.Message.Value
|
||||
}
|
||||
@@ -532,11 +531,11 @@ func ConvertAppVersionReviewPhase(in *pb.AppVersionReviewPhase) *types.AppVersio
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertRepoEvent(in *pb.RepoEvent) *types.RepoEvent {
|
||||
func convertRepoEvent(in *pb.RepoEvent) *RepoEvent {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.RepoEvent{}
|
||||
out := RepoEvent{}
|
||||
if in.CreateTime != nil {
|
||||
date := strfmt.DateTime(time.Unix(in.CreateTime.Seconds, 0))
|
||||
out.CreateTime = &date
|
||||
@@ -564,11 +563,11 @@ func ConvertRepoEvent(in *pb.RepoEvent) *types.RepoEvent {
|
||||
return &out
|
||||
}
|
||||
|
||||
func ConvertCluster(in *pb.Cluster) *types.Cluster {
|
||||
func convertCluster(in *pb.Cluster) *Cluster {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := types.Cluster{}
|
||||
out := Cluster{}
|
||||
if in.AdditionalInfo != nil {
|
||||
out.AdditionalInfo = in.AdditionalInfo.Value
|
||||
}
|
||||
Reference in New Issue
Block a user