Skip to content

Commit 06b86f1

Browse files
committed
feat: add function to replace JWKS files in Nginx configuration
1 parent 05d9b50 commit 06b86f1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

e2e/nginx/replace.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package replace_test
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"regexp"
8+
"strings"
9+
)
10+
11+
func ReplaceNginxConfig(pathFile string, newPaths []string) (file []byte, err error) {
12+
content, err := os.ReadFile(pathFile)
13+
if err != nil {
14+
return nil, err
15+
}
16+
config := string(content)
17+
re := regexp.MustCompile(`\["jwks_files"\]\s*=\s*\{[^}]*\}`)
18+
newValue := fmt.Sprintf(`["jwks_files"] = {%s}`, strings.Join(newPaths, `, `))
19+
modifiedConfig := re.ReplaceAllString(config, newValue)
20+
return []byte(modifiedConfig), nil
21+
}

0 commit comments

Comments
 (0)