diff --git a/CHANGELOG.md b/CHANGELOG.md index fd88808e..fdb2b036 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## To Be Released * fix(addons): parse `maintenance-window-hour` as an int +* feat(session): remove region cache on logout ## 1.44.1 diff --git a/config/region.go b/config/region.go index 992ead3b..35fd7089 100644 --- a/config/region.go +++ b/config/region.go @@ -137,3 +137,12 @@ func GetRegion(ctx context.Context, c Config, name string, opts GetRegionOpts) ( } return scalingo.Region{}, UnknownRegionError{regionName: name} } + +func DeleteRegionsCache(ctx context.Context, c Config) error { + err := os.Remove(c.RegionsCachePath) + if err != nil && !os.IsNotExist(err) { + return errors.Wrapf(ctx, err, "remove region cache %s", c.RegionsCachePath) + } + + return nil +} diff --git a/session/destroy.go b/session/destroy.go index 1a2249dd..14570265 100644 --- a/session/destroy.go +++ b/session/destroy.go @@ -13,5 +13,15 @@ func DestroyToken(ctx context.Context) error { if err != nil { return errors.Wrap(ctx, err, "remove local authentication credentials") } + + // We want to delete the regions cache so that the cache is created again during the next login. + // This is important for people with two different Scalingo accounts, one with and one without access to the osc-secnum-fr1 region. + // If we don't, there is a risk that when the client login with the osc-secnum-fr1 account, the regions cache does not contain the osc-secnum-fr1 region and client cannot contact this region. + // Ref. https://github.com/Scalingo/cli/issues/1057 + err = config.DeleteRegionsCache(ctx, config.C) + if err != nil { + return errors.Wrap(ctx, err, "remove local regions cache") + } + return nil }