worker: Add identity filter and client oauth support
This commit is contained in:
parent
968e7b210f
commit
0ea31c39d5
11 changed files with 277 additions and 65 deletions
|
|
@ -34,16 +34,6 @@ type Server struct {
|
|||
|
||||
type contextKey int
|
||||
|
||||
const (
|
||||
identityHeaderKey contextKey = iota
|
||||
)
|
||||
|
||||
type IdentityHeader struct {
|
||||
Identity struct {
|
||||
AccountNumber string `json:"account_number"`
|
||||
} `json:"identity"`
|
||||
}
|
||||
|
||||
// NewServer creates a new cloud server
|
||||
func NewServer(workers *worker.Server, rpmMetadata rpmmd.RPMMD, distros *distroregistry.Registry) *Server {
|
||||
server := &Server{
|
||||
|
|
@ -72,6 +62,13 @@ func (server *Server) Handler(path string, identityFilter []string) http.Handler
|
|||
|
||||
func (server *Server) VerifyIdentityHeader(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
const identityHeaderKey contextKey = iota
|
||||
type identityHeader struct {
|
||||
Identity struct {
|
||||
AccountNumber string `json:"account_number"`
|
||||
} `json:"identity"`
|
||||
}
|
||||
|
||||
idHeaderB64 := r.Header["X-Rh-Identity"]
|
||||
if len(idHeaderB64) != 1 {
|
||||
http.Error(w, "Auth header is not present", http.StatusNotFound)
|
||||
|
|
@ -84,7 +81,7 @@ func (server *Server) VerifyIdentityHeader(next http.Handler) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
var idHeader IdentityHeader
|
||||
var idHeader identityHeader
|
||||
err = json.Unmarshal([]byte(strings.TrimSuffix(fmt.Sprintf("%s", b64Result), "\n")), &idHeader)
|
||||
if err != nil {
|
||||
http.Error(w, "Auth header has incorrect format", http.StatusNotFound)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue