Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4382 from hashicorp/b-scoped-config-sources-upgrade
Browse files Browse the repository at this point in the history
Scoped Config Sources Upgrade Fix
  • Loading branch information
paladin-devops authored Jan 13, 2023
2 parents e19fa4d + abb4ca5 commit 186d35f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .changelog/4382.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
```release-note:bug
upgrade: Fixes a bug where pre-v0.10.4 config sources could not be updated or
deleted.
```
28 changes: 25 additions & 3 deletions internal/server/boltdbstate/config_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package boltdbstate
import (
"context"
"encoding/binary"
"regexp"
"sort"
"strings"

Expand Down Expand Up @@ -299,15 +300,36 @@ func (s *State) configSourceIndexSet(txn *memdb.Txn, id []byte, value *pb.Config
// configSourceIndexInit initializes the config index from persisted data.
func (s *State) configSourceIndexInit(dbTxn *bolt.Tx, memTxn *memdb.Txn) error {
bucket := dbTxn.Bucket(configSourceBucket)

// Regex to match for the names of any config sourcer plugins v0.10.5 and earlier
re := regexp.MustCompile(`aws-ssm|consul|kubernetes|null|packer|terraform-cloud|vault`)

return bucket.ForEach(func(k, v []byte) error {
var value pb.ConfigSource
if err := proto.Unmarshal(v, &value); err != nil {
return err
}
if err := s.configSourceIndexSet(memTxn, k, &value); err != nil {
return err
}

// If there are any records whose ID is the name of a plugin, pre-v0.10.4
// behavior, then we delete that record from the database, since it is
// about to be saved with a hashed ID. This is not very elegant, but
// is the simplest way for users to upgrade since custom config sourcer
// plugins aren't yet supported, as of 1/10/2023.
key := string(k)
if re.MatchString(key) {
if err := bucket.Delete(k); err != nil {
return err
}
// configSourceSet will create a new record in Bolt DB, AND update
// Mem DB, with the ID value hashed as per the v0.10.4 hashing logic.
if err := s.configSourceSet(dbTxn, memTxn, &value); err != nil {
return err
}
} else {
if err := s.configSourceIndexSet(memTxn, k, &value); err != nil {
return err
}
}
return nil
})
}
Expand Down

0 comments on commit 186d35f

Please sign in to comment.