Skip to content

feat:show notes for gitops app #3045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions api/appStore/AppStoreRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func (router AppStoreRouterImpl) Init(configRouter *mux.Router) {
configRouter.Path("/installed-app/detail").Queries("installed-app-id", "{installed-app-id}").Queries("env-id", "{env-id}").
HandlerFunc(router.deployRestHandler.FetchAppDetailsForInstalledApp).
Methods("GET")
configRouter.Path("/installed-app/notes").Queries("installed-app-id", "{installed-app-id}").Queries("env-id", "{env-id}").
HandlerFunc(router.deployRestHandler.FetchNotesForArgoInstalledApp).
Methods("GET")
configRouter.Path("/installed-app").
HandlerFunc(router.deployRestHandler.GetAllInstalledApp).Methods("GET")
configRouter.Path("/cluster-component/install/{clusterId}").
Expand Down
48 changes: 48 additions & 0 deletions api/appStore/InstalledAppRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type InstalledAppRestHandler interface {
CheckAppExists(w http.ResponseWriter, r *http.Request)
DefaultComponentInstallation(w http.ResponseWriter, r *http.Request)
FetchAppDetailsForInstalledApp(w http.ResponseWriter, r *http.Request)
FetchNotesForArgoInstalledApp(w http.ResponseWriter, r *http.Request)
}

type InstalledAppRestHandlerImpl struct {
Expand Down Expand Up @@ -389,6 +390,53 @@ func (impl *InstalledAppRestHandlerImpl) DefaultComponentInstallation(w http.Res
}
common.WriteJsonResp(w, err, isTriggered, http.StatusOK)
}
func (handler *InstalledAppRestHandlerImpl) FetchNotesForArgoInstalledApp(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
if userId == 0 || err != nil {
common.WriteJsonResp(w, err, nil, http.StatusUnauthorized)
return
}
vars := mux.Vars(r)
installedAppId, err := strconv.Atoi(vars["installed-app-id"])
if err != nil {
handler.Logger.Errorw("request err, FetchNotesForArgoInstalledApp", "err", err, "installedAppId", installedAppId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
token := r.Header.Get("token")
envId, err := strconv.Atoi(vars["env-id"])
if err != nil {
handler.Logger.Errorw("request err, FetchNotesForArgoInstalledApp", "err", err, "installedAppId", installedAppId, "envId", envId)
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
return
}
handler.Logger.Infow("request payload, FetchNotesForArgoInstalledApp, app store", "installedAppId", installedAppId, "envId", envId)

notes, appName, err := handler.installedAppService.FindNotesForArgoApplication(installedAppId, envId)
if err != nil {
handler.Logger.Errorw("service err, FetchNotesForArgoInstalledApp, 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)

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)

}

func (handler *InstalledAppRestHandlerImpl) FetchAppDetailsForInstalledApp(w http.ResponseWriter, r *http.Request) {
userId, err := handler.userAuthService.GetLoggedInUser(r)
Expand Down
3 changes: 3 additions & 0 deletions api/bean/AppView.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ type AppDetailContainer struct {
LinkOuts []LinkOuts `json:"linkOuts,omitempty"`
ResourceTree map[string]interface{} `json:"resourceTree,omitempty"`
}
type Notes struct {
Notes string `json:"gitOpsNotes,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you create new struct for only notes, wasn't there any notes field in the response object?

}

type Environment struct {
AppStatus string `json:"appStatus"` //this is not the status of environment , this make sense with a specific app only
Expand Down
20 changes: 20 additions & 0 deletions api/helm-app/HelmAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type HelmAppService interface {
GetDevtronHelmAppIdentifier() *AppIdentifier
UpdateApplicationWithChartInfoWithExtraValues(ctx context.Context, appIdentifier *AppIdentifier, chartRepository *ChartRepository, extraValues map[string]interface{}, extraValuesYamlUrl string, useLatestChartVersion bool) (*openapi.UpdateReleaseResponse, error)
TemplateChart(ctx context.Context, templateChartRequest *openapi2.TemplateChartRequest) (*openapi2.TemplateChartResponse, error)
GetNotes(ctx context.Context, request *InstallReleaseRequest) (string, error)
}

type HelmAppServiceImpl struct {
Expand Down Expand Up @@ -727,6 +728,25 @@ func (impl *HelmAppServiceImpl) TemplateChart(ctx context.Context, templateChart

return response, nil
}
func (impl *HelmAppServiceImpl) GetNotes(ctx context.Context, request *InstallReleaseRequest) (string, error) {
clusterId := int(request.ReleaseIdentifier.ClusterConfig.ClusterId)
config, err := impl.GetClusterConf(clusterId)
var notesTxt string
if err != nil {
impl.logger.Errorw("error in fetching cluster detail", "clusterId", clusterId, "err", err)
return notesTxt, err
}

request.ReleaseIdentifier.ClusterConfig = config

response, err := impl.helmAppClient.GetNotes(ctx, request)
if err != nil {
impl.logger.Errorw("error in fetching chart", "err", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

add request in logging

return notesTxt, err
}
notesTxt = response.Notes
return notesTxt, err
}

type AppIdentifier struct {
ClusterId int `json:"clusterId"`
Expand Down
15 changes: 15 additions & 0 deletions api/helm-app/applicationClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type HelmAppClient interface {
RollbackRelease(ctx context.Context, in *RollbackReleaseRequest) (*BooleanResponse, error)
TemplateChart(ctx context.Context, in *InstallReleaseRequest) (*TemplateChartResponse, error)
InstallReleaseWithCustomChart(ctx context.Context, in *HelmInstallCustomRequest) (*HelmInstallCustomResponse, error)
GetNotes(ctx context.Context, request *InstallReleaseRequest) (*ChartNotesResponse, error)
}

type HelmAppClientImpl struct {
Expand Down Expand Up @@ -290,3 +291,17 @@ func (impl *HelmAppClientImpl) InstallReleaseWithCustomChart(ctx context.Context
}
return response, nil
}

func (impl *HelmAppClientImpl) GetNotes(ctx context.Context, in *InstallReleaseRequest) (*ChartNotesResponse, error) {
applicationClient, err := impl.getApplicationClient()
if err != nil {
return nil, err
}
response, err := applicationClient.GetNotes(ctx, in)

if err != nil {
return nil, err
}
return response, nil

}
Loading