Skip to content

Commit

Permalink
Read from file
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenmj authored Sep 22, 2023
1 parent 7a89673 commit 439a809
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions pkg/jwt/configuration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package jwt

import (
"os"

"github.com/buildbarn/bb-storage/pkg/clock"
"github.com/buildbarn/bb-storage/pkg/eviction"
configuration "github.com/buildbarn/bb-storage/pkg/proto/configuration/jwt"
Expand All @@ -16,23 +18,25 @@ import (
// "Authorization" header parser based on options stored in a
// configuration file.
func NewAuthorizationHeaderParserFromConfiguration(config *configuration.AuthorizationHeaderParserConfiguration) (*AuthorizationHeaderParser, error) {
var keySet *configuration.JSONWebKeySet
var err error
var jwksJson []byte

switch key := config.Jwks.(type) {
case *configuration.AuthorizationHeaderParserConfiguration_JwksInline:
keySet = key.JwksInline
jwksJson, err = protojson.Marshal(key.JwksInline)
if err != nil {
return nil, util.StatusWrap(err, "Failed to parse inline JWKS")
}
case *configuration.AuthorizationHeaderParserConfiguration_JwksPath:
// FIXME: Implement reading this from a file
jwksJson, err = os.ReadFile(key.JwksPath)
if err != nil {
return nil, util.StatusWrap(err, "Failed to read JWKS file")
}
default:
return nil, status.Error(codes.InvalidArgument, "No key type provided")
}

messageJSON, err := protojson.Marshal(keySet)
if err != nil {
return nil, util.StatusWrap(err, "Failed to convert JWKS to JSON")
}

signatureValidator, err := NewJWKSSignatureValidator(messageJSON)
signatureValidator, err := NewJWKSSignatureValidator(jwksJson)

evictionSet, err := eviction.NewSetFromConfiguration[string](config.CacheReplacementPolicy)
if err != nil {
Expand Down

0 comments on commit 439a809

Please sign in to comment.