Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[v2] identity: add support for string boolean in users' enabled member #3396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion openstack/identity/v3/users/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package users

import (
"encoding/json"
"fmt"
"strconv"
"time"

"github.com/gophercloud/gophercloud/v2"
Expand All @@ -20,7 +22,7 @@ type User struct {
DomainID string `json:"domain_id"`

// Enabled is whether or not the user is enabled.
Enabled bool `json:"enabled"`
Enabled bool `json:"-"`

// Extra is a collection of miscellaneous key/values.
Extra map[string]any `json:"-"`
Expand All @@ -45,6 +47,7 @@ func (r *User) UnmarshalJSON(b []byte) error {
type tmp User
var s struct {
tmp
Enabled any `json:"enabled"`
Extra map[string]any `json:"extra"`
PasswordExpiresAt gophercloud.JSONRFC3339MilliNoZ `json:"password_expires_at"`
}
Expand All @@ -56,6 +59,20 @@ func (r *User) UnmarshalJSON(b []byte) error {

r.PasswordExpiresAt = time.Time(s.PasswordExpiresAt)

switch t := s.Enabled.(type) {
case nil:
r.Enabled = false
case bool:
r.Enabled = t
case string:
r.Enabled, err = strconv.ParseBool(t)
if err != nil {
return fmt.Errorf("Failed to parse Enabled %q: %v", t, err)
}
default:
return fmt.Errorf("Unknown type for Enabled: %T (value: %v)", t, t)
}

// Collect other fields and bundle them into Extra
// but only if a field titled "extra" wasn't sent.
if s.Extra != nil {
Expand Down
2 changes: 1 addition & 1 deletion openstack/identity/v3/users/testing/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const ListOutput = `
"users": [
{
"domain_id": "default",
"enabled": true,
"enabled": "True",
"id": "2844b2a08be147a08ef58317d6471f1f",
"links": {
"self": "http://example.com/identity/v3/users/2844b2a08be147a08ef58317d6471f1f"
Expand Down
Loading