Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.
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
3 changes: 1 addition & 2 deletions openstack/identity/v3/groups/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ type CreateOpts struct {
// DomainID is the ID of the domain the group belongs to.
DomainID string `json:"domain_id,omitempty"`

// Extra is free-form extra key/value pairs to describe the group.
Extra map[string]interface{} `json:"-"`
}

Expand Down Expand Up @@ -94,7 +93,7 @@ func Create(client *golangsdk.ServiceClient, opts CreateOptsBuilder) (r CreateRe
return
}
_, r.Err = client.Post(createURL(client), &b, &r.Body, &golangsdk.RequestOpts{
OkCodes: []int{201},
OkCodes: []int{200},
})
return
}
Expand Down
2 changes: 1 addition & 1 deletion openstack/identity/v3/groups/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func HandleCreateGroupSuccessfully(t *testing.T) {
th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
th.TestJSONRequest(t, r, CreateRequest)

w.WriteHeader(http.StatusCreated)
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, GetOutput)
})
}
Expand Down
25 changes: 0 additions & 25 deletions openstack/identity/v3/projects/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ type ListOpts struct {
// DomainID filters the response by a domain ID.
DomainID string `q:"domain_id"`

// Enabled filters the response by enabled projects.
Enabled *bool `q:"enabled"`

// IsDomain filters the response by projects that are domains.
// Setting this to true is effectively listing domains.
IsDomain *bool `q:"is_domain"`

// Name filters the response by project name.
Name string `q:"name"`

Expand Down Expand Up @@ -68,12 +61,6 @@ type CreateOpts struct {
// DomainID is the ID this project will belong under.
DomainID string `json:"domain_id,omitempty"`

// Enabled sets the project status to enabled or disabled.
Enabled *bool `json:"enabled,omitempty"`

// IsDomain indicates if this project is a domain.
IsDomain *bool `json:"is_domain,omitempty"`

// Name is the name of the project.
Name string `json:"name" required:"true"`

Expand Down Expand Up @@ -114,21 +101,9 @@ type UpdateOptsBuilder interface {

// UpdateOpts represents parameters to update a project.
type UpdateOpts struct {
// DomainID is the ID this project will belong under.
DomainID string `json:"domain_id,omitempty"`

// Enabled sets the project status to enabled or disabled.
Enabled *bool `json:"enabled,omitempty"`

// IsDomain indicates if this project is a domain.
IsDomain *bool `json:"is_domain,omitempty"`

// Name is the name of the project.
Name string `json:"name,omitempty"`

// ParentID specifies the parent project of this new project.
ParentID string `json:"parent_id,omitempty"`

// Description is the description of the project.
Description string `json:"description,omitempty"`
}
Expand Down
60 changes: 14 additions & 46 deletions openstack/identity/v3/users/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,8 @@ type ListOpts struct {
// Enabled filters the response by enabled users.
Enabled *bool `q:"enabled"`

// IdpID filters the response by an Identity Provider ID.
IdPID string `q:"idp_id"`

// Name filters the response by username.
Name string `q:"name"`

// PasswordExpiresAt filters the response based on expiring passwords.
PasswordExpiresAt string `q:"password_expires_at"`

// ProtocolID filters the response by protocol ID.
ProtocolID string `q:"protocol_id"`

// UniqueID filters the response by unique ID.
UniqueID string `q:"unique_id"`
}

// ToUserListQuery formats a ListOpts into a query string.
Expand Down Expand Up @@ -90,21 +78,12 @@ type CreateOpts struct {
// DefaultProjectID is the ID of the default project of the user.
DefaultProjectID string `json:"default_project_id,omitempty"`

// Description is a description of the user.
Description string `json:"description,omitempty"`

// DomainID is the ID of the domain the user belongs to.
DomainID string `json:"domain_id,omitempty"`

// Enabled sets the user status to enabled or disabled.
Enabled *bool `json:"enabled,omitempty"`

// Extra is free-form extra key/value pairs to describe the user.
Extra map[string]interface{} `json:"-"`

// Options are defined options in the API to enable certain features.
Options map[Option]interface{} `json:"options,omitempty"`

// Password is the password of the new user.
Password string `json:"password,omitempty"`
}
Expand All @@ -116,14 +95,6 @@ func (opts CreateOpts) ToUserCreateMap() (map[string]interface{}, error) {
return nil, err
}

if opts.Extra != nil {
if v, ok := b["user"].(map[string]interface{}); ok {
for key, value := range opts.Extra {
v[key] = value
}
}
}

return b, nil
}

Expand Down Expand Up @@ -154,21 +125,12 @@ type UpdateOpts struct {
// DefaultProjectID is the ID of the default project of the user.
DefaultProjectID string `json:"default_project_id,omitempty"`

// Description is a description of the user.
Description string `json:"description,omitempty"`

// DomainID is the ID of the domain the user belongs to.
DomainID string `json:"domain_id,omitempty"`

// Enabled sets the user status to enabled or disabled.
Enabled *bool `json:"enabled,omitempty"`

// Extra is free-form extra key/value pairs to describe the user.
Extra map[string]interface{} `json:"-"`

// Options are defined options in the API to enable certain features.
Options map[Option]interface{} `json:"options,omitempty"`

// Password is the password of the new user.
Password string `json:"password,omitempty"`
}
Expand All @@ -180,14 +142,6 @@ func (opts UpdateOpts) ToUserUpdateMap() (map[string]interface{}, error) {
return nil, err
}

if opts.Extra != nil {
if v, ok := b["user"].(map[string]interface{}); ok {
for key, value := range opts.Extra {
v[key] = value
}
}
}

return b, nil
}

Expand Down Expand Up @@ -240,3 +194,17 @@ func ListInGroup(client *golangsdk.ServiceClient, groupID string, opts ListOptsB
return UserPage{pagination.LinkedPageBase{PageResult: r}}
})
}

// Add a user into one group
func AddToGroup(client *golangsdk.ServiceClient, groupID string, userID string) (r AddMembershipResult) {
_, r.Err = client.Put(membershipURL(client, groupID, userID), nil, nil, &golangsdk.RequestOpts{
OkCodes: []int{204},
})
return
}

// Remove user from group
func RemoveFromGroup(client *golangsdk.ServiceClient, groupID string, userID string) (r DeleteResult) {
_, r.Err = client.Delete(membershipURL(client, groupID, userID), nil)
return
}
31 changes: 4 additions & 27 deletions openstack/identity/v3/users/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/internal"
"github.com/huaweicloud/golangsdk/pagination"
)

Expand All @@ -14,18 +13,12 @@ type User struct {
// DefaultProjectID is the ID of the default project of the user.
DefaultProjectID string `json:"default_project_id"`

// Description is the description of the user.
Description string `json:"description"`

// DomainID is the domain ID the user belongs to.
DomainID string `json:"domain_id"`

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

// Extra is a collection of miscellaneous key/values.
Extra map[string]interface{} `json:"-"`

// ID is the unique ID of the user.
ID string `json:"id"`

Expand All @@ -35,9 +28,6 @@ type User struct {
// Name is the name of the user.
Name string `json:"name"`

// Options are a set of defined options of the user.
Options map[string]interface{} `json:"options"`

// PasswordExpiresAt is the timestamp when the user's password expires.
PasswordExpiresAt time.Time `json:"-"`
}
Expand All @@ -46,7 +36,6 @@ func (r *User) UnmarshalJSON(b []byte) error {
type tmp User
var s struct {
tmp
Extra map[string]interface{} `json:"extra"`
PasswordExpiresAt golangsdk.JSONRFC3339MilliNoZ `json:"password_expires_at"`
}
err := json.Unmarshal(b, &s)
Expand All @@ -57,22 +46,6 @@ func (r *User) UnmarshalJSON(b []byte) error {

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

// Collect other fields and bundle them into Extra
// but only if a field titled "extra" wasn't sent.
if s.Extra != nil {
r.Extra = s.Extra
} else {
var result interface{}
err := json.Unmarshal(b, &result)
if err != nil {
return err
}
if resultMap, ok := result.(map[string]interface{}); ok {
delete(resultMap, "password_expires_at")
r.Extra = internal.RemainingKeys(User{}, resultMap)
}
}

return err
}

Expand Down Expand Up @@ -147,3 +120,7 @@ func (r userResult) Extract() (*User, error) {
err := r.ExtractInto(&s)
return s.User, err
}

type AddMembershipResult struct {
golangsdk.ErrResult
}
Loading