mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-11 21:48:41 +00:00
feat(packages): add support for uploading helm provenance files (#36695)
Adds `POST helm/api/prov` endpoint for helm repository allowing for upload of provenance files. Tested manually to a degree but I really didn't want to mess with gpg again so I'm not sure if helm will correctly verify the chart. Initial draft made by gemini 3 flash but was finetuned somewhat. Additionally there's an route that allows for upload of both files via /api/charts - as separate files in form. If there's any interest in that I guess it can be added but I think helm is moving to OCI anyway which we support. Fixes: https://github.com/go-gitea/gitea/issues/36678 Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
@@ -60,8 +60,48 @@ dependencies:
|
||||
zw.Close()
|
||||
content := buf.Bytes()
|
||||
|
||||
// The signature is invalid, but the repository isn't verifying it.
|
||||
provContent := `-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA512
|
||||
|
||||
apiVersion: v2
|
||||
description: ` + packageDescription + `
|
||||
name: ` + packageName + `
|
||||
type: application
|
||||
version: ` + packageVersion + `
|
||||
maintainers:
|
||||
- - name: ` + packageAuthor + `
|
||||
dependencies:
|
||||
- - name: dep1
|
||||
repository: https://example.com/
|
||||
|
||||
...
|
||||
files:
|
||||
` + filename + `: sha256:d31d2f08b885ec696c37c7f7ef106709aaf5e8575b6d3dc5d52112ed29a9cb92
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
wsBcBAEBCgAQBQJdy0ReCRCEO7+YH8GHYgAAfhUIADx3pHHLLINv0MFkiEYpX/Kd
|
||||
nvHFBNps7hXqSocsg0a9Fi1LRAc3OpVh3knjPfHNGOy8+xOdhbqpdnB+5ty8YopI
|
||||
mYMWp6cP/Mwpkt7/gP1ecWFMevicbaFH5AmJCBihBaKJE4R1IX49/wTIaLKiWkv2
|
||||
cR64bmZruQPSW83UTNULtdD7kuTZXeAdTMjAK0NECsCz9/eK5AFggP4CDf7r2zNi
|
||||
hZsNrzloIlBZlGGns6mUOTO42J/+JojnOLIhI3Psd0HBD2bTlsm/rSfty4yZUs7D
|
||||
qtgooNdohoyGSzR5oapd7fEvauRQswJxOA0m0V+u9/eyLR0+JcYB8Udi1prnWf8=
|
||||
=aHfz
|
||||
-----END PGP SIGNATURE-----`
|
||||
|
||||
url := fmt.Sprintf("/api/packages/%s/helm", user.Name)
|
||||
|
||||
t.Run("UploadProvFileWithoutChart", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
provURL := url + "/api/prov"
|
||||
|
||||
// Attempt to upload provenance file without chart to back it.
|
||||
req := NewRequestWithBody(t, "POST", provURL, bytes.NewReader([]byte(provContent))).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusNotFound)
|
||||
})
|
||||
|
||||
t.Run("Upload", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
@@ -95,6 +135,37 @@ dependencies:
|
||||
req = NewRequestWithBody(t, "POST", uploadURL, bytes.NewReader(content)).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
provURL := url + "/api/prov"
|
||||
|
||||
// Upload Provenance file
|
||||
req = NewRequestWithBody(t, "POST", provURL, bytes.NewReader([]byte(provContent))).
|
||||
AddBasicAuth(user.Name)
|
||||
MakeRequest(t, req, http.StatusCreated)
|
||||
|
||||
pvs, err = packages.GetVersionsByPackageType(t.Context(), user.ID, packages.TypeHelm)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pvs, 1)
|
||||
|
||||
pfs, err = packages.GetFilesByVersionID(t.Context(), pvs[0].ID)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, pfs, 2)
|
||||
|
||||
var provFile *packages.PackageFile
|
||||
for _, pf := range pfs {
|
||||
if pf.Name == filename+".prov" {
|
||||
provFile = pf
|
||||
break
|
||||
}
|
||||
}
|
||||
assert.NotNil(t, provFile)
|
||||
assert.False(t, provFile.IsLead)
|
||||
|
||||
req = NewRequest(t, "GET", fmt.Sprintf("%s/%s.prov", url, filename)).
|
||||
AddBasicAuth(user.Name)
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
assert.Equal(t, provContent, resp.Body.String())
|
||||
})
|
||||
|
||||
t.Run("Download", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user