-
Notifications
You must be signed in to change notification settings - Fork 103
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
Filter teams by name, org members by email #393
Changes from 4 commits
065461b
ea83e1f
72b43bc
bb26a1e
1f33aab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -77,6 +77,9 @@ type OrganizationMembershipListOptions struct { | |||||
// Optional: A list of relations to include. See available resources | ||||||
// https://www.terraform.io/cloud-docs/api-docs/organization-memberships#available-related-resources | ||||||
Include []OrgMembershipIncludeOpt `url:"include,omitempty"` | ||||||
|
||||||
// Optional: A list of organization member emails to filter by. | ||||||
Emails []string `url:"filter[email],omitempty"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be,
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👋 The param in the API is actually |
||||||
} | ||||||
|
||||||
// OrganizationMembershipCreateOptions represents the options for creating an organization membership. | ||||||
|
@@ -206,6 +209,10 @@ func (o *OrganizationMembershipListOptions) valid() error { | |||||
return err | ||||||
} | ||||||
|
||||||
if err := validateOrgMembershipEmailParams(o.Emails); err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
|
@@ -229,3 +236,13 @@ func validateOrgMembershipIncludeParams(params []OrgMembershipIncludeOpt) error | |||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
func validateOrgMembershipEmailParams(emails []string) error { | ||||||
for _, email := range emails { | ||||||
if !validEmail(email) { | ||||||
return ErrInvalidEmail | ||||||
} | ||||||
} | ||||||
|
||||||
return nil | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,9 @@ type TeamListOptions struct { | |
// Optional: A list of relations to include. | ||
// https://www.terraform.io/docs/cloud/api/teams.html#available-related-resources | ||
Include []TeamIncludeOpt `url:"include,omitempty"` | ||
|
||
// Optional: A list of team names to filter by. | ||
Names []string `url:"filter[names],omitempty"` | ||
} | ||
|
||
// TeamCreateOptions represents the options for creating a team. | ||
|
@@ -263,6 +266,10 @@ func (o *TeamListOptions) valid() error { | |
return err | ||
} | ||
|
||
if err := validateTeamNames(o.Names); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -278,3 +285,13 @@ func validateTeamIncludeParams(params []TeamIncludeOpt) error { | |
|
||
return nil | ||
} | ||
|
||
func validateTeamNames(names []string) error { | ||
for _, name := range names { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works when names is nil, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yessir! |
||
if name == "" { | ||
return ErrEmptyTeamName | ||
} | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package tfe | ||
|
||
import ( | ||
"net/mail" | ||
"regexp" | ||
) | ||
|
||
|
@@ -20,3 +21,9 @@ func validString(v *string) bool { | |
func validStringID(v *string) bool { | ||
return v != nil && reStringID.MatchString(*v) | ||
} | ||
|
||
// validEmail checks if the given input is a correct email | ||
func validEmail(v string) bool { | ||
_, err := mail.ParseAddress(v) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice 🎉 |
||
return err == nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm asking @laurapacilio about this because ... after doing a quick search I realized that this suggestion may not be consistent with what we do as a company.