apps.go 19.1 KB
Newer Older
H
hongming 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 *
 * 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"
)

H
hongming 已提交
35 36 37 38 39
const (
	BuiltinRepoId = "repo-helm"
	StatusActive  = "active"
)

H
hongming 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
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 != "" {
H
hongming 已提交
61 62 63 64 65 66
		// hard code, app template in built-in repo has no repo_id attribute
		if repoId == BuiltinRepoId {
			describeAppsRequest.RepoId = []string{"\u0000"}
		} else {
			describeAppsRequest.RepoId = strings.Split(repoId, "|")
		}
H
hongming 已提交
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
	}
	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}
	}
H
hongming 已提交
155
	resp, err := op.App().CreateApp(openpitrix.ContextWithUsername(request.Username), createAppRequest)
H
hongming 已提交
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
	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}
	}

H
hongming 已提交
257
	resp, err := op.App().CreateAppVersion(openpitrix.ContextWithUsername(request.Username), createAppVersionRequest)
H
hongming 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
	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}
	}
H
hongming 已提交
590
	describeAppVersionAudits.Reverse = &wrappers.BoolValue{Value: !reverse}
H
hongming 已提交
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
	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}
	}
H
hongming 已提交
629
	describeAppVersionReviews.Reverse = &wrappers.BoolValue{Value: !reverse}
H
hongming 已提交
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
	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}
	}
H
hongming 已提交
672
	describeAppVersionsRequest.Reverse = &wrappers.BoolValue{Value: !reverse}
H
hongming 已提交
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
	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
}