Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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.FetchNotesFromdb(installedAppId, envId, token, handler.checkNotesAuth)
Copy link
Contributor

Choose a reason for hiding this comment

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

change the function name, fetchChartNotes

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

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)
FetchNotesFromdb(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) FetchNotesFromdb(installedAppId int) (*InstalledApps, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

FetchNotes

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

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
AppStoreDeployOperationNotesUpdate(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) AppStoreDeployOperationNotesUpdate(installAppId int, notes string) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

UpdateNotesForInstalledApp

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

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
34 changes: 34 additions & 0 deletions pkg/appStore/deployment/service/InstalledAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type InstalledAppService interface {
MarkGitOpsInstalledAppsDeletedIfArgoAppIsDeleted(installedAppId int, envId int) error
CheckAppExistsByInstalledAppId(installedAppId int) error
FindNotesForArgoApplication(installedAppId, envId int) (string, string, error)
FetchNotesFromdb(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 +784,33 @@ func (impl *InstalledAppServiceImpl) FindAppDetailsForAppstoreApplication(instal
}
return appDetail, nil
}
func (impl *InstalledAppServiceImpl) FetchNotesFromdb(installedAppId int, envId int, token string, checkNotesAuth func(token string, appName string, envId int) bool) (string, error) {
installedApp, err := impl.installedAppRepository.FetchNotesFromdb(installedAppId)
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 "", nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return error

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

}

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 +857,13 @@ func (impl *InstalledAppServiceImpl) FindNotesForArgoApplication(installedAppId,
impl.logger.Errorw("error in fetching notes", "err", err)
return notes, appName, err
}
_, err = impl.appStoreDeploymentService.AppStoreDeployOperationNotesUpdate(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