mirror of
https://github.com/kubevela/kubevela.git
synced 2026-02-14 18:10:21 +00:00
Feat: add the updating the application trigger API (#5382)
* Feat: add the updating the application trigger API Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Fix: change the test case Signed-off-by: barnettZQG <barnett.zqg@gmail.com> * Fix: imported more than once Signed-off-by: barnettZQG <barnett.zqg@gmail.com> --------- Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
@@ -2086,7 +2086,7 @@
|
||||
"tags": [
|
||||
"application"
|
||||
],
|
||||
"summary": "list application triggers",
|
||||
"summary": "List the application triggers",
|
||||
"operationId": "listApplicationTriggers",
|
||||
"parameters": [
|
||||
{
|
||||
@@ -2124,7 +2124,7 @@
|
||||
"tags": [
|
||||
"application"
|
||||
],
|
||||
"summary": "create one application trigger",
|
||||
"summary": "Create an application trigger",
|
||||
"operationId": "createApplicationTrigger",
|
||||
"parameters": [
|
||||
{
|
||||
@@ -2160,6 +2160,51 @@
|
||||
}
|
||||
},
|
||||
"/api/v1/applications/{appName}/triggers/{token}": {
|
||||
"put": {
|
||||
"consumes": [
|
||||
"application/xml",
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json",
|
||||
"application/xml"
|
||||
],
|
||||
"tags": [
|
||||
"application"
|
||||
],
|
||||
"summary": "Update an application trigger",
|
||||
"operationId": "updateApplicationTrigger",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "identifier of the application ",
|
||||
"name": "appName",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "identifier of the trigger",
|
||||
"name": "token",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/v1.ApplicationTriggerBase"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/bcode.Bcode"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"consumes": [
|
||||
"application/xml",
|
||||
@@ -2172,7 +2217,7 @@
|
||||
"tags": [
|
||||
"application"
|
||||
],
|
||||
"summary": "delete one application trigger",
|
||||
"summary": "Delete an application trigger",
|
||||
"operationId": "deleteApplicationTrigger",
|
||||
"parameters": [
|
||||
{
|
||||
@@ -8964,8 +9009,8 @@
|
||||
},
|
||||
"model.ApplicationRevision": {
|
||||
"required": [
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"createTime",
|
||||
"appPrimaryKey",
|
||||
"version",
|
||||
"revisionCRName",
|
||||
@@ -9347,11 +9392,11 @@
|
||||
},
|
||||
"model.WorkflowStep": {
|
||||
"required": [
|
||||
"alias",
|
||||
"name",
|
||||
"dependsOn",
|
||||
"description",
|
||||
"orderIndex",
|
||||
"dependsOn",
|
||||
"name",
|
||||
"alias",
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
@@ -9469,9 +9514,9 @@
|
||||
},
|
||||
"model.WorkflowStepStatus": {
|
||||
"required": [
|
||||
"id",
|
||||
"name",
|
||||
"alias"
|
||||
"alias",
|
||||
"id"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -10055,11 +10100,11 @@
|
||||
"v1.ApplicationDeployResponse": {
|
||||
"required": [
|
||||
"version",
|
||||
"status",
|
||||
"triggerType",
|
||||
"createTime",
|
||||
"status",
|
||||
"note",
|
||||
"envName",
|
||||
"triggerType",
|
||||
"record"
|
||||
],
|
||||
"properties": {
|
||||
@@ -10338,6 +10383,7 @@
|
||||
"type",
|
||||
"payloadType",
|
||||
"token",
|
||||
"registry",
|
||||
"createTime",
|
||||
"updateTime"
|
||||
],
|
||||
@@ -10361,6 +10407,9 @@
|
||||
"payloadType": {
|
||||
"type": "string"
|
||||
},
|
||||
"registry": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -10833,13 +10882,13 @@
|
||||
},
|
||||
"v1.ConfigTemplateDetail": {
|
||||
"required": [
|
||||
"sensitive",
|
||||
"createTime",
|
||||
"alias",
|
||||
"name",
|
||||
"namespace",
|
||||
"description",
|
||||
"scope",
|
||||
"sensitive",
|
||||
"createTime",
|
||||
"alias",
|
||||
"schema",
|
||||
"uiSchema"
|
||||
],
|
||||
@@ -11669,11 +11718,11 @@
|
||||
},
|
||||
"v1.DetailAddonResponse": {
|
||||
"required": [
|
||||
"invisible",
|
||||
"name",
|
||||
"version",
|
||||
"description",
|
||||
"icon",
|
||||
"invisible",
|
||||
"description",
|
||||
"schema",
|
||||
"uiSchema",
|
||||
"definitions",
|
||||
@@ -11753,12 +11802,12 @@
|
||||
},
|
||||
"v1.DetailApplicationResponse": {
|
||||
"required": [
|
||||
"project",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"name",
|
||||
"alias",
|
||||
"project",
|
||||
"description",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"icon",
|
||||
"policies",
|
||||
"envBindings",
|
||||
@@ -11816,20 +11865,20 @@
|
||||
},
|
||||
"v1.DetailClusterResponse": {
|
||||
"required": [
|
||||
"status",
|
||||
"provider",
|
||||
"dashboardURL",
|
||||
"description",
|
||||
"icon",
|
||||
"labels",
|
||||
"reason",
|
||||
"apiServerURL",
|
||||
"kubeConfigSecret",
|
||||
"alias",
|
||||
"status",
|
||||
"dashboardURL",
|
||||
"icon",
|
||||
"description",
|
||||
"reason",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"name",
|
||||
"kubeConfig",
|
||||
"labels",
|
||||
"provider",
|
||||
"apiServerURL",
|
||||
"createTime",
|
||||
"resourceInfo"
|
||||
],
|
||||
"properties": {
|
||||
@@ -11887,13 +11936,13 @@
|
||||
},
|
||||
"v1.DetailComponentResponse": {
|
||||
"required": [
|
||||
"name",
|
||||
"main",
|
||||
"alias",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"appPrimaryKey",
|
||||
"creator",
|
||||
"name",
|
||||
"main",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"alias",
|
||||
"type",
|
||||
"definition"
|
||||
],
|
||||
@@ -11982,12 +12031,12 @@
|
||||
},
|
||||
"v1.DetailDefinitionResponse": {
|
||||
"required": [
|
||||
"alias",
|
||||
"labels",
|
||||
"ownerAddon",
|
||||
"name",
|
||||
"alias",
|
||||
"icon",
|
||||
"labels",
|
||||
"description",
|
||||
"icon",
|
||||
"status",
|
||||
"schema",
|
||||
"uiSchema"
|
||||
@@ -12045,15 +12094,15 @@
|
||||
},
|
||||
"v1.DetailPolicyResponse": {
|
||||
"required": [
|
||||
"description",
|
||||
"creator",
|
||||
"envName",
|
||||
"name",
|
||||
"alias",
|
||||
"type",
|
||||
"description",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"type",
|
||||
"properties"
|
||||
"alias",
|
||||
"creator",
|
||||
"properties",
|
||||
"envName"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -12095,18 +12144,18 @@
|
||||
},
|
||||
"v1.DetailRevisionResponse": {
|
||||
"required": [
|
||||
"appPrimaryKey",
|
||||
"revisionCRName",
|
||||
"triggerType",
|
||||
"workflowName",
|
||||
"version",
|
||||
"status",
|
||||
"deployUser",
|
||||
"note",
|
||||
"createTime",
|
||||
"appPrimaryKey",
|
||||
"deployUser",
|
||||
"triggerType",
|
||||
"updateTime",
|
||||
"revisionCRName",
|
||||
"reason",
|
||||
"envName"
|
||||
"envName",
|
||||
"version",
|
||||
"workflowName",
|
||||
"createTime"
|
||||
],
|
||||
"properties": {
|
||||
"appPrimaryKey": {
|
||||
@@ -12163,10 +12212,10 @@
|
||||
},
|
||||
"v1.DetailTargetResponse": {
|
||||
"required": [
|
||||
"updateTime",
|
||||
"name",
|
||||
"project",
|
||||
"createTime",
|
||||
"updateTime"
|
||||
"project"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -12206,11 +12255,11 @@
|
||||
},
|
||||
"v1.DetailUserResponse": {
|
||||
"required": [
|
||||
"email",
|
||||
"disabled",
|
||||
"createTime",
|
||||
"lastLoginTime",
|
||||
"name",
|
||||
"email",
|
||||
"projects",
|
||||
"roles"
|
||||
],
|
||||
@@ -12252,12 +12301,12 @@
|
||||
"v1.DetailWorkflowRecordResponse": {
|
||||
"required": [
|
||||
"status",
|
||||
"mode",
|
||||
"workflowAlias",
|
||||
"applicationRevision",
|
||||
"namespace",
|
||||
"message",
|
||||
"mode",
|
||||
"name",
|
||||
"namespace",
|
||||
"workflowName",
|
||||
"deployTime",
|
||||
"deployUser",
|
||||
@@ -12321,15 +12370,15 @@
|
||||
"v1.DetailWorkflowResponse": {
|
||||
"required": [
|
||||
"name",
|
||||
"enable",
|
||||
"envName",
|
||||
"alias",
|
||||
"description",
|
||||
"default",
|
||||
"createTime",
|
||||
"updateTime",
|
||||
"subMode",
|
||||
"alias",
|
||||
"enable",
|
||||
"default",
|
||||
"envName",
|
||||
"mode"
|
||||
"mode",
|
||||
"subMode"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -12537,8 +12586,8 @@
|
||||
},
|
||||
"v1.EnvBindingTarget": {
|
||||
"required": [
|
||||
"name",
|
||||
"alias"
|
||||
"alias",
|
||||
"name"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -12565,11 +12614,11 @@
|
||||
"v1.GetPipelineResponse": {
|
||||
"required": [
|
||||
"spec",
|
||||
"description",
|
||||
"createTime",
|
||||
"name",
|
||||
"alias",
|
||||
"project",
|
||||
"description",
|
||||
"info"
|
||||
],
|
||||
"properties": {
|
||||
@@ -12612,10 +12661,10 @@
|
||||
},
|
||||
"v1.GetPipelineRunLogResponse": {
|
||||
"required": [
|
||||
"phase",
|
||||
"id",
|
||||
"name",
|
||||
"type",
|
||||
"phase",
|
||||
"source",
|
||||
"log"
|
||||
],
|
||||
@@ -13269,11 +13318,11 @@
|
||||
},
|
||||
"v1.LoginUserInfoResponse": {
|
||||
"required": [
|
||||
"createTime",
|
||||
"lastLoginTime",
|
||||
"name",
|
||||
"email",
|
||||
"disabled",
|
||||
"createTime",
|
||||
"lastLoginTime",
|
||||
"projects",
|
||||
"platformPermissions",
|
||||
"projectPermissions"
|
||||
@@ -13475,11 +13524,11 @@
|
||||
},
|
||||
"v1.PipelineBase": {
|
||||
"required": [
|
||||
"description",
|
||||
"createTime",
|
||||
"name",
|
||||
"alias",
|
||||
"project",
|
||||
"description",
|
||||
"spec"
|
||||
],
|
||||
"properties": {
|
||||
@@ -13578,11 +13627,11 @@
|
||||
},
|
||||
"v1.PipelineMetaResponse": {
|
||||
"required": [
|
||||
"name",
|
||||
"alias",
|
||||
"project",
|
||||
"description",
|
||||
"createTime",
|
||||
"name",
|
||||
"alias"
|
||||
"createTime"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
@@ -13605,13 +13654,13 @@
|
||||
},
|
||||
"v1.PipelineRun": {
|
||||
"required": [
|
||||
"contextName",
|
||||
"contextValues",
|
||||
"spec",
|
||||
"pipelineName",
|
||||
"project",
|
||||
"pipelineRunName",
|
||||
"record",
|
||||
"contextName",
|
||||
"contextValues",
|
||||
"spec",
|
||||
"status"
|
||||
],
|
||||
"properties": {
|
||||
@@ -14208,9 +14257,9 @@
|
||||
},
|
||||
"v1.SystemInfoResponse": {
|
||||
"required": [
|
||||
"loginType",
|
||||
"platformID",
|
||||
"enableCollection",
|
||||
"loginType",
|
||||
"systemVersion"
|
||||
],
|
||||
"properties": {
|
||||
@@ -14734,14 +14783,14 @@
|
||||
},
|
||||
"v1.WorkflowRecord": {
|
||||
"required": [
|
||||
"namespace",
|
||||
"message",
|
||||
"status",
|
||||
"mode",
|
||||
"name",
|
||||
"namespace",
|
||||
"workflowName",
|
||||
"workflowAlias",
|
||||
"applicationRevision"
|
||||
"applicationRevision",
|
||||
"mode",
|
||||
"message"
|
||||
],
|
||||
"properties": {
|
||||
"applicationRevision": {
|
||||
@@ -14832,8 +14881,8 @@
|
||||
},
|
||||
"v1.WorkflowStep": {
|
||||
"required": [
|
||||
"type",
|
||||
"name"
|
||||
"name",
|
||||
"type"
|
||||
],
|
||||
"properties": {
|
||||
"alias": {
|
||||
|
||||
@@ -99,6 +99,7 @@ type ApplicationService interface {
|
||||
CreateApplicationTrigger(ctx context.Context, app *model.Application, req apisv1.CreateApplicationTriggerRequest) (*apisv1.ApplicationTriggerBase, error)
|
||||
ListApplicationTriggers(ctx context.Context, app *model.Application) ([]*apisv1.ApplicationTriggerBase, error)
|
||||
DeleteApplicationTrigger(ctx context.Context, app *model.Application, triggerName string) error
|
||||
UpdateApplicationTrigger(ctx context.Context, app *model.Application, token string, req apisv1.UpdateApplicationTriggerRequest) (*apisv1.ApplicationTriggerBase, error)
|
||||
}
|
||||
|
||||
type applicationServiceImpl struct {
|
||||
@@ -410,6 +411,18 @@ func (c *applicationServiceImpl) CreateApplication(ctx context.Context, req apis
|
||||
|
||||
// CreateApplicationTrigger create application trigger
|
||||
func (c *applicationServiceImpl) CreateApplicationTrigger(ctx context.Context, app *model.Application, req apisv1.CreateApplicationTriggerRequest) (*apisv1.ApplicationTriggerBase, error) {
|
||||
// checking the workflow
|
||||
_, err := c.WorkflowService.GetWorkflow(ctx, app, req.WorkflowName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.ComponentName != "" {
|
||||
_, err := c.GetApplicationComponent(ctx, app, req.ComponentName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
trigger := &model.ApplicationTrigger{
|
||||
AppPrimaryKey: app.Name,
|
||||
WorkflowName: req.WorkflowName,
|
||||
@@ -427,18 +440,7 @@ func (c *applicationServiceImpl) CreateApplicationTrigger(ctx context.Context, a
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &apisv1.ApplicationTriggerBase{
|
||||
WorkflowName: req.WorkflowName,
|
||||
Name: req.Name,
|
||||
Alias: req.Alias,
|
||||
Description: req.Description,
|
||||
Type: req.Type,
|
||||
PayloadType: req.PayloadType,
|
||||
Token: trigger.Token,
|
||||
ComponentName: trigger.ComponentName,
|
||||
CreateTime: trigger.CreateTime,
|
||||
UpdateTime: trigger.UpdateTime,
|
||||
}, nil
|
||||
return assembler.ConvertTrigger2DTO(*trigger), nil
|
||||
}
|
||||
|
||||
// DeleteApplicationTrigger delete application trigger
|
||||
@@ -457,6 +459,42 @@ func (c *applicationServiceImpl) DeleteApplicationTrigger(ctx context.Context, a
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateApplicationTrigger update application trigger
|
||||
func (c *applicationServiceImpl) UpdateApplicationTrigger(ctx context.Context, app *model.Application, token string, req apisv1.UpdateApplicationTriggerRequest) (*apisv1.ApplicationTriggerBase, error) {
|
||||
trigger := model.ApplicationTrigger{
|
||||
AppPrimaryKey: app.PrimaryKey(),
|
||||
Token: token,
|
||||
}
|
||||
if err := c.Store.Get(ctx, &trigger); err != nil {
|
||||
if errors.Is(err, datastore.ErrRecordNotExist) {
|
||||
return nil, bcode.ErrApplicationTriggerNotExist
|
||||
}
|
||||
klog.Warningf("get app trigger failure %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
// checking the workflow
|
||||
_, err := c.WorkflowService.GetWorkflow(ctx, app, req.WorkflowName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if req.ComponentName != "" {
|
||||
_, err := c.GetApplicationComponent(ctx, app, req.ComponentName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
trigger.Alias = req.Alias
|
||||
trigger.ComponentName = req.ComponentName
|
||||
trigger.Description = req.Description
|
||||
trigger.WorkflowName = req.WorkflowName
|
||||
trigger.Registry = req.Registry
|
||||
trigger.PayloadType = req.PayloadType
|
||||
if err := c.Store.Put(ctx, &trigger); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return assembler.ConvertTrigger2DTO(trigger), nil
|
||||
}
|
||||
|
||||
// ListApplicationTrigger list application triggers
|
||||
func (c *applicationServiceImpl) ListApplicationTriggers(ctx context.Context, app *model.Application) ([]*apisv1.ApplicationTriggerBase, error) {
|
||||
trigger := &model.ApplicationTrigger{
|
||||
|
||||
@@ -208,15 +208,17 @@ var _ = Describe("Test application service function", func() {
|
||||
appModel, err := appService.GetApplication(context.TODO(), testApp)
|
||||
Expect(err).Should(BeNil())
|
||||
_, err = appService.CreateApplicationTrigger(context.TODO(), appModel, v1.CreateApplicationTriggerRequest{
|
||||
Name: "trigger-name",
|
||||
Name: "trigger-name",
|
||||
WorkflowName: repository.ConvertWorkflowName("app-dev"),
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
base, err := appService.CreateApplicationTrigger(context.TODO(), appModel, v1.CreateApplicationTriggerRequest{
|
||||
Name: "trigger-name-2",
|
||||
ComponentName: "trigger-component",
|
||||
ComponentName: "component-name",
|
||||
WorkflowName: repository.ConvertWorkflowName("app-dev"),
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(base.ComponentName).Should(Equal("trigger-component"))
|
||||
Expect(base.ComponentName).Should(Equal("component-name"))
|
||||
})
|
||||
|
||||
It("Test ListTriggers function", func() {
|
||||
@@ -299,6 +301,33 @@ var _ = Describe("Test application service function", func() {
|
||||
Expect(cmp.Diff(len(detailResponse.Traits), 2)).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test UpdateTrigger function", func() {
|
||||
appModel, err := appService.GetApplication(context.TODO(), testApp)
|
||||
Expect(err).Should(BeNil())
|
||||
triggers, err := appService.ListApplicationTriggers(context.TODO(), appModel)
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(len(triggers)).Should(Equal(2))
|
||||
_, err = appService.UpdateApplicationTrigger(context.TODO(), appModel, triggers[1].Token, v1.UpdateApplicationTriggerRequest{
|
||||
ComponentName: "notfound",
|
||||
WorkflowName: repository.ConvertWorkflowName("app-dev"),
|
||||
})
|
||||
Expect(err).Should(Equal(bcode.ErrApplicationComponentNotExist))
|
||||
_, err = appService.UpdateApplicationTrigger(context.TODO(), appModel, triggers[1].Token, v1.UpdateApplicationTriggerRequest{
|
||||
WorkflowName: "notfound",
|
||||
})
|
||||
Expect(err).Should(Equal(bcode.ErrWorkflowNotExist))
|
||||
base, err := appService.UpdateApplicationTrigger(context.TODO(), appModel, triggers[1].Token, v1.UpdateApplicationTriggerRequest{
|
||||
Alias: triggers[1].Alias,
|
||||
Description: triggers[1].Description,
|
||||
ComponentName: "test2",
|
||||
WorkflowName: repository.ConvertWorkflowName("app-dev"),
|
||||
PayloadType: triggers[1].PayloadType,
|
||||
Registry: triggers[1].Registry,
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
Expect(cmp.Diff(base.ComponentName, "test2")).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test DetailComponent function", func() {
|
||||
appModel, err := appService.GetApplication(context.TODO(), testApp)
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
@@ -29,6 +29,7 @@ import (
|
||||
|
||||
"github.com/oam-dev/kubevela/apis/types"
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/model"
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/domain/repository"
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/infrastructure/datastore"
|
||||
apisv1 "github.com/oam-dev/kubevela/pkg/apiserver/interfaces/api/dto/v1"
|
||||
"github.com/oam-dev/kubevela/pkg/apiserver/utils/bcode"
|
||||
@@ -168,6 +169,7 @@ var _ = Describe("Test application service function", func() {
|
||||
Name: "test-acr",
|
||||
PayloadType: "acr",
|
||||
Type: "webhook",
|
||||
WorkflowName: repository.ConvertWorkflowName("webhook-dev"),
|
||||
ComponentName: "component-name-webhook",
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
@@ -202,6 +204,7 @@ var _ = Describe("Test application service function", func() {
|
||||
PayloadType: "acr",
|
||||
Type: "webhook",
|
||||
ComponentName: "component-name-webhook",
|
||||
WorkflowName: repository.ConvertWorkflowName("webhook-dev"),
|
||||
Registry: "test-enterprise-registry.test-region.cr.aliyuncs.com",
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
@@ -236,6 +239,7 @@ var _ = Describe("Test application service function", func() {
|
||||
PayloadType: "harbor",
|
||||
Type: "webhook",
|
||||
ComponentName: "component-name-webhook",
|
||||
WorkflowName: repository.ConvertWorkflowName("webhook-dev"),
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
@@ -274,6 +278,7 @@ var _ = Describe("Test application service function", func() {
|
||||
PayloadType: "dockerhub",
|
||||
Type: "webhook",
|
||||
ComponentName: "component-name-webhook",
|
||||
WorkflowName: repository.ConvertWorkflowName("webhook-dev"),
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
@@ -306,6 +311,7 @@ var _ = Describe("Test application service function", func() {
|
||||
PayloadType: "jfrog",
|
||||
Type: "webhook",
|
||||
ComponentName: "component-name-webhook",
|
||||
WorkflowName: repository.ConvertWorkflowName("webhook-dev"),
|
||||
})
|
||||
Expect(err).Should(BeNil())
|
||||
jfrogBody := apisv1.HandleApplicationTriggerJFrogRequest{
|
||||
|
||||
@@ -48,6 +48,7 @@ var _ = Describe("Test workflow service functions", func() {
|
||||
projectService *projectServiceImpl
|
||||
envService *envServiceImpl
|
||||
envBinding *envBindingServiceImpl
|
||||
targetService *targetServiceImpl
|
||||
testProject = "workflow-project"
|
||||
ds datastore.DataStore
|
||||
)
|
||||
@@ -60,6 +61,7 @@ var _ = Describe("Test workflow service functions", func() {
|
||||
rbacService := &rbacServiceImpl{Store: ds}
|
||||
projectService = &projectServiceImpl{Store: ds, RbacService: rbacService, K8sClient: k8sClient}
|
||||
envService = &envServiceImpl{Store: ds, KubeClient: k8sClient, ProjectService: projectService}
|
||||
targetService = &targetServiceImpl{Store: ds, K8sClient: k8sClient}
|
||||
envBinding = &envBindingServiceImpl{
|
||||
Store: ds,
|
||||
WorkflowService: workflowService,
|
||||
@@ -77,11 +79,20 @@ var _ = Describe("Test workflow service functions", func() {
|
||||
ProjectService: projectService,
|
||||
EnvService: envService,
|
||||
EnvBindingService: envBinding,
|
||||
WorkflowService: workflowService,
|
||||
}
|
||||
})
|
||||
It("Test CreateWorkflow function", func() {
|
||||
|
||||
_, err := projectService.CreateProject(context.TODO(), apisv1.CreateProjectRequest{Name: testProject})
|
||||
Expect(err).Should(BeNil())
|
||||
_, err = targetService.CreateTarget(context.TODO(), apisv1.CreateTargetRequest{
|
||||
Name: "dev-1", Project: testProject, Cluster: &apisv1.ClusterTarget{ClusterName: "local", Namespace: "dev-1"}})
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
_, err = envService.CreateEnv(context.TODO(), apisv1.CreateEnvRequest{Name: "dev", Namespace: "dev-1", Targets: []string{"dev-1"}, Project: testProject})
|
||||
Expect(err).Should(BeNil())
|
||||
|
||||
reqApp := apisv1.CreateApplicationRequest{
|
||||
Name: appName,
|
||||
Project: testProject,
|
||||
|
||||
@@ -118,7 +118,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
|
||||
Writes(apis.ApplicationStatisticsResponse{}))
|
||||
|
||||
ws.Route(ws.POST("/{appName}/triggers").To(c.createApplicationTrigger).
|
||||
Doc("create one application trigger").
|
||||
Doc("Create an application trigger").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Filter(c.RbacService.CheckPerm("trigger", "create")).
|
||||
Filter(c.appCheckFilter).
|
||||
@@ -129,7 +129,7 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
|
||||
Writes(apis.ApplicationTriggerBase{}))
|
||||
|
||||
ws.Route(ws.DELETE("/{appName}/triggers/{token}").To(c.deleteApplicationTrigger).
|
||||
Doc("delete one application trigger").
|
||||
Doc("Delete an application trigger").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Filter(c.RbacService.CheckPerm("trigger", "delete")).
|
||||
Filter(c.appCheckFilter).
|
||||
@@ -139,8 +139,19 @@ func (c *application) GetWebServiceRoute() *restful.WebService {
|
||||
Returns(400, "Bad Request", bcode.Bcode{}).
|
||||
Writes([]*apis.EmptyResponse{}))
|
||||
|
||||
ws.Route(ws.PUT("/{appName}/triggers/{token}").To(c.updateApplicationTrigger).
|
||||
Doc("Update an application trigger").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Filter(c.RbacService.CheckPerm("trigger", "update")).
|
||||
Filter(c.appCheckFilter).
|
||||
Param(ws.PathParameter("appName", "identifier of the application ").DataType("string")).
|
||||
Param(ws.PathParameter("token", "identifier of the trigger").DataType("string")).
|
||||
Returns(200, "OK", apis.ApplicationTriggerBase{}).
|
||||
Returns(400, "Bad Request", bcode.Bcode{}).
|
||||
Writes([]*apis.ApplicationTriggerBase{}))
|
||||
|
||||
ws.Route(ws.GET("/{appName}/triggers").To(c.listApplicationTriggers).
|
||||
Doc("list application triggers").
|
||||
Doc("List the application triggers").
|
||||
Metadata(restfulspec.KeyOpenAPITags, tags).
|
||||
Filter(c.RbacService.CheckPerm("trigger", "list")).
|
||||
Filter(c.appCheckFilter).
|
||||
@@ -747,6 +758,24 @@ func (c *application) deleteApplicationTrigger(req *restful.Request, res *restfu
|
||||
}
|
||||
}
|
||||
|
||||
func (c *application) updateApplicationTrigger(req *restful.Request, res *restful.Response) {
|
||||
var updateReq apis.UpdateApplicationTriggerRequest
|
||||
if err := req.ReadEntity(&updateReq); err != nil {
|
||||
bcode.ReturnError(req, res, err)
|
||||
return
|
||||
}
|
||||
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
|
||||
trigger, err := c.ApplicationService.UpdateApplicationTrigger(req.Request.Context(), app, req.PathParameter("token"), updateReq)
|
||||
if err != nil {
|
||||
bcode.ReturnError(req, res, err)
|
||||
return
|
||||
}
|
||||
if err := res.WriteEntity(trigger); err != nil {
|
||||
bcode.ReturnError(req, res, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (c *application) publishApplicationTemplate(req *restful.Request, res *restful.Response) {
|
||||
app := req.Request.Context().Value(&apis.CtxKeyApplication).(*model.Application)
|
||||
base, err := c.ApplicationService.PublishApplicationTemplate(req.Request.Context(), app)
|
||||
|
||||
@@ -274,6 +274,23 @@ func ConvertPermission2DTO(permission *model.Permission) *apisv1.PermissionBase
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertTrigger2DTO convert trigger model to the DTO
|
||||
func ConvertTrigger2DTO(trigger model.ApplicationTrigger) *apisv1.ApplicationTriggerBase {
|
||||
return &apisv1.ApplicationTriggerBase{
|
||||
WorkflowName: trigger.WorkflowName,
|
||||
Name: trigger.Name,
|
||||
Alias: trigger.Alias,
|
||||
Description: trigger.Description,
|
||||
Type: trigger.Type,
|
||||
PayloadType: trigger.PayloadType,
|
||||
Token: trigger.Token,
|
||||
Registry: trigger.Registry,
|
||||
ComponentName: trigger.ComponentName,
|
||||
CreateTime: trigger.CreateTime,
|
||||
UpdateTime: trigger.UpdateTime,
|
||||
}
|
||||
}
|
||||
|
||||
func convertBool(b *bool) bool {
|
||||
if b == nil {
|
||||
return false
|
||||
|
||||
@@ -512,6 +512,16 @@ type CreateApplicationTriggerRequest struct {
|
||||
Registry string `json:"registry,omitempty" optional:"true"`
|
||||
}
|
||||
|
||||
// UpdateApplicationTriggerRequest update application trigger
|
||||
type UpdateApplicationTriggerRequest struct {
|
||||
Alias string `json:"alias" validate:"checkalias" optional:"true"`
|
||||
Description string `json:"description" optional:"true"`
|
||||
WorkflowName string `json:"workflowName"`
|
||||
PayloadType string `json:"payloadType" validate:"checkpayloadtype"`
|
||||
ComponentName string `json:"componentName,omitempty" optional:"true"`
|
||||
Registry string `json:"registry,omitempty" optional:"true"`
|
||||
}
|
||||
|
||||
// ApplicationTriggerBase application trigger base model
|
||||
type ApplicationTriggerBase struct {
|
||||
Name string `json:"name"`
|
||||
@@ -522,6 +532,7 @@ type ApplicationTriggerBase struct {
|
||||
PayloadType string `json:"payloadType"`
|
||||
Token string `json:"token"`
|
||||
ComponentName string `json:"componentName,omitempty"`
|
||||
Registry string `json:"registry"`
|
||||
CreateTime time.Time `json:"createTime"`
|
||||
UpdateTime time.Time `json:"updateTime"`
|
||||
}
|
||||
|
||||
@@ -34,9 +34,33 @@ import (
|
||||
var appName = "app-e2e"
|
||||
var appProject = "test-app-project"
|
||||
|
||||
func prepareEnv(envName string) {
|
||||
var targetName = testNSprefix + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
// create target
|
||||
var createTarget = apisv1.CreateTargetRequest{
|
||||
Name: targetName,
|
||||
Project: appProject,
|
||||
Cluster: &apisv1.ClusterTarget{
|
||||
ClusterName: "local",
|
||||
Namespace: targetName,
|
||||
},
|
||||
}
|
||||
res := post("/targets", createTarget)
|
||||
Expect(decodeResponseBody(res, nil)).Should(Succeed())
|
||||
|
||||
// create env
|
||||
var createEnvReq = apisv1.CreateEnvRequest{
|
||||
Name: envName,
|
||||
Targets: []string{targetName},
|
||||
}
|
||||
res = post("/envs", createEnvReq)
|
||||
Expect(decodeResponseBody(res, nil)).Should(Succeed())
|
||||
}
|
||||
|
||||
var _ = Describe("Test application rest api", func() {
|
||||
It("Test create app", func() {
|
||||
defer GinkgoRecover()
|
||||
prepareEnv("dev-env")
|
||||
var req = apisv1.CreateApplicationRequest{
|
||||
Name: appName,
|
||||
Project: appProject,
|
||||
@@ -58,7 +82,7 @@ var _ = Describe("Test application rest api", func() {
|
||||
Expect(cmp.Diff(appBase.Labels["test"], req.Labels["test"])).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test list components", func() {
|
||||
It("Test listing components", func() {
|
||||
defer GinkgoRecover()
|
||||
res := get("/applications/" + appName + "/components")
|
||||
var components apisv1.ComponentListResponse
|
||||
@@ -66,37 +90,42 @@ var _ = Describe("Test application rest api", func() {
|
||||
Expect(cmp.Diff(len(components.Components), 1)).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test updating a trigger", func() {
|
||||
defer GinkgoRecover()
|
||||
res := get("/applications/" + appName + "/triggers")
|
||||
var triggers apisv1.ListApplicationTriggerResponse
|
||||
Expect(decodeResponseBody(res, &triggers)).Should(Succeed())
|
||||
Expect(cmp.Diff(len(triggers.Triggers), 1)).Should(BeEmpty())
|
||||
|
||||
old := triggers.Triggers[0]
|
||||
var req = apisv1.UpdateApplicationTriggerRequest{
|
||||
Alias: "Update",
|
||||
Description: "Update the description",
|
||||
WorkflowName: old.WorkflowName,
|
||||
PayloadType: old.PayloadType,
|
||||
ComponentName: old.ComponentName,
|
||||
Registry: old.Registry,
|
||||
}
|
||||
res = put("/applications/"+appName+"/triggers/"+old.Token, req)
|
||||
var base apisv1.ApplicationTriggerBase
|
||||
Expect(decodeResponseBody(res, &base)).Should(Succeed())
|
||||
Expect(cmp.Diff(base.Alias, req.Alias)).Should(BeEmpty())
|
||||
Expect(cmp.Diff(base.Description, req.Description)).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test detail application", func() {
|
||||
defer GinkgoRecover()
|
||||
res := get("/applications/" + appName)
|
||||
var detail apisv1.DetailApplicationResponse
|
||||
Expect(decodeResponseBody(res, &detail)).Should(Succeed())
|
||||
Expect(cmp.Diff(len(detail.Policies), 0)).Should(BeEmpty())
|
||||
// The policy for the dev-env environment
|
||||
Expect(cmp.Diff(len(detail.Policies), 1)).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("Test deploy application", func() {
|
||||
defer GinkgoRecover()
|
||||
var targetName = testNSprefix + strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||
var envName = "dev"
|
||||
// create target
|
||||
var createTarget = apisv1.CreateTargetRequest{
|
||||
Name: targetName,
|
||||
Project: appProject,
|
||||
Cluster: &apisv1.ClusterTarget{
|
||||
ClusterName: "local",
|
||||
Namespace: targetName,
|
||||
},
|
||||
}
|
||||
res := post("/targets", createTarget)
|
||||
Expect(decodeResponseBody(res, nil)).Should(Succeed())
|
||||
|
||||
// create env
|
||||
var createEnvReq = apisv1.CreateEnvRequest{
|
||||
Name: envName,
|
||||
Targets: []string{targetName},
|
||||
}
|
||||
res = post("/envs", createEnvReq)
|
||||
Expect(decodeResponseBody(res, nil)).Should(Succeed())
|
||||
prepareEnv(envName)
|
||||
|
||||
// create envbinding
|
||||
var createEnvbindingReq = apisv1.CreateApplicationEnvbindingRequest{
|
||||
@@ -104,7 +133,7 @@ var _ = Describe("Test application rest api", func() {
|
||||
Name: envName,
|
||||
},
|
||||
}
|
||||
res = post("/applications/"+appName+"/envs", createEnvbindingReq)
|
||||
res := post("/applications/"+appName+"/envs", createEnvbindingReq)
|
||||
Expect(decodeResponseBody(res, nil)).Should(Succeed())
|
||||
|
||||
// deploy app
|
||||
|
||||
Reference in New Issue
Block a user