This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Organization.Users which should have been Members add Member, MembersService, MemberServiceOp Signed-off-by: Marques Johansson <mjohansson@equinix.com>
- Loading branch information
Showing
3 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package packngo | ||
|
||
import "path" | ||
|
||
// API documentation https://metal.equinix.com/developers/api#tag/Memberships | ||
const membersBasePath = "/members" | ||
|
||
// OrganizationService interface defines available organization methods | ||
type MemberService interface { | ||
List(string, *ListOptions) ([]Member, *Response, error) | ||
Delete(string, string) (*Response, error) | ||
} | ||
|
||
type membersRoot struct { | ||
Members []Member `json:"members"` | ||
Meta meta `json:"meta"` | ||
} | ||
|
||
// Member is the returned from organization/id/members | ||
type Member struct { | ||
*Href `json:",inline"` | ||
ID string `json:"id"` | ||
Roles []string `json:"roles"` | ||
ProjectsCount int `json:"projects_count"` | ||
User User `json:"user"` | ||
Organization Organization `json:"organization"` | ||
Projects []Project `json:"projects"` | ||
} | ||
|
||
// MemberServiceOp implements MemberService | ||
type MemberServiceOp struct { | ||
client *Client | ||
} | ||
|
||
var _ MemberService = (*MemberServiceOp)(nil) | ||
|
||
// List returns the members in an organization | ||
func (s *MemberServiceOp) List(organizationID string, opts *ListOptions) (orgs []Member, resp *Response, err error) { | ||
subset := new(membersRoot) | ||
endpointPath := path.Join(organizationBasePath, organizationID, membersBasePath) | ||
apiPathQuery := opts.WithQuery(endpointPath) | ||
|
||
for { | ||
resp, err = s.client.DoRequest("GET", apiPathQuery, nil, subset) | ||
if err != nil { | ||
return nil, resp, err | ||
} | ||
|
||
orgs = append(orgs, subset.Members...) | ||
|
||
if apiPathQuery = nextPage(subset.Meta, opts); apiPathQuery != "" { | ||
continue | ||
} | ||
return | ||
} | ||
} | ||
|
||
// Delete removes the given member from the given organization | ||
func (s *MemberServiceOp) Delete(organizationID, memberID string) (*Response, error) { | ||
if validateErr := ValidateUUID(organizationID); validateErr != nil { | ||
return nil, validateErr | ||
} | ||
apiPath := path.Join(organizationBasePath, organizationID, membersBasePath, memberID) | ||
|
||
return s.client.DoRequest("DELETE", apiPath, nil, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters