From 3be9c620fc7e9d7616124b5bcdaafa3d509ae1ff Mon Sep 17 00:00:00 2001 From: jwijenbergh Date: Thu, 7 Mar 2024 14:52:17 +0100 Subject: Client + Server: Add a way to obtain the cached profiles list --- internal/server/server.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'internal/server/server.go') diff --git a/internal/server/server.go b/internal/server/server.go index d622aef..97a25b4 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -35,10 +35,19 @@ func (s *Servers) NewServer(identifier string, t srvtypes.Type, api *api.API) Se } } -// Profiles gets the profiles for the server +// Profiles gets the cached profiles from the configuration/state file +func (s *Server) Profiles() (*srvtypes.Profiles, error) { + cfgs, err := s.cfgServer() + if err != nil { + return nil, err + } + return &cfgs.Profiles, nil +} + +// FreshProfiles gets the profiles for the server // It only does a /info network request if the profiles have not been cached // force indicates whether or not the profiles should be fetched fresh -func (s *Server) Profiles(ctx context.Context) (*profiles.Info, error) { +func (s *Server) FreshProfiles(ctx context.Context) (*profiles.Info, error) { a, err := s.api() if err != nil { return nil, err @@ -48,6 +57,7 @@ func (s *Server) Profiles(ctx context.Context) (*profiles.Info, error) { if err != nil { return nil, err } + // Update the profile list in the config err = s.SetProfileList(prfs.Public()) if err != nil { return nil, err @@ -64,7 +74,7 @@ func (s *Server) api() (*api.API, error) { func (s *Server) findProfile(ctx context.Context, wgSupport bool) (*profiles.Profile, error) { // Get the profiles by ignoring the cache - prfs, err := s.Profiles(ctx) + prfs, err := s.FreshProfiles(ctx) if err != nil { return nil, err } -- cgit v1.2.3