Skip to content

Commit 47e9171

Browse files
committed
- remove annotations from LocalIdentity, not needed
- add locking where needed in the local membership struct Signed-off-by: Angelo De Caro <[email protected]>
1 parent b566afe commit 47e9171

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

token/services/identity/common/identity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type GetIdentityFunc func(auditInfo []byte) (driver.Identity, []byte, error)
1313

1414
// LocalIdentity contains information about an identity
1515
type LocalIdentity struct {
16-
Name string `yaml:"name,omitempty"`
16+
Name string
1717
EnrollmentID string
1818
Default bool
1919
GetIdentity GetIdentityFunc

token/services/identity/common/lm.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,10 @@ func (l *LocalMembership) GetIdentifier(id driver.Identity) (string, error) {
109109
}
110110

111111
func (l *LocalMembership) GetDefaultIdentifier() string {
112-
for _, identity := range l.localIdentities {
113-
if identity.Default {
114-
return identity.Name
115-
}
116-
}
117-
return ""
112+
l.localIdentitiesMutex.RLock()
113+
defer l.localIdentitiesMutex.RUnlock()
114+
115+
return l.getDefaultIdentifier()
118116
}
119117

120118
func (l *LocalMembership) GetIdentityInfo(label string, auditInfo []byte) (driver.IdentityInfo, error) {
@@ -137,10 +135,13 @@ func (l *LocalMembership) RegisterIdentity(idConfig driver.IdentityConfiguration
137135
l.localIdentitiesMutex.Lock()
138136
defer l.localIdentitiesMutex.Unlock()
139137

140-
return l.registerIdentityConfiguration(&idConfig, l.GetDefaultIdentifier() == "")
138+
return l.registerIdentityConfiguration(&idConfig, l.getDefaultIdentifier() == "")
141139
}
142140

143141
func (l *LocalMembership) IDs() ([]string, error) {
142+
l.localIdentitiesMutex.RLock()
143+
defer l.localIdentitiesMutex.RUnlock()
144+
144145
var ids []string
145146
for _, identity := range l.localIdentities {
146147
ids = append(ids, identity.Name)
@@ -176,7 +177,7 @@ func (l *LocalMembership) Load(identities []*config.Identity) error {
176177
l.logger.Debugf("load identities from storage...done")
177178

178179
// if no default identity, use the first one
179-
defaultIdentifier := l.GetDefaultIdentifier()
180+
defaultIdentifier := l.getDefaultIdentifier()
180181
if len(defaultIdentifier) == 0 {
181182
l.logger.Warnf("no default identity, use the first one available")
182183
if len(l.localIdentities) > 0 {
@@ -192,6 +193,15 @@ func (l *LocalMembership) Load(identities []*config.Identity) error {
192193
return nil
193194
}
194195

196+
func (l *LocalMembership) getDefaultIdentifier() string {
197+
for _, identity := range l.localIdentities {
198+
if identity.Default {
199+
return identity.Name
200+
}
201+
}
202+
return ""
203+
}
204+
195205
func (l *LocalMembership) registerIdentity(identity config.Identity) error {
196206
// marshal opts
197207
optsRaw, err := yaml.Marshal(identity.Opts)
@@ -362,7 +372,7 @@ func (l *LocalMembership) loadFromStorage() error {
362372
URL: entry.URL,
363373
Config: entry.Config,
364374
Raw: entry.Raw,
365-
}, l.GetDefaultIdentifier() == ""); err != nil {
375+
}, l.getDefaultIdentifier() == ""); err != nil {
366376
return err
367377
}
368378
}

0 commit comments

Comments
 (0)