Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Commit

Permalink
De-dup gob register
Browse files Browse the repository at this point in the history
  • Loading branch information
mipearson committed May 6, 2021
1 parent 457d523 commit d176318
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ func Enabled() bool {
return !viper.GetBool("cache.no_cache")
}

var initialisedGob = false

func gobInit() {
if initialisedGob {
return
}
initialisedGob = true
gob.Register(sts.AssumeRoleWithSAMLOutput{})
gob.Register(okta.OktaSession{})
}

func importCache(roleExpiryDuration time.Duration) error {
cacheFile, err := os.Open(viper.GetString("cache.file_location"))
defer cacheFile.Close()
Expand All @@ -40,14 +51,11 @@ func importCache(roleExpiryDuration time.Duration) error {
return err
}

gob.Register(sts.AssumeRoleWithSAMLOutput{})
gob.Register(okta.OktaSession{})
gobInit()
decoder := gob.NewDecoder(bufio.NewReader(cacheFile))
var items map[string]gocache.Item

err = decoder.Decode(&items)

if err != nil {
if err = decoder.Decode(&items); err != nil {
return err
}

Expand Down Expand Up @@ -99,12 +107,9 @@ func Export() error {
}

writer := bufio.NewWriter(cacheFile)
gob.Register(sts.AssumeRoleWithSAMLOutput{})
gob.Register(okta.OktaSession{})
gobInit()
enc := gob.NewEncoder(writer)
err = enc.Encode(cache().Items())

if err != nil {
if err = enc.Encode(cache().Items()); err != nil {
return err
}

Expand Down

0 comments on commit d176318

Please sign in to comment.