Fix the password display problem when passing the chart link (#1281)
* Fix the password display problem when passing the chart link Signed-off-by: Eduardo Naves <eduardonaves41@gmail.com>
This commit is contained in:
		
							parent
							
								
									6707a3d392
								
							
						
					
					
						commit
						430677d43c
					
				|  | @ -7,6 +7,7 @@ import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
|  | 	"net/url" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
| 	"regexp" | 	"regexp" | ||||||
|  | @ -3192,6 +3193,18 @@ func renderValsSecrets(e vals.Evaluator, input ...string) ([]string, error) { | ||||||
| 	return output, nil | 	return output, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | func hideChartCredentials(chartCredentials string) (string, error) { | ||||||
|  | 	u, err := url.Parse(chartCredentials) | ||||||
|  | 	if err != nil { | ||||||
|  | 		return "", err | ||||||
|  | 	} | ||||||
|  | 	if u.User != nil { | ||||||
|  | 		u.User = url.UserPassword("---", "---") | ||||||
|  | 	} | ||||||
|  | 	modifiedURL := u.String() | ||||||
|  | 	return modifiedURL, nil | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // DisplayAffectedReleases logs the upgraded, deleted and in error releases
 | // DisplayAffectedReleases logs the upgraded, deleted and in error releases
 | ||||||
| func (ar *AffectedReleases) DisplayAffectedReleases(logger *zap.SugaredLogger) { | func (ar *AffectedReleases) DisplayAffectedReleases(logger *zap.SugaredLogger) { | ||||||
| 	if ar.Upgraded != nil && len(ar.Upgraded) > 0 { | 	if ar.Upgraded != nil && len(ar.Upgraded) > 0 { | ||||||
|  | @ -3203,7 +3216,12 @@ func (ar *AffectedReleases) DisplayAffectedReleases(logger *zap.SugaredLogger) { | ||||||
| 		) | 		) | ||||||
| 		tbl.Separator = "   " | 		tbl.Separator = "   " | ||||||
| 		for _, release := range ar.Upgraded { | 		for _, release := range ar.Upgraded { | ||||||
| 			err := tbl.AddRow(release.Name, release.Chart, release.installedVersion, release.duration.Round(time.Second)) | 			modifiedChart, modErr := hideChartCredentials(release.Chart) | ||||||
|  | 			if modErr != nil { | ||||||
|  | 				logger.Warn("Could not modify chart credentials, %v", modErr) | ||||||
|  | 				continue | ||||||
|  | 			} | ||||||
|  | 			err := tbl.AddRow(release.Name, modifiedChart, release.installedVersion, release.duration.Round(time.Second)) | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				logger.Warn("Could not add row, %v", err) | 				logger.Warn("Could not add row, %v", err) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | @ -3455,3 +3455,25 @@ func TestAppendChartDownloadTLSFlags(t *testing.T) { | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | func TestHideChartURL(t *testing.T) { | ||||||
|  | 	tests := []struct { | ||||||
|  | 		input    string | ||||||
|  | 		expected string | ||||||
|  | 	}{ | ||||||
|  | 		{"http://username:password@example.com/", "http://---:---@example.com/"}, | ||||||
|  | 		{"http://example.com@", "http://---:---@"}, | ||||||
|  | 		{"https://username:password@example.com/", "https://---:---@example.com/"}, | ||||||
|  | 		{"https://username:@password@example.com/", "https://---:---@example.com/"}, | ||||||
|  | 		{"https://username::password@example.com/", "https://---:---@example.com/"}, | ||||||
|  | 		{"https://username:httpd@example.com/", "https://---:---@example.com/"}, | ||||||
|  | 		{"https://username:httpsd@example.com/", "https://---:---@example.com/"}, | ||||||
|  | 		{"https://example.com/", "https://example.com/"}, | ||||||
|  | 	} | ||||||
|  | 	for _, test := range tests { | ||||||
|  | 		result, _ := hideChartCredentials(test.input) | ||||||
|  | 		if result != test.expected { | ||||||
|  | 			t.Errorf("For input '%s', expected '%s', but got '%s'", test.input, test.expected, result) | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue