Skip to content

Commit

Permalink
Convert the inline PEM into the expected bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidtw committed Mar 8, 2024
1 parent bf3bded commit f03d457
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions cmd/xmidt-agent/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
package main

import (
"encoding/pem"
"os"
"strings"

"github.com/xmidt-org/xmidt-agent/internal/jwtxt"
"github.com/xmidt-org/xmidt-agent/internal/jwtxt/event"
Expand Down Expand Up @@ -55,8 +57,19 @@ func provideInstructions(in instructionsIn) (*jwtxt.Instructions, error) {

if len(in.Service.JwtTxtRedirector.PEMs) > 0 {
pems := make([][]byte, 0, len(in.Service.JwtTxtRedirector.PEMs))
for _, pem := range in.Service.JwtTxtRedirector.PEMs {
pems = append(pems, []byte(pem))
for _, item := range in.Service.JwtTxtRedirector.PEMs {
block, rest := pem.Decode([]byte(item))

if block == nil || strings.TrimSpace(string(rest)) != "" {
return nil, jwtxt.ErrInvalidInput
}

buf := pem.EncodeToMemory(block)
if buf == nil {
return nil, jwtxt.ErrInvalidInput
}

pems = append(pems, buf)
}
opts = append(opts, jwtxt.WithPEMs(pems...))
}
Expand Down

0 comments on commit f03d457

Please sign in to comment.