-
Notifications
You must be signed in to change notification settings - Fork 554
feat: custom chart download #3801
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
7af7645
feat: custom chart download
Ash-exp 2914cf1
fixed: chartsMetadata nil pointer issue
Ash-exp 004b56d
fixed: fetch chat details
Ash-exp 4d50784
fixed: validation API error response
Ash-exp 5477145
fixed: upload validation logic
Ash-exp f92aed2
fixed: validation logic for chart name
Ash-exp 1d9ae4d
fix: chart validation logic
Ash-exp 6d3fe50
feat: added reserveCharts list to cache
Ash-exp a255b39
Merge branch 'main' into feat-custom-chart-download
Ash-exp 5bf0af4
feat: user uploaded chart download fixed
Ash-exp cc79a6b
feat: added validation for inactive chart name
Ash-exp 9017a12
Merge branch 'main' into feat-custom-chart-download
Ash-exp 3ada5a2
fixed: download function
Ash-exp 88e2563
fixed: download function
Ash-exp 95c69aa
updated chart download
Ash-exp d657716
removed comments
Ash-exp fe411b4
updated comments and removed unnecessary injection
Ash-exp 0d03337
Merge branch 'main' into feat-custom-chart-download
Ash-exp c895d3e
updated: BuildChartAndGetPath for custom charts
Ash-exp c744d66
Merge branch 'main' into feat-custom-chart-download
Ash-exp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,36 +4,41 @@ import ( | |
| "encoding/json" | ||
| "fmt" | ||
| "github.com/devtron-labs/devtron/api/restHandler/common" | ||
| "github.com/devtron-labs/devtron/internal/util" | ||
| "github.com/devtron-labs/devtron/pkg/chart" | ||
| chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository" | ||
| "github.com/devtron-labs/devtron/pkg/sql" | ||
| "github.com/devtron-labs/devtron/pkg/user" | ||
| "github.com/devtron-labs/devtron/pkg/user/casbin" | ||
| "github.com/gorilla/mux" | ||
| "github.com/juju/errors" | ||
| "go.uber.org/zap" | ||
| "gopkg.in/go-playground/validator.v9" | ||
| "io/ioutil" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|
|
||
| type DeploymentConfigRestHandler interface { | ||
| CreateChartFromFile(w http.ResponseWriter, r *http.Request) | ||
| SaveChart(w http.ResponseWriter, r *http.Request) | ||
| DownloadChart(w http.ResponseWriter, r *http.Request) | ||
| GetUploadedCharts(w http.ResponseWriter, r *http.Request) | ||
| } | ||
|
|
||
| type DeploymentConfigRestHandlerImpl struct { | ||
| Logger *zap.SugaredLogger | ||
| userAuthService user.UserService | ||
| enforcer casbin.Enforcer | ||
| validator *validator.Validate | ||
| refChartDir chartRepoRepository.RefChartDir | ||
| chartService chart.ChartService | ||
| chartRefRepository chartRepoRepository.ChartRefRepository | ||
| Logger *zap.SugaredLogger | ||
| userAuthService user.UserService | ||
| enforcer casbin.Enforcer | ||
| validator *validator.Validate | ||
| refChartDir chartRepoRepository.RefChartDir | ||
| chartService chart.ChartService | ||
| chartRefRepository chartRepoRepository.ChartRefRepository | ||
| chartTemplateService util.ChartTemplateService | ||
| } | ||
|
|
||
| type DeploymentChartInfo struct { | ||
|
|
@@ -46,15 +51,16 @@ type DeploymentChartInfo struct { | |
| } | ||
|
|
||
| func NewDeploymentConfigRestHandlerImpl(Logger *zap.SugaredLogger, userAuthService user.UserService, enforcer casbin.Enforcer, validator *validator.Validate, | ||
| refChartDir chartRepoRepository.RefChartDir, chartService chart.ChartService, chartRefRepository chartRepoRepository.ChartRefRepository) *DeploymentConfigRestHandlerImpl { | ||
| refChartDir chartRepoRepository.RefChartDir, chartService chart.ChartService, chartTemplateService util.ChartTemplateService, chartRefRepository chartRepoRepository.ChartRefRepository) *DeploymentConfigRestHandlerImpl { | ||
| return &DeploymentConfigRestHandlerImpl{ | ||
| Logger: Logger, | ||
| userAuthService: userAuthService, | ||
| enforcer: enforcer, | ||
| validator: validator, | ||
| refChartDir: refChartDir, | ||
| chartService: chartService, | ||
| chartRefRepository: chartRefRepository, | ||
| Logger: Logger, | ||
| userAuthService: userAuthService, | ||
| enforcer: enforcer, | ||
| validator: validator, | ||
| refChartDir: refChartDir, | ||
| chartService: chartService, | ||
| chartTemplateService: chartTemplateService, | ||
| chartRefRepository: chartRefRepository, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -107,7 +113,7 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo | |
| handler.Logger.Errorw("error in deleting temp dir ", "err", err1) | ||
| } | ||
| } | ||
| if err.Error() == "Chart exists already, try uploading another chart" { | ||
| if err.Error() == chart.CHART_ALREADY_EXISTS_INTERNAL_ERROR || err.Error() == chart.CHART_NAME_RESERVED_INTERNAL_ERROR { | ||
| common.WriteJsonResp(w, err, nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
|
|
@@ -210,6 +216,36 @@ func (handler *DeploymentConfigRestHandlerImpl) SaveChart(w http.ResponseWriter, | |
|
|
||
| } | ||
|
|
||
| func (handler *DeploymentConfigRestHandlerImpl) DownloadChart(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 | ||
| } | ||
|
|
||
| token := r.Header.Get("token") | ||
| if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionDelete, "*"); !ok { | ||
| common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct rbac action There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have used ActionUpdate |
||
| return | ||
| } | ||
|
|
||
| vars := mux.Vars(r) | ||
| chartRefId, err := strconv.Atoi(vars["chartRefId"]) | ||
| if err != nil { | ||
| handler.Logger.Errorw("error in parsing chartRefId", "chartRefId", chartRefId, "err", err) | ||
| common.WriteJsonResp(w, fmt.Errorf("error in parsing chartRefId : %s must be integer", chartRefId), nil, http.StatusBadRequest) | ||
| return | ||
| } | ||
| manifestByteArr, err := handler.chartService.DownloadCustomChart(chartRefId) | ||
| if err != nil { | ||
| handler.Logger.Errorw("error in converting chart to bytes", "err", err) | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
| } | ||
| common.WriteOctetStreamResp(w, r, manifestByteArr, "") | ||
| return | ||
| } | ||
|
|
||
| func (handler *DeploymentConfigRestHandlerImpl) GetUploadedCharts(w http.ResponseWriter, r *http.Request) { | ||
|
|
||
| userId, err := handler.userAuthService.GetLoggedInUser(r) | ||
|
|
@@ -224,7 +260,7 @@ func (handler *DeploymentConfigRestHandlerImpl) GetUploadedCharts(w http.Respons | |
| return | ||
| } | ||
|
|
||
| charts, err := handler.chartService.FetchChartInfoByFlag(true) | ||
| charts, err := handler.chartService.FetchCustomChartsInfo() | ||
| if err != nil { | ||
| common.WriteJsonResp(w, err, nil, http.StatusInternalServerError) | ||
| return | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 👍