Skip to content

Commit

Permalink
Merge pull request #475 from devtron-labs/bulk-source-change
Browse files Browse the repository at this point in the history
Bulk source change
  • Loading branch information
Ashish-devtron committed Sep 26, 2023
2 parents 915247f + ed4bcc4 commit 03470b0
Show file tree
Hide file tree
Showing 14 changed files with 347 additions and 90 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/pr-issue-validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ on:
jobs:
validate-PR-issue:
runs-on: ubuntu-latest
permissions:
issues: write
contents: read
pull-requests: write

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Validate Issue Reference
env:
GITHUB_TOKEN: ${{ secrets.GIT_TARGET_TOKEN }}
GITHUB_TOKEN: ${{ github.token }}
PR_BODY: ${{ github.event.pull_request.body }}
url: ${{ github.event.pull_request.url }}
PRNUM: ${{ github.event.pull_request.number }}
Expand Down
57 changes: 57 additions & 0 deletions api/restHandler/app/BuildPipelineRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type DevtronAppBuildRestHandler interface {
GetExternalCiById(w http.ResponseWriter, r *http.Request)
PatchCiPipelines(w http.ResponseWriter, r *http.Request)
PatchCiMaterialSourceWithAppIdAndEnvironmentId(w http.ResponseWriter, r *http.Request)
PatchCiMaterialSourceWithAppIdsAndEnvironmentId(w http.ResponseWriter, r *http.Request)
TriggerCiPipeline(w http.ResponseWriter, r *http.Request)
GetCiPipelineMin(w http.ResponseWriter, r *http.Request)
GetCIPipelineById(w http.ResponseWriter, r *http.Request)
Expand Down Expand Up @@ -249,6 +250,29 @@ func (handler PipelineConfigRestHandlerImpl) parseSourceChangeRequest(w http.Res
return &patchRequest, userId, nil
}

func (handler PipelineConfigRestHandlerImpl) parseBulkSourceChangeRequest(w http.ResponseWriter, r *http.Request) (*bean.CiMaterialBulkPatchRequest, int32, error) {
decoder := json.NewDecoder(r.Body)
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, "Unauthorized User", http.StatusUnauthorized)
return nil, 0, err
}
var patchRequest bean.CiMaterialBulkPatchRequest
err = decoder.Decode(&patchRequest)
if err != nil {
handler.Logger.Errorw("request err, BulkPatchCiPipeline", "err", err, "BulkPatchCiPipeline", patchRequest)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return nil, 0, err
}
err = handler.validator.Struct(patchRequest)
if err != nil {
handler.Logger.Errorw("request err, BulkPatchCiPipeline", "err", err, "BulkPatchCiPipeline", patchRequest)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return nil, 0, err
}
return &patchRequest, userId, nil
}

func (handler PipelineConfigRestHandlerImpl) authorizeCiSourceChangeRequest(w http.ResponseWriter, patchRequest *bean.CiMaterialPatchRequest, token string) error {
handler.Logger.Debugw("update request ", "req", patchRequest)
app, err := handler.pipelineBuilder.GetApp(patchRequest.AppId)
Expand Down Expand Up @@ -304,6 +328,23 @@ func (handler PipelineConfigRestHandlerImpl) PatchCiMaterialSourceWithAppIdAndEn
common.WriteJsonResp(w, err, createResp, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) PatchCiMaterialSourceWithAppIdsAndEnvironmentId(w http.ResponseWriter, r *http.Request) {
bulkPatchRequest, userId, err := handler.parseBulkSourceChangeRequest(w, r)
if err != nil {
handler.Logger.Errorw("Parse error, PatchCiMaterialSource", "err", err, "PatchCiMaterialSource", bulkPatchRequest)
return
}
token := r.Header.Get("token")
// Here passing the checkAppSpecificAccess func to check RBAC
bulkPatchResponse, err := handler.pipelineBuilder.BulkPatchCiMaterialSource(bulkPatchRequest, userId, token, handler.checkAppSpecificAccess)
if err != nil {
handler.Logger.Errorw("service err, BulkPatchCiPipelines", "err", err, "BulkPatchCiPipelines", bulkPatchRequest)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}
common.WriteJsonResp(w, err, bulkPatchResponse, http.StatusOK)
}

func (handler PipelineConfigRestHandlerImpl) PatchCiPipelines(w http.ResponseWriter, r *http.Request) {
decoder := json.NewDecoder(r.Body)
userId, err := handler.userAuthService.GetLoggedInUser(r)
Expand Down Expand Up @@ -1937,3 +1978,19 @@ func (handler PipelineConfigRestHandlerImpl) extractCipipelineMetaForImageTags(a
}
return externalCi, ciPipelineId, appId, nil
}

func (handler PipelineConfigRestHandlerImpl) checkAppSpecificAccess(token, action string, appId int) (bool, error) {
app, err := handler.pipelineBuilder.GetApp(appId)
if err != nil {
return false, err
}
if app.AppType != helper.CustomApp {
return false, errors.New("only custom apps supported")
}

resourceName := handler.enforcerUtil.GetAppRBACName(app.AppName)
if ok := handler.enforcer.Enforce(token, casbin.ResourceApplications, action, resourceName); !ok {
return false, errors.New(string(bean.CI_PATCH_NOT_AUTHORIZED_MESSAGE))
}
return true, nil
}
1 change: 1 addition & 0 deletions api/router/PipelineConfigRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (router PipelineConfigRouterImpl) initPipelineConfigRouter(configRouter *mu
configRouter.Path("/ci-pipeline/template/patch").HandlerFunc(router.restHandler.UpdateCiTemplate).Methods("POST")
configRouter.Path("/ci-pipeline/patch").HandlerFunc(router.restHandler.PatchCiPipelines).Methods("POST")
configRouter.Path("/ci-pipeline/patch-source").HandlerFunc(router.restHandler.PatchCiMaterialSourceWithAppIdAndEnvironmentId).Methods("PATCH")
configRouter.Path("/ci-pipeline/bulk/branch-update").HandlerFunc(router.restHandler.PatchCiMaterialSourceWithAppIdsAndEnvironmentId).Methods("PUT")
configRouter.Path("/ci-pipeline/patch/regex").HandlerFunc(router.restHandler.UpdateBranchCiPipelinesWithRegex).Methods("POST")

configRouter.Path("/cd-pipeline/{cd_pipeline_id}/material").HandlerFunc(router.restHandler.GetArtifactsByCDPipeline).Methods("GET")
Expand Down
43 changes: 28 additions & 15 deletions docs/user-guide/creating-application/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The `Overview` section contains the brief information of the application, any added tags, configured external links and deployment details of the particular application.
In this section, you can also [change project of your application](#change-project-of-your-application) and [manage tags](#manage-tags) if you added them while creating application.

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview-latest.jpg)
![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/overview-latest-1.jpg)


The following details are provided on the **Overview** page:
Expand All @@ -23,28 +23,38 @@ You can change the project of your application by clicking **Project** on the `O
1. Click `Project`.
2. On the `Change project` dialog box, select the different project you want to change from the drop-down list.

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/change-project-app.jpg)
![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/change-project-app-1.jpg)

3. Click **Save**. The application will be moved to the selected project.

Click **Save**. The application will be moved to the selected project.
{% hint style="info" %}
### If you change the project:

The current users will lose the access to the application.

The users who already have an access to the selected project, will get an access to the application automatically.
{% endhint %}

**Note**: If you change the project:
* The current users will lose the access to the application.
* The users who already have an access to the selected project, will get an access to the application automatically.

## Manage Tags

`Tags` are key-value pairs. You can add one or multiple tags in your application. When tags are propagated, they are considered as labels to Kubernetes resources. Kubernetes offers integrated support for using these labels to query objects and perform bulk operations e.g., consolidated billing using labels. You can use these tags to filter/identify resources via CLI or in other Kubernetes tools.

`Manage tags` is the central place where you can create, edit, and delete tags. You can also propagate tags as labels to Kubernetes resources for the application.

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/manage-tags-latest.jpg)
![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/manage-tags-latest-1.jpg)

* Click `Edit tags`.
* Click `Edit`.
* On the `Manage tags` page, click `+ Add tag` to add a new tag.
* Click `X` to delete a tag.
* Click the symbol <img src="https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/donot-propagate.jpg" height="10"> on the left side of your tag to propagate a tag.<br>`Note`: Dark grey colour in symbol specifies that the tags are propagated.
* Click the symbol <img src="https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/donot-propagate.jpg" height="10"> on the left side of your tag to propagate a tag.<br>

{% hint style="info" %}
Dark grey colour in symbol specifies that the tags are propagated.
{% endhint %}

* To remove the tags from propagation, click the symbol <img src="https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/propagate-dark.jpg" height="10"> again.

* Click `Save`.

The changes in the tags will be reflected in the `Tags` on the `Overview` section.
Expand Down Expand Up @@ -87,18 +97,21 @@ For more detail, refer [Kubernetes PVC](https://kubernetes.io/docs/tasks/configu

In order to configure PVC:
* Go to the `Overview` section of your application.
* On the right-corner, click `Edit Tags`.
* On the right-corner, click `Edit`.

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/pvc-edit-tags.jpg)

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/manage-tags-pvc.jpg)
![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/pvc-edit-tags-1.jpg)

* For app level PVC mounting, enter the following:<ul><li>key:`devtron.ai/ci-pvc-all`</li><li>value: metadata name (e.g., `cache-pvc)` which you define on the [PVC template](#create-pvc-file).</li></ul>`Note`: This PVC mounting will impact all the build pipilines of the application.

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/manage-tags-pvc-1.jpg)

* For pipeline level, enter the following:<ul><li>key:`devtron.ai/ci-pvc-{pipelinename}`</li><li>value: metadata name which you define on the [PVC template](#create-pvc-file).</li></ul>`Note`: This PVC mounting will impact only the particular build pipeline.

To know the `pipelinename` detail, go to the `App Configutation`, click `Workflow Editor` the pipeline name will be on the `Build` pipeline as shown below.
To know the `pipelinename` detail, go to the `App Configuration`, click `Workflow Editor` the pipeline name will be on the `Build` pipeline as shown below.

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/pipeline-name-pvc-1.jpg)

![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/pipeline-name-pvc.jpg)
![](https://devtron-public-asset.s3.us-east-2.amazonaws.com/images/creating-application/overview/pipeline-level-tag.jpg)

* Click `Save`.

Expand Down
Loading

0 comments on commit 03470b0

Please sign in to comment.