diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-11-10 10:00:46 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-11-10 10:02:32 +0100 |
| commit | 6df9ea2134103d02ecbe73e945b5df5fb7b131a1 (patch) | |
| tree | dc6fb435d049fa273b344baae4f0394ad95c317e /internal/server/common.go | |
| parent | f87b8d988f25c112f457baa24609a44ba85d4f34 (diff) | |
Server: Re-initialize endpoints when getting a config
Diffstat (limited to 'internal/server/common.go')
| -rw-r--r-- | internal/server/common.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/internal/server/common.go b/internal/server/common.go index 443a925..1b745cb 100644 --- a/internal/server/common.go +++ b/internal/server/common.go @@ -328,6 +328,16 @@ func getCurrentProfile(server Server) (*ServerProfile, error) { ) } +func (base *ServerBase) InitializeEndpoints() error { + errorMessage := "failed initializing endpoints" + endpoints, endpointsErr := APIGetEndpoints(base.URL) + if endpointsErr != nil { + return types.NewWrappedError(errorMessage, endpointsErr) + } + base.Endpoints = *endpoints + return nil +} + func (base *ServerBase) GetValidProfiles(clientSupportsWireguard bool) ServerProfileInfo { var validProfiles []ServerProfile for _, profile := range base.Profiles.Info.ProfileList { @@ -466,6 +476,18 @@ func HasValidProfile(server Server, clientSupportsWireguard bool) (bool, error) func GetConfig(server Server, clientSupportsWireguard bool, preferTCP bool) (string, string, error) { errorMessage := "failed getting an OpenVPN/WireGuard configuration" + // Re-initialize the endpoints + // TODO: Make this a warning instead? + base, baseErr := server.GetBase() + if baseErr != nil { + return "", "", types.NewWrappedError(errorMessage, baseErr) + } + + endpointsErr := base.InitializeEndpoints() + if endpointsErr != nil { + return "", "", types.NewWrappedError(errorMessage, endpointsErr) + } + profile, profileErr := getCurrentProfile(server) if profileErr != nil { return "", "", types.NewWrappedError(errorMessage, profileErr) |
