@@ -2,6 +2,8 @@ package users
22
33import (
44 "encoding/json"
5+ "fmt"
6+ "strconv"
57 "time"
68
79 "github.com/gophercloud/gophercloud/v2"
@@ -20,7 +22,7 @@ type User struct {
2022 DomainID string `json:"domain_id"`
2123
2224 // Enabled is whether or not the user is enabled.
23- Enabled bool `json:"enabled "`
25+ Enabled bool `json:"- "`
2426
2527 // Extra is a collection of miscellaneous key/values.
2628 Extra map [string ]any `json:"-"`
@@ -45,6 +47,7 @@ func (r *User) UnmarshalJSON(b []byte) error {
4547 type tmp User
4648 var s struct {
4749 tmp
50+ Enabled any `json:"enabled"`
4851 Extra map [string ]any `json:"extra"`
4952 PasswordExpiresAt gophercloud.JSONRFC3339MilliNoZ `json:"password_expires_at"`
5053 }
@@ -56,6 +59,20 @@ func (r *User) UnmarshalJSON(b []byte) error {
5659
5760 r .PasswordExpiresAt = time .Time (s .PasswordExpiresAt )
5861
62+ switch t := s .Enabled .(type ) {
63+ case nil :
64+ r .Enabled = false
65+ case bool :
66+ r .Enabled = t
67+ case string :
68+ r .Enabled , err = strconv .ParseBool (t )
69+ if err != nil {
70+ return fmt .Errorf ("Failed to parse Enabled %q: %v" , t , err )
71+ }
72+ default :
73+ return fmt .Errorf ("Unknown type for Enabled: %T (value: %v)" , t , t )
74+ }
75+
5976 // Collect other fields and bundle them into Extra
6077 // but only if a field titled "extra" wasn't sent.
6178 if s .Extra != nil {
0 commit comments