Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions api/appStore/InstalledAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,31 +411,26 @@ func (handler *InstalledAppRestHandlerImpl) FetchNotesForArgoInstalledApp(w http
return
}
handler.Logger.Infow("request payload, FetchNotesForArgoInstalledApp, app store", "installedAppId", installedAppId, "envId", envId)

notes, appName, err := handler.installedAppService.FindNotesForArgoApplication(installedAppId, envId)
notes, err := handler.installedAppService.FetchChartNotes(installedAppId, envId, token, handler.checkNotesAuth)
if err != nil {
handler.Logger.Errorw("service err, FetchNotesForArgoInstalledApp, app store", "err", err, "installedAppId", installedAppId, "envId", envId)
handler.Logger.Errorw("service err, FetchNotesFromdb, app store", "err", err, "installedAppId", installedAppId, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
return
}

//rbac block starts from here
object, object2 := handler.enforcerUtil.GetHelmObjectByAppNameAndEnvId(appName, envId)
common.WriteJsonResp(w, err, &bean2.Notes{Notes: notes}, http.StatusOK)

var ok bool
}
func (handler *InstalledAppRestHandlerImpl) checkNotesAuth(token string, appName string, envId int) bool {

object, object2 := handler.enforcerUtil.GetHelmObjectByAppNameAndEnvId(appName, envId)
var ok bool
if object2 == "" {
ok = handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object)
} else {
ok = handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object) || handler.enforcer.Enforce(token, casbin.ResourceHelmApp, casbin.ActionGet, object2)
}

if !ok {
common.WriteJsonResp(w, fmt.Errorf("unauthorized user"), nil, http.StatusForbidden)
return
}
common.WriteJsonResp(w, err, &bean2.Notes{Notes: notes}, http.StatusOK)

return ok
}

func (handler *InstalledAppRestHandlerImpl) FetchAppDetailsForInstalledApp(w http.ResponseWriter, r *http.Request) {
Expand Down
10 changes: 9 additions & 1 deletion pkg/appStore/deployment/repository/InstalledAppRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type InstalledAppRepository interface {
GetAllIntalledAppsByAppStoreId(appStoreId int) ([]InstalledAppAndEnvDetails, error)
GetAllInstalledAppsByChartRepoId(chartRepoId int) ([]InstalledAppAndEnvDetails, error)
GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId int, envId int) (*InstalledAppVersions, error)
FetchNotes(installedAppId int) (*InstalledApps, error)
GetInstalledAppVersionByAppStoreId(appStoreId int) ([]*InstalledAppVersions, error)

DeleteInstalledApp(model *InstalledApps) (*InstalledApps, error)
DeleteInstalledAppVersion(model *InstalledAppVersions) (*InstalledAppVersions, error)
GetInstalledAppVersionByInstalledAppId(id int) ([]*InstalledAppVersions, error)
Expand Down Expand Up @@ -93,6 +93,7 @@ type InstalledApps struct {
DeploymentAppType string `sql:"deployment_app_type"`
Status appStoreBean.AppstoreDeploymentStatus `sql:"status"`
DeploymentAppDeleteRequest bool `sql:"deployment_app_delete_request"`
Notes string `json:"notes"`
App app.App
Environment repository.Environment
sql.AuditLog
Expand Down Expand Up @@ -189,6 +190,13 @@ func (impl InstalledAppRepositoryImpl) UpdateInstalledAppVersion(model *Installe
}
return model, nil
}
func (impl InstalledAppRepositoryImpl) FetchNotes(installedAppId int) (*InstalledApps, error) {
model := &InstalledApps{}
err := impl.dbConnection.Model(model).
Column("installed_apps.*", "App").
Where("installed_apps.id = ?", installedAppId).Where("installed_apps.active = true").Select()
return model, err
}

func (impl InstalledAppRepositoryImpl) GetInstalledApp(id int) (*InstalledApps, error) {
model := &InstalledApps{}
Expand Down
28 changes: 28 additions & 0 deletions pkg/appStore/deployment/service/AppStoreDeploymentService.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type AppStoreDeploymentService interface {
GetInstalledAppVersion(id int, userId int32) (*appStoreBean.InstallAppVersionDTO, error)
InstallAppByHelm(installAppVersionRequest *appStoreBean.InstallAppVersionDTO, ctx context.Context) (*appStoreBean.InstallAppVersionDTO, error)
UpdateProjectHelmApp(updateAppRequest *appStoreBean.UpdateProjectHelmAppDTO) error
UpdateNotesForInstalledApp(installAppId int, notes string) (bool, error)
}

type DeploymentServiceTypeConfig struct {
Expand Down Expand Up @@ -280,6 +281,33 @@ func (impl AppStoreDeploymentServiceImpl) GetGitOpsRepoName(appName string) stri
return repoName
}

func (impl AppStoreDeploymentServiceImpl) UpdateNotesForInstalledApp(installAppId int, notes string) (bool, error) {
dbConnection := impl.installedAppRepository.GetConnection()
tx, err := dbConnection.Begin()
if err != nil {
return false, err
}
// Rollback tx on error.
defer tx.Rollback()
installedApp, err := impl.installedAppRepository.GetInstalledApp(installAppId)
if err != nil {
impl.logger.Errorw("error while fetching from db", "error", err)
return false, err
}
installedApp.Notes = notes
_, err = impl.installedAppRepository.UpdateInstalledApp(installedApp, tx)
if err != nil {
impl.logger.Errorw("error while fetching from db", "error", err)
return false, err
}
err = tx.Commit()
if err != nil {
impl.logger.Errorw("error while commit db transaction to db", "error", err)
return false, err
}
return true, nil
}

func (impl AppStoreDeploymentServiceImpl) AppStoreDeployOperationStatusUpdate(installAppId int, status appStoreBean.AppstoreDeploymentStatus) (bool, error) {
dbConnection := impl.installedAppRepository.GetConnection()
tx, err := dbConnection.Begin()
Expand Down
50 changes: 50 additions & 0 deletions pkg/appStore/deployment/service/InstalledAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
util3 "github.com/devtron-labs/devtron/util"
"github.com/devtron-labs/devtron/util/argo"
"net/http"
"regexp"

/* #nosec */
"crypto/sha1"
Expand Down Expand Up @@ -82,6 +83,7 @@ type InstalledAppService interface {
MarkGitOpsInstalledAppsDeletedIfArgoAppIsDeleted(installedAppId int, envId int) error
CheckAppExistsByInstalledAppId(installedAppId int) error
FindNotesForArgoApplication(installedAppId, envId int) (string, string, error)
FetchChartNotes(installedAppId int, envId int, token string, checkNotesAuth func(token string, appName string, envId int) bool) (string, error)
}

type InstalledAppServiceImpl struct {
Expand Down Expand Up @@ -783,6 +785,48 @@ func (impl *InstalledAppServiceImpl) FindAppDetailsForAppstoreApplication(instal
}
return appDetail, nil
}
func (impl *InstalledAppServiceImpl) FetchChartNotes(installedAppId int, envId int, token string, checkNotesAuth func(token string, appName string, envId int) bool) (string, error) {
//check notes.txt in db
installedApp, err := impl.installedAppRepository.FetchNotes(installedAppId)
installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId)
if err != nil {
impl.logger.Errorw("error fetching installed app version in installed app service", "err", err)
return "", err
}
appStoreAppVersion, err := impl.appStoreApplicationVersionRepository.FindById(installedAppVerison.AppStoreApplicationVersion.Id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are already getting appStoreAppVersion by installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId) , no need to fetch it again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok,changes done

if err != nil {
impl.logger.Errorw("error fetching app store app version in installed app service", "err", err)
return "", err
}
chartVersion := appStoreAppVersion.Version
re := regexp.MustCompile(`CHART VERSION: ([0-9]+\.[0-9]+\.[0-9]+)`)
newStr := re.ReplaceAllString(installedApp.Notes, "CHART VERSION: "+chartVersion)
installedApp.Notes = newStr
appName := installedApp.App.AppName
if err != nil {
impl.logger.Errorw("error fetching notes from db", "err", err)
return "", err
}
isValidAuth := checkNotesAuth(token, appName, envId)
if !isValidAuth {
impl.logger.Errorw("unauthorized user", "isValidAuth", isValidAuth)
return "", fmt.Errorf("unauthorized user")
}
//if notes is not present in db then below call will happen
if installedApp.Notes == "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

notes, _, err := impl.FindNotesForArgoApplication(installedAppId, envId)
if err != nil {
impl.logger.Errorw("error fetching notes", "err", err)
return "", err
}
if notes == "" {
impl.logger.Errorw("error fetching notes", "err", err)
}
return notes, err
}

return installedApp.Notes, nil
}
func (impl *InstalledAppServiceImpl) FindNotesForArgoApplication(installedAppId, envId int) (string, string, error) {
installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId)
if err != nil {
Expand Down Expand Up @@ -829,7 +873,13 @@ func (impl *InstalledAppServiceImpl) FindNotesForArgoApplication(installedAppId,
impl.logger.Errorw("error in fetching notes", "err", err)
return notes, appName, err
}
_, err = impl.appStoreDeploymentService.UpdateNotesForInstalledApp(installedAppId, notes)
if err != nil {
impl.logger.Errorw("error in updating notes in db ", "err", err)
return notes, appName, err
}
}

return notes, appName, nil
}

Expand Down
28 changes: 28 additions & 0 deletions specs/charts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
/orchestrator/app-store/installed-app/notes:
get:
description: Used to fetch notes.txt for helm charts deployed via gitOps
parameters:
- name: env-id
in: query
description: it is an environment id of app
required: true
type: integer
- name: installed-app-id
in: query
description: it is a installed application id
required: true
type: integer
responses:
'200':
description: if it is able to fetch the notes.txt then status will be ok
content:
application/json:
schema:
properties:
notes:
type: string
description: it will provide notes
'500':
description: error while fetching notes.txt



# components mentioned below
components:
Expand Down