-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support package signatures * Adjust tests * Update CHANGELOG * WIP * WIP * Use signature_path * Fixes
- Loading branch information
Showing
10 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/Masterminds/semver/v3" | ||
"github.com/gorilla/mux" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/elastic/package-registry/packages" | ||
) | ||
|
||
const signaturesRouterPath = "/epr/{packageName}/{packageName:[a-z0-9_]+}-{packageVersion}.zip.sig" | ||
|
||
var errSignatureFileNotFound = errors.New("signature file not found") | ||
|
||
func signaturesHandler(indexer Indexer, cacheTime time.Duration) func(w http.ResponseWriter, r *http.Request) { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
vars := mux.Vars(r) | ||
packageName, ok := vars["packageName"] | ||
if !ok { | ||
badRequest(w, "missing package name") | ||
return | ||
} | ||
|
||
packageVersion, ok := vars["packageVersion"] | ||
if !ok { | ||
badRequest(w, "missing package version") | ||
return | ||
} | ||
|
||
_, err := semver.StrictNewVersion(packageVersion) | ||
if err != nil { | ||
badRequest(w, "invalid package version") | ||
return | ||
} | ||
|
||
opts := packages.NameVersionFilter(packageName, packageVersion) | ||
packageList, err := indexer.Get(r.Context(), &opts) | ||
if err != nil { | ||
log.Printf("getting package path failed: %v", err) | ||
http.Error(w, "internal server error", http.StatusInternalServerError) | ||
return | ||
} | ||
if len(packageList) == 0 { | ||
notFoundError(w, errSignatureFileNotFound) | ||
return | ||
} | ||
|
||
cacheHeaders(w, cacheTime) | ||
packages.ServeSignature(w, r, packageList[0]) | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
e16ddaf4f91df524b27bf4f2e4b1ac09 |
This file contains 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
signature file not found |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
e16ddaf4f91df524b27bf4f2e4b1ac09 |