chore(storage): remove servers.json in favor of just code at runtime

This commit is contained in:
Quentin McGaw
2026-05-24 22:00:34 +00:00
parent 39ac8b3432
commit ebbc630b31
5 changed files with 20 additions and 100 deletions
+8 -6
View File
@@ -44,7 +44,6 @@ jobs:
locale: "US" locale: "US"
level: error level: error
exclude: | exclude: |
./internal/storage/servers.json
./.golangci.yml ./.golangci.yml
*.md *.md
@@ -98,7 +97,7 @@ jobs:
github.event_name == 'release' || github.event_name == 'release' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
) )
needs: [ verify ] needs: [verify]
runs-on: ubuntu-latest runs-on: ubuntu-latest
environment: secrets environment: secrets
steps: steps:
@@ -120,7 +119,8 @@ jobs:
- name: Run Gluetun container with ProtonVPN Wireguard and port forwarding - name: Run Gluetun container with ProtonVPN Wireguard and port forwarding
configuration configuration
run: echo -e "${{ secrets.PROTONVPN_WIREGUARD_PRIVATE_KEY }}" | ./ci/runner run:
echo -e "${{ secrets.PROTONVPN_WIREGUARD_PRIVATE_KEY }}" | ./ci/runner
protonvpn-wireguard-port-forwarding protonvpn-wireguard-port-forwarding
- name: Run Gluetun container with ProtonVPN OpenVPN and port forwarding - name: Run Gluetun container with ProtonVPN OpenVPN and port forwarding
@@ -129,7 +129,8 @@ jobs:
secrets.PROTONVPN_OPENVPN_PASSWORD }}" | ./ci/runner secrets.PROTONVPN_OPENVPN_PASSWORD }}" | ./ci/runner
protonvpn-openvpn-port-forwarding protonvpn-openvpn-port-forwarding
- name: Run Gluetun container with Private Internet Access OpenVPN and port - name:
Run Gluetun container with Private Internet Access OpenVPN and port
forwarding configuration forwarding configuration
run: echo -e "${{ secrets.PRIVATEINTERNETACCESS_OPENVPN_USER }}\n${{ run: echo -e "${{ secrets.PRIVATEINTERNETACCESS_OPENVPN_USER }}\n${{
secrets.PRIVATEINTERNETACCESS_OPENVPN_PASSWORD }}" | ./ci/runner secrets.PRIVATEINTERNETACCESS_OPENVPN_PASSWORD }}" | ./ci/runner
@@ -141,7 +142,8 @@ jobs:
secrets.AIRVPN_WIREGUARD_ADDRESSES }}" | ./ci/runner airvpn-wireguard secrets.AIRVPN_WIREGUARD_ADDRESSES }}" | ./ci/runner airvpn-wireguard
- name: Run Gluetun container with AirVPN OpenVPN configuration - name: Run Gluetun container with AirVPN OpenVPN configuration
run: echo -e "${{ secrets.AIRVPN_OPENVPN_KEY }}\n${{ secrets.AIRVPN_OPENVPN_CERT run:
echo -e "${{ secrets.AIRVPN_OPENVPN_KEY }}\n${{ secrets.AIRVPN_OPENVPN_CERT
}}" | ./ci/runner airvpn-openvpn }}" | ./ci/runner airvpn-openvpn
codeql: codeql:
@@ -169,7 +171,7 @@ jobs:
github.event_name == 'release' || github.event_name == 'release' ||
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]')
) )
needs: [ verify, verify-private, codeql ] needs: [verify, verify-private, codeql]
permissions: permissions:
actions: read actions: read
contents: read contents: read
+10 -18
View File
@@ -1,32 +1,23 @@
package storage package storage
import ( import (
"embed"
"encoding/json" "encoding/json"
"fmt" "fmt"
"path" "path/filepath"
serversmodule "github.com/qdm12/gluetun-servers/pkg/servers" serversmodule "github.com/qdm12/gluetun-servers/pkg/servers"
"github.com/qdm12/gluetun/internal/constants/providers"
"github.com/qdm12/gluetun/internal/models" "github.com/qdm12/gluetun/internal/models"
) )
//go:embed servers.json
var allServersEmbedFS embed.FS
func parseHardcodedServers() (allServers models.AllServers) { func parseHardcodedServers() (allServers models.AllServers) {
f, err := allServersEmbedFS.Open("servers.json") allProviders := providers.All()
if err != nil {
panic(err)
}
defer f.Close() // no-op
decoder := json.NewDecoder(f)
err = decoder.Decode(&allServers)
if err != nil {
panic("decoding servers.json: " + err.Error())
}
for provider, metadata := range allServers.ProviderToServers { const version = 1
filename := path.Base(metadata.Filepath) allServers.ProviderToServers = make(map[string]models.Servers, len(allProviders))
allServers.Version = version
for _, provider := range allProviders {
filename := provider + ".json"
providerFile, err := serversmodule.Files.Open(filename) providerFile, err := serversmodule.Files.Open(filename)
if err != nil { if err != nil {
panic(fmt.Sprintf("reading embedded provider file %s for %s: %s", filename, provider, err)) panic(fmt.Sprintf("reading embedded provider file %s for %s: %s", filename, provider, err))
@@ -44,7 +35,8 @@ func parseHardcodedServers() (allServers models.AllServers) {
filename, provider)) filename, provider))
} }
providerServers.Filepath = metadata.Filepath // inherit filepath from servers.json const serversPath = "/gluetun/servers/"
providerServers.Filepath = filepath.Join(serversPath, filename)
allServers.ProviderToServers[provider] = providerServers allServers.ProviderToServers[provider] = providerServers
} }
+1 -2
View File
@@ -3,6 +3,5 @@ package storage
import "fmt" import "fmt"
func panicOnProviderMissingHardcoded(provider string) { func panicOnProviderMissingHardcoded(provider string) {
panic(fmt.Sprintf("provider %s not found in hardcoded servers map; "+ panic(fmt.Sprintf("provider %s not found in hardcoded servers map", provider))
"did you add the provider key in the embedded servers.json?", provider))
} }
+1 -2
View File
@@ -152,8 +152,7 @@ func Test_extractServersFromBytes(t *testing.T) {
allProviders[0]: 1, allProviders[0]: 1,
// Missing provider allProviders[1] // Missing provider allProviders[1]
} }
expectedPanicValue := fmt.Sprintf("provider %s not found in hardcoded servers map; "+ expectedPanicValue := fmt.Sprintf("provider %s not found in hardcoded servers map", allProviders[1])
"did you add the provider key in the embedded servers.json?", allProviders[1])
assert.PanicsWithValue(t, expectedPanicValue, func() { assert.PanicsWithValue(t, expectedPanicValue, func() {
_, _ = s.extractServersFromBytes(b, hardcodedVersions) _, _ = s.extractServersFromBytes(b, hardcodedVersions)
}) })
-72
View File
@@ -1,72 +0,0 @@
{
"version": 1,
"airvpn": {
"filepath": "/gluetun/servers/airvpn.json"
},
"cyberghost": {
"filepath": "/gluetun/servers/cyberghost.json"
},
"expressvpn": {
"filepath": "/gluetun/servers/expressvpn.json"
},
"fastestvpn": {
"filepath": "/gluetun/servers/fastestvpn.json"
},
"giganews": {
"filepath": "/gluetun/servers/giganews.json"
},
"hidemyass": {
"filepath": "/gluetun/servers/hidemyass.json"
},
"ipvanish": {
"filepath": "/gluetun/servers/ipvanish.json"
},
"ivpn": {
"filepath": "/gluetun/servers/ivpn.json"
},
"mullvad": {
"filepath": "/gluetun/servers/mullvad.json"
},
"nordvpn": {
"filepath": "/gluetun/servers/nordvpn.json"
},
"perfect privacy": {
"filepath": "/gluetun/servers/perfect privacy.json"
},
"privado": {
"filepath": "/gluetun/servers/privado.json"
},
"private internet access": {
"filepath": "/gluetun/servers/private internet access.json"
},
"privatevpn": {
"filepath": "/gluetun/servers/privatevpn.json"
},
"protonvpn": {
"filepath": "/gluetun/servers/protonvpn.json"
},
"purevpn": {
"filepath": "/gluetun/servers/purevpn.json"
},
"slickvpn": {
"filepath": "/gluetun/servers/slickvpn.json"
},
"surfshark": {
"filepath": "/gluetun/servers/surfshark.json"
},
"torguard": {
"filepath": "/gluetun/servers/torguard.json"
},
"vpn unlimited": {
"filepath": "/gluetun/servers/vpn unlimited.json"
},
"vpnsecure": {
"filepath": "/gluetun/servers/vpnsecure.json"
},
"vyprvpn": {
"filepath": "/gluetun/servers/vyprvpn.json"
},
"windscribe": {
"filepath": "/gluetun/servers/windscribe.json"
}
}