Skip to content

Commit fb44d54

Browse files
authored
Recover safely from users without slackUID (#63)
* if slackuid doesn't exist, notify * add logrus Fields
1 parent 04b6459 commit fb44d54

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

users.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,15 @@ func (client *OIDCClient) GetUserInfo(user *OIDCUser) {
133133
return
134134
}
135135
if len(arg) > 0 {
136-
userData := make([]map[string]interface{}, 0)
136+
userData := make([]map[string]any, 0)
137137
err = json.Unmarshal(b, &userData)
138138
// userdata attributes are a KV pair of string:[]any, this casts attributes, finds the specific attribute, casts it to a list of any, and then pulls the first field since there will only ever be one
139-
user.SlackUID = userData[0]["attributes"].(map[string]interface{})["slackuid"].([]interface{})[0].(string)
139+
userAttributes := userData[0]["attributes"].(map[string]any)
140+
if slackIDRaw, exists := userAttributes["slackuid"]; exists {
141+
user.SlackUID = slackIDRaw.([]any)[0].(string)
142+
} else {
143+
logging.Logger.WithFields(logrus.Fields{"method": "GetUserInfo"}).Error("User " + user.Username + " does not have a SlackUID. Skipping messaging.")
144+
}
140145
} else {
141146
err = json.Unmarshal(b, &user)
142147
}

0 commit comments

Comments
 (0)