Skip to content

Commit

Permalink
fix(configuration): agnostic_parser handle basepath directive
Browse files Browse the repository at this point in the history
  • Loading branch information
darkweak committed Dec 21, 2022
1 parent fd86a57 commit 4b9406d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 29 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
run: make build-and-run-beego
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Beego as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -117,12 +117,12 @@ jobs:
run: make build-and-run-chi
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Chi as middleware
uses: jakejarvis/wait-action@master
with:
time: 40s
time: 50s
-
name: Set Chi logs configuration result as environment variable
run: cd plugins/chi && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down Expand Up @@ -165,12 +165,12 @@ jobs:
run: make build-and-run-dotweb
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Dotweb as middleware
uses: jakejarvis/wait-action@master
with:
time: 40s
time: 50s
-
name: Set Dotweb logs configuration result as environment variable
run: cd plugins/dotweb && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down Expand Up @@ -213,12 +213,12 @@ jobs:
run: make build-and-run-echo
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Echo as middleware
uses: jakejarvis/wait-action@master
with:
time: 45s
time: 50s
-
name: Set Echo logs configuration result as environment variable
run: cd plugins/echo && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down Expand Up @@ -261,7 +261,7 @@ jobs:
run: make build-and-run-fiber
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Fiber as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -309,7 +309,7 @@ jobs:
run: make build-and-run-gin
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Gin as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -357,7 +357,7 @@ jobs:
run: make build-and-run-go-zero
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Go-zero as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -405,7 +405,7 @@ jobs:
run: make build-and-run-goyave
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Goyave as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -453,7 +453,7 @@ jobs:
run: make build-and-run-kratos
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Kratos as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -501,12 +501,12 @@ jobs:
run: make build-and-run-roadrunner
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Roadrunner as middleware
uses: jakejarvis/wait-action@master
with:
time: 10s
time: 50s
-
name: Set Roadrunner logs configuration result as environment variable
run: cd plugins/roadrunner && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down Expand Up @@ -549,7 +549,7 @@ jobs:
run: make build-and-run-skipper
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Skipper as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -597,7 +597,7 @@ jobs:
run: make build-and-run-souin
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Souin as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -645,7 +645,7 @@ jobs:
run: make build-and-run-traefik
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Traefik as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -693,7 +693,7 @@ jobs:
run: make build-and-run-tyk
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Tyk as middleware
uses: jakejarvis/wait-action@master
Expand Down Expand Up @@ -741,12 +741,12 @@ jobs:
run: make build-and-run-webgo
env:
GH_APP_TOKEN: ${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: ${{ env.GITHUB_SHA }}
CURRENT_SHA: ${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside Webgo as middleware
uses: jakejarvis/wait-action@master
with:
time: 45s
time: 50s
-
name: Set Webgo logs configuration result as environment variable
run: cd plugins/webgo && echo "$(make load-checker)" >> $GITHUB_ENV
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workflow_plugins_generator.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

plugins=("beego" "chi" "dotweb" "echo" "fiber" "gin" "go-zero" "goyave" "kratos" "roadrunner" "skipper" "souin" "traefik" "tyk" "webgo")
durations=("50" "40" "40" "45" "50" "50" "50" "50" "50" "10" "65" "50" "20" "30" "45")
durations=("50" "50" "50" "50" "50" "50" "50" "50" "50" "50" "65" "50" "20" "30" "50")
versions=("19" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19" "19")

IFS= read -r -d '' tpl <<EOF
Expand Down Expand Up @@ -83,7 +83,7 @@ for i in ${!plugins[@]}; do
run: make build-and-run-$lower
env:
GH_APP_TOKEN: \${{ secrets.GH_APP_TOKEN }}
CURRENT_SHA: \${{ env.GITHUB_SHA }}
CURRENT_SHA: \${{ github.event.pull_request.head.sha }}
-
name: Wait for Souin is really loaded inside $capitalized as middleware
uses: jakejarvis/wait-action@master
Expand Down
4 changes: 3 additions & 1 deletion plugins/roadrunner/examples/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ ENV CGO_ENABLED=0
ENV VERSION=v2.10.7
ENV TIME="$(date +%H:%M)"

RUN apk add git

COPY . /opt
WORKDIR /opt/plugins/roadrunner
RUN go get -u "github.com/darkweak/souin@${CURRENT_SHA}"
WORKDIR /opt/plugins/roadrunner/examples
RUN sed -i "s/GH_TOKEN/${GH_TOKEN}/" configuration.toml

RUN apk add git
RUN vx build -c configuration.toml -o /usr/bin/

FROM composer:latest AS development-runner
COPY --from=velox /usr/bin/rr /usr/bin/rr

RUN apk add linux-headers
RUN docker-php-ext-install sockets
RUN composer require spiral/roadrunner nyholm/psr7

Expand Down
30 changes: 24 additions & 6 deletions plugins/souin/agnostic/configuration_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ func parseAPI(apiConfiguration map[string]interface{}) configurationtypes.API {

for apiK, apiV := range apiConfiguration {
switch apiK {
case "basepath":
a.BasePath = apiV.(string)
case "prometheus":
prometheusConfiguration, _ = apiV.(map[string]interface{})
case "souin":
Expand Down Expand Up @@ -59,8 +61,12 @@ func parseCacheKeys(ccConfiguration map[string]interface{}) map[configurationtyp
case "hide":
ck.Hide = true
case "headers":
for _, header := range cacheKeysConfigurationVMapV.([]interface{}) {
ck.Headers = append(ck.Headers, header.(string))
if headers, ok := cacheKeysConfigurationVMapV.([]string); ok {
ck.Headers = headers
} else {
for _, hv := range cacheKeysConfigurationVMapV.([]interface{}) {
ck.Headers = append(ck.Headers, hv.(string))
}
}
}
}
Expand Down Expand Up @@ -88,8 +94,12 @@ func parseDefaultCache(dcConfiguration map[string]interface{}) *configurationtyp
switch defaultCacheK {
case "allowed_http_verbs":
dc.AllowedHTTPVerbs = make([]string, 0)
for _, h := range defaultCacheV.([]interface{}) {
dc.AllowedHTTPVerbs = append(dc.AllowedHTTPVerbs, h.(string))
if verbs, ok := defaultCacheV.([]string); ok {
dc.AllowedHTTPVerbs = verbs
} else {
for _, verb := range defaultCacheV.([]interface{}) {
dc.AllowedHTTPVerbs = append(dc.AllowedHTTPVerbs, verb.(string))
}
}
case "badger":
provider := configurationtypes.CacheProvider{}
Expand Down Expand Up @@ -139,8 +149,16 @@ func parseDefaultCache(dcConfiguration map[string]interface{}) *configurationtyp
}
dc.Etcd = provider
case "headers":
for _, hv := range defaultCacheV.([]interface{}) {
dc.Headers = append(dc.Headers, hv.(string))
if headers, ok := defaultCacheV.([]string); ok {
dc.Headers = headers
} else {
if headers, ok := defaultCacheV.([]string); ok {
dc.Headers = headers
} else {
for _, hv := range defaultCacheV.([]interface{}) {
dc.Headers = append(dc.Headers, hv.(string))
}
}
}
case "nuts":
provider := configurationtypes.CacheProvider{}
Expand Down

0 comments on commit 4b9406d

Please sign in to comment.