-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat(api): implement crud operations for team members #614
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0293313
feat(api): implement crud operations for team members
41268a7
refactor(api): include tests for update and delete
2e718bc
chore: fix linting
a690c55
chore: Merge remote-tracking branch 'origin/main' into vatasha/ally-7…
e10173c
Add updated test for when the API returns an int for date fields
cccda3e
Merge branch 'main' into vatasha/ally-736/implement-team-members
hazedav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
// | ||
// Author:: Vatasha White (<[email protected]>) | ||
// Copyright:: Copyright 2021, Lacework Inc. | ||
// License:: Apache License, Version 2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package api | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type TeamMembersService struct { | ||
client *Client | ||
} | ||
|
||
// NewTeamMember returns an instance of the Team Member struct | ||
// | ||
// Basic usage: Initialize a new TeamMember struct and then use the new instance to perform CRUD operations. | ||
// | ||
// client, err := api.NewClient("account") | ||
// if err != nil { | ||
// return err | ||
// } | ||
// | ||
// teamMember := api.NewTeamMember( | ||
// "FooBar", | ||
// api.TeamMemberProps{ | ||
// Company: "ACME Inc", | ||
// FirstName: "Foo", | ||
// LastName: "Bar" | ||
// }, | ||
// }, | ||
// ) | ||
// | ||
// client.V2.TeamMembers.Create(teamMember) | ||
// | ||
func NewTeamMember(username string, props TeamMemberProps) TeamMember { | ||
return TeamMember{ | ||
Props: props, | ||
UserEnabled: 1, | ||
UserName: username, | ||
} | ||
} | ||
|
||
// List returns a list of team members | ||
func (svc *TeamMembersService) List() (res TeamMembersResponse, err error) { | ||
err = svc.client.RequestDecoder("GET", apiV2TeamMembers, nil, &res) | ||
return | ||
} | ||
|
||
// Create creates a single team member | ||
func (svc *TeamMembersService) Create(tm TeamMember) (res TeamMemberResponse, err error) { | ||
err = svc.client.RequestEncoderDecoder("POST", apiV2TeamMembers, tm, &res) | ||
return | ||
} | ||
|
||
// Delete deletes a single team member with the corresponding guid | ||
func (svc *TeamMembersService) Delete(guid string) error { | ||
if guid == "" { | ||
return errors.New("please specify a guid") | ||
} | ||
|
||
return svc.client.RequestDecoder("DELETE", fmt.Sprintf(apiV2TeamMembersFromGUID, guid), nil, nil) | ||
} | ||
|
||
// Update updates a single team member with the corresponding guid | ||
func (svc *TeamMembersService) Update(tm TeamMember) (res TeamMemberResponse, err error) { | ||
if tm.UserGuid == "" { | ||
err = errors.New("please specify a guid") | ||
return | ||
} | ||
err = svc.client.RequestEncoderDecoder("PATCH", fmt.Sprintf(apiV2TeamMembersFromGUID, tm.UserGuid), tm, &res) | ||
return | ||
} | ||
|
||
// Get returns a response of the team member | ||
func (svc *TeamMembersService) Get(guid string, res interface{}) error { | ||
if guid == "" { | ||
return errors.New("please specify a guid") | ||
} | ||
return svc.client.RequestDecoder("GET", fmt.Sprintf(apiV2TeamMembersFromGUID, guid), nil, &res) | ||
|
||
} | ||
|
||
type TeamMemberProps struct { | ||
AccountAdmin bool `json:"accountAdmin,omitempty"` | ||
Company string `json:"company"` | ||
CreatedTime string `json:"createdTime,omitempty"` | ||
FirstName string `json:"firstName"` | ||
JitCreated bool `json:"jitCreated,omitempty"` | ||
LastLoginTime interface{} `json:"lastLoginTime,omitempty"` | ||
LastName string `json:"lastName"` | ||
LastSessionCreatedTime interface{} `json:"lastSessionCreatedTime,omitempty"` | ||
OrgAdmin bool `json:"orgAdmin,omitempty"` | ||
OrgUser bool `json:"orgUser,omitempty"` | ||
UpdatedBy string `json:"updatedBy,omitempty"` | ||
UpdatedTime interface{} `json:"updatedTime,omitempty"` | ||
} | ||
|
||
type TeamMember struct { | ||
CustGuid string `json:"custGuid,omitempty"` | ||
Props TeamMemberProps `json:"props"` | ||
UserEnabled int `json:"userEnabled"` | ||
UserGuid string `json:"userGuid,omitempty"` | ||
UserName string `json:"userName"` | ||
} | ||
|
||
type TeamMemberResponse struct { | ||
Data TeamMember `json:"data"` | ||
} | ||
|
||
type TeamMembersResponse struct { | ||
Data []TeamMember `json:"data"` | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For updates, verify that you are able to send the
UserGuid
as part of the request payload, some endpoints complain about it since you are already injecting it via URL parameter.