@@ -2,6 +2,8 @@ package users
2
2
3
3
import (
4
4
"encoding/json"
5
+ "fmt"
6
+ "strconv"
5
7
"time"
6
8
7
9
"github.com/gophercloud/gophercloud/v2"
@@ -20,7 +22,7 @@ type User struct {
20
22
DomainID string `json:"domain_id"`
21
23
22
24
// Enabled is whether or not the user is enabled.
23
- Enabled bool `json:"enabled "`
25
+ Enabled bool `json:"- "`
24
26
25
27
// Extra is a collection of miscellaneous key/values.
26
28
Extra map [string ]any `json:"-"`
@@ -45,6 +47,7 @@ func (r *User) UnmarshalJSON(b []byte) error {
45
47
type tmp User
46
48
var s struct {
47
49
tmp
50
+ Enabled any `json:"enabled"`
48
51
Extra map [string ]any `json:"extra"`
49
52
PasswordExpiresAt gophercloud.JSONRFC3339MilliNoZ `json:"password_expires_at"`
50
53
}
@@ -56,6 +59,20 @@ func (r *User) UnmarshalJSON(b []byte) error {
56
59
57
60
r .PasswordExpiresAt = time .Time (s .PasswordExpiresAt )
58
61
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
+
59
76
// Collect other fields and bundle them into Extra
60
77
// but only if a field titled "extra" wasn't sent.
61
78
if s .Extra != nil {
0 commit comments