Skip to content

Commit 29cef1e

Browse files
committed
feat: allow HEAD on :repo/charts/:filename endpoint
Signed-off-by: Dmytro Bainak <154363928+dmytroba-salt@users.noreply.github.com>
1 parent 8795e99 commit 29cef1e

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Powered by some great Go technology:
2828
- `GET /index.yaml` - retrieved when you run `helm repo add chartmuseum http://localhost:8080/`
2929
- `GET /charts/mychart-0.1.0.tgz` - retrieved when you run `helm install chartmuseum/mychart`
3030
- `GET /charts/mychart-0.1.0.tgz.prov` - retrieved when you run `helm install` with the `--verify` flag
31+
- `HEAD` requests for the above routes are also supported; they are **not** used in `helm`,
32+
but they might be used by hubs like JFrog Artifactory
3133

3234
### Chart Manipulation
3335
- `POST /api/charts` - upload a new chart version

pkg/chartmuseum/server/multitenant/handlers.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,31 @@ func (server *MultiTenantServer) getArtifactHubFileRequestHandler(c *gin.Context
146146
c.Data(200, artifactHubFileContentType, artifactHubFile)
147147
}
148148

149-
func (server *MultiTenantServer) getStorageObjectRequestHandler(c *gin.Context) {
149+
func (server *MultiTenantServer) getStorageObjectRequestImpl(c *gin.Context) (*StorageObject, *HTTPError) {
150150
repo := c.Param("repo")
151151
filename := c.Param("filename")
152152
log := server.Logger.ContextLoggingFn(c)
153-
storageObject, err := server.getStorageObject(log, repo, filename)
153+
return server.getStorageObject(log, repo, filename)
154+
}
155+
156+
func (server *MultiTenantServer) getStorageObjectRequestHandler(c *gin.Context) {
157+
storageObject, err := server.getStorageObjectRequestImpl(c)
154158
if err != nil {
155159
c.JSON(err.Status, gin.H{"error": err.Message})
156160
return
157161
}
158162
c.Data(200, storageObject.ContentType, storageObject.Content)
159163
}
164+
165+
func (server *MultiTenantServer) headStorageObjectRequestHandler(c *gin.Context) {
166+
_, err := server.getStorageObjectRequestImpl(c)
167+
if err != nil {
168+
c.Status(err.Status)
169+
return
170+
}
171+
c.Status(200)
172+
}
173+
160174
func (server *MultiTenantServer) getStorageObjectTemplateRequestHandler(c *gin.Context) {
161175
repo := c.Param("repo")
162176
name := c.Param("name")

pkg/chartmuseum/server/multitenant/routes.go

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (s *MultiTenantServer) Routes() []*cm_router.Route {
3939
{Method: "GET", Path: "/:repo/index.yaml", Handler: s.getIndexFileRequestHandler, Action: cm_auth.PullAction},
4040
{Method: "HEAD", Path: "/:repo/index.yaml", Handler: s.headIndexFileRequestHandler, Action: cm_auth.PullAction},
4141
{Method: "GET", Path: "/:repo/charts/:filename", Handler: s.getStorageObjectRequestHandler, Action: cm_auth.PullAction},
42+
{Method: "HEAD", Path: "/:repo/charts/:filename", Handler: s.headStorageObjectRequestHandler, Action: cm_auth.PullAction},
4243
}
4344

4445
chartManipulationRoutes := []*cm_router.Route{

pkg/chartmuseum/server/multitenant/server_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,13 @@ func (suite *MultiTenantServerTestSuite) testAllRoutes(repo string, depth int) {
11081108
res = suite.doRequest(stype, "GET", fmt.Sprintf("%s/charts/fakechart-0.1.0.bad", repoPrefix), nil, "")
11091109
suite.Equal(500, res.Status(), fmt.Sprintf("500 GET %s/charts/fakechart-0.1.0.bad", repoPrefix))
11101110

1111+
// HEAD /:repo/charts/:filename
1112+
res = suite.doRequest(stype, "HEAD", fmt.Sprintf("%s/charts/mychart-0.1.0.tgz", repoPrefix), nil, "")
1113+
suite.Equal(200, res.Status(), fmt.Sprintf("200 GET %s/charts/mychart-0.1.0.tgz", repoPrefix))
1114+
1115+
res = suite.doRequest(stype, "HEAD", fmt.Sprintf("%s/charts/fakechart-0.1.0.bad", repoPrefix), nil, "")
1116+
suite.Equal(500, res.Status(), fmt.Sprintf("500 GET %s/charts/fakechart-0.1.0.bad", repoPrefix))
1117+
11111118
apiPrefix := pathutil.Join("/api", repo)
11121119

11131120
// GET /api/:repo/charts

0 commit comments

Comments
 (0)