Skip to content

Commit 908f977

Browse files
committed
support raw api (#715)
Signed-off-by: Allen <[email protected]>
1 parent 26e2e63 commit 908f977

File tree

3 files changed

+42
-12
lines changed

3 files changed

+42
-12
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Powered by some great Go technology:
3838
- `GET /api/charts/<name>/<version>` - describe a chart version
3939
- `GET /api/charts/<name>/<version>/templates` - get chart template
4040
- `GET /api/charts/<name>/<version>/values` - get chart values
41+
- `GET /api/charts/<name>/<version>/raw` - get all the files of chart
4142
- `HEAD /api/charts/<name>` - check if chart exists (any versions)
4243
- `HEAD /api/charts/<name>/<version>` - check if chart version exists
4344

pkg/chartmuseum/server/multitenant/handlers.go

+40-11
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@ import (
2727
"time"
2828

2929
cm_storage "github.com/chartmuseum/storage"
30-
30+
"github.com/gin-gonic/gin"
31+
"go.uber.org/zap"
3132
cm_logger "helm.sh/chartmuseum/pkg/chartmuseum/logger"
3233
cm_repo "helm.sh/chartmuseum/pkg/repo"
33-
3434
"helm.sh/helm/v3/pkg/chart"
3535
"helm.sh/helm/v3/pkg/chart/loader"
3636
helm_repo "helm.sh/helm/v3/pkg/repo"
37-
38-
"github.com/gin-gonic/gin"
39-
40-
"go.uber.org/zap"
4137
)
4238

4339
var (
@@ -157,6 +153,7 @@ func (server *MultiTenantServer) getStorageObjectRequestHandler(c *gin.Context)
157153
}
158154
c.Data(200, storageObject.ContentType, storageObject.Content)
159155
}
156+
160157
func (server *MultiTenantServer) getStorageObjectTemplateRequestHandler(c *gin.Context) {
161158
repo := c.Param("repo")
162159
name := c.Param("name")
@@ -186,6 +183,34 @@ func (server *MultiTenantServer) getStorageObjectTemplateRequestHandler(c *gin.C
186183
})
187184
}
188185

186+
func (server *MultiTenantServer) getStorageObjectRawRequestHandler(c *gin.Context) {
187+
repo := c.Param("repo")
188+
name := c.Param("name")
189+
version := c.Param("version")
190+
191+
log := server.Logger.ContextLoggingFn(c)
192+
193+
fileName, err := server.getChartFileName(log, repo, name, version)
194+
if err != nil {
195+
c.JSON(http.StatusNotFound, gin.H{"error": err.Message})
196+
return
197+
}
198+
199+
storageObject, err := server.getStorageObject(log, repo, fileName)
200+
if err != nil {
201+
c.JSON(err.Status, gin.H{"error": err.Message})
202+
return
203+
}
204+
chrt, err1 := loader.LoadArchive(bytes.NewReader(storageObject.Content))
205+
if err1 != nil {
206+
c.JSON(http.StatusInternalServerError, gin.H{"error": err1})
207+
return
208+
}
209+
c.JSON(200, map[string]interface{}{
210+
"raw": chrt.Raw,
211+
})
212+
}
213+
189214
func (server *MultiTenantServer) getStorageObjectValuesRequestHandler(c *gin.Context) {
190215
repo := c.Param("repo")
191216
name := c.Param("name")
@@ -222,6 +247,7 @@ func (server *MultiTenantServer) getStorageObjectValuesRequestHandler(c *gin.Con
222247
}
223248
c.Data(200, "application/yaml", data)
224249
}
250+
225251
func (server *MultiTenantServer) getAllChartsRequestHandler(c *gin.Context) {
226252
repo := c.Param("repo")
227253
offset := 0
@@ -368,7 +394,8 @@ func (server *MultiTenantServer) postPackageRequestHandler(c *gin.Context) {
368394
chart, chartErr := cm_repo.ChartVersionFromStorageObject(cm_storage.Object{
369395
Path: pathutil.Join(repo, filename),
370396
Content: content,
371-
LastModified: time.Now()})
397+
LastModified: time.Now(),
398+
})
372399
if chartErr != nil {
373400
log(cm_logger.ErrorLevel, "cannot get chart from content", zap.Error(chartErr), zap.Binary("content", content))
374401
}
@@ -430,9 +457,10 @@ func (server *MultiTenantServer) postPackageAndProvenanceRequestHandler(c *gin.C
430457
if len(c.Errors) > 0 {
431458
return // this is a "request too large"
432459
}
433-
c.JSON(http.StatusBadRequest, gin.H{"error": fmt.Sprintf(
434-
"no package or provenance file found in form fields %s and %s",
435-
server.ChartPostFormFieldName, server.ProvPostFormFieldName),
460+
c.JSON(http.StatusBadRequest, gin.H{
461+
"error": fmt.Sprintf(
462+
"no package or provenance file found in form fields %s and %s",
463+
server.ChartPostFormFieldName, server.ProvPostFormFieldName),
436464
})
437465
return
438466
}
@@ -466,7 +494,8 @@ func (server *MultiTenantServer) postPackageAndProvenanceRequestHandler(c *gin.C
466494
chart, chartErr := cm_repo.ChartVersionFromStorageObject(cm_storage.Object{
467495
Path: path,
468496
Content: chartContent,
469-
LastModified: time.Now()})
497+
LastModified: time.Now(),
498+
})
470499
if chartErr != nil {
471500
log(cm_logger.ErrorLevel, "cannot get chart from content", zap.Error(err), zap.Binary("content", chartContent))
472501
}

pkg/chartmuseum/server/multitenant/routes.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package multitenant
1818

1919
import (
2020
cm_auth "github.com/chartmuseum/auth"
21-
2221
cm_router "helm.sh/chartmuseum/pkg/chartmuseum/router"
2322
)
2423

@@ -49,6 +48,7 @@ func (s *MultiTenantServer) Routes() []*cm_router.Route {
4948
{Method: "GET", Path: "/api/:repo/charts/:name/:version", Handler: s.getChartVersionRequestHandler, Action: cm_auth.PullAction},
5049
{Method: "GET", Path: "/api/:repo/charts/:name/:version/templates", Handler: s.getStorageObjectTemplateRequestHandler, Action: cm_auth.PullAction},
5150
{Method: "GET", Path: "/api/:repo/charts/:name/:version/values", Handler: s.getStorageObjectValuesRequestHandler, Action: cm_auth.PullAction},
51+
{Method: "GET", Path: "/api/:repo/charts/:name/:version/raw", Handler: s.getStorageObjectRawRequestHandler, Action: cm_auth.PullAction},
5252
{Method: "POST", Path: "/api/:repo/charts", Handler: s.postRequestHandler, Action: cm_auth.PushAction},
5353
{Method: "POST", Path: "/api/:repo/prov", Handler: s.postProvenanceFileRequestHandler, Action: cm_auth.PushAction},
5454
}

0 commit comments

Comments
 (0)