Skip to content
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

User Resource and Data Sources. #179

Merged
merged 41 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
196c1b4
chore: update vendor dependencie
marinsalinas Nov 17, 2020
8ed700b
feat: add User SDK requests
marinsalinas Nov 4, 2020
8f30e82
wip/feat: added schema and create function
marinsalinas Nov 4, 2020
f2d8ea6
wip/feat: added user read function
marinsalinas Nov 5, 2020
3499dc2
wip/feat: added user update and delete function
marinsalinas Nov 5, 2020
8794641
feat: add user data source
marinsalinas Nov 5, 2020
2986b97
fix: change directory_service_user and identity_provider_user casting…
marinsalinas Nov 9, 2020
3a8c17e
fix: change directory_service_user and identity_provider_user casting…
marinsalinas Nov 9, 2020
e54da77
fix: avoid sending object when is empty
marinsalinas Nov 9, 2020
6345392
chore: return nil when user si not found
marinsalinas Nov 9, 2020
ce9d911
modified logs and modified directory_service_reference to slice in re…
yannickstruyf3 Nov 9, 2020
9a64e31
feat: add user data source by name
marinsalinas Nov 9, 2020
cabf816
feat: add user list data source
marinsalinas Nov 10, 2020
f8036bd
test: add testing for user endpoints
marinsalinas Nov 10, 2020
53e3d3f
test: add basic acceptance test for user resource
marinsalinas Nov 10, 2020
8d4c819
fix: get correct value when expand identity provider user
marinsalinas Nov 13, 2020
5bf1a55
test: add user data source acceptance testing
marinsalinas Nov 13, 2020
297855c
chore: add user resource website documentation
marinsalinas Nov 17, 2020
b585d8e
chore: add user data source website documentation
marinsalinas Nov 17, 2020
cc41372
chore: add users data source website documentation
marinsalinas Nov 17, 2020
c8a4c58
test: add testing for user endpoints
marinsalinas Nov 10, 2020
b3bea91
test: add basic acceptance test for user resource
marinsalinas Nov 10, 2020
3533598
feat: make user_reference_list and expernal_user_group_reference_list…
marinsalinas Nov 19, 2020
b283dc0
test: add user with identity_provider test case
marinsalinas Nov 20, 2020
2d6174a
chore: update go.sum
marinsalinas Nov 23, 2020
97d28f4
refactor: change metadata function in roles ds
marinsalinas Nov 24, 2020
985a89b
changed if statement in ds role and modified the conflictswith
yannickstruyf3 Nov 24, 2020
d7478ee
chore: fix linting issues
marinsalinas Dec 1, 2020
37e9e7a
feat: add user group singular datasource
marinsalinas Dec 1, 2020
02c9b9d
changed print messages and added filter based on DN
yannickstruyf3 Dec 1, 2020
2f8f9d3
renamed ds attributes and prints
yannickstruyf3 Dec 1, 2020
5058d5c
fix: rewrite if statement on user_group data source to get the resource
marinsalinas Dec 1, 2020
d71217e
chore: fix misspelling on user data source website docs
marinsalinas Dec 1, 2020
c56fe66
fixed bug that occured when updating the permissions of a role
yannickstruyf3 Dec 1, 2020
78c9187
kind in permission_reference_list is now by default 'permission'
yannickstruyf3 Dec 1, 2020
cc9b315
test: add acc test for user group data source
marinsalinas Dec 1, 2020
e5acd60
website: add user group data source website documentation
marinsalinas Dec 2, 2020
d7391f8
feat: add user groups datasource
marinsalinas Dec 2, 2020
1da0e7b
website: add user groups data source website documentation
marinsalinas Dec 2, 2020
6241b0d
chore: update vendor dependencies
marinsalinas Dec 3, 2020
1f34b86
chore: fix linting issues
marinsalinas Dec 3, 2020
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
231 changes: 230 additions & 1 deletion client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ type Service interface {
UpdateProject(uuid string, body *Project) (*Project, error)
DeleteProject(uuid string) error
CreateAccessControlPolicy(request *AccessControlPolicy) (*AccessControlPolicy, error)
GetAccessControlPolicy(uuid string) (*AccessControlPolicy, error)
GetAccessControlPolicy(accessControlPolicyUUID string) (*AccessControlPolicy, error)
ListAccessControlPolicy(getEntitiesRequest *DSMetadata) (*AccessControlPolicyListResponse, error)
ListAllAccessControlPolicy(filter string) (*AccessControlPolicyListResponse, error)
UpdateAccessControlPolicy(uuid string, body *AccessControlPolicy) (*AccessControlPolicy, error)
Expand All @@ -83,6 +83,15 @@ type Service interface {
ListAllRole(filter string) (*RoleListResponse, error)
UpdateRole(uuid string, body *Role) (*Role, error)
DeleteRole(uuid string) (*DeleteResponse, error)
CreateUser(request *UserIntentInput) (*UserIntentResponse, error)
GetUser(userUUID string) (*UserIntentResponse, error)
UpdateUser(uuid string, body *UserIntentInput) (*UserIntentResponse, error)
DeleteUser(uuid string) (*DeleteResponse, error)
ListUser(getEntitiesRequest *DSMetadata) (*UserListResponse, error)
ListAllUser(filter string) (*UserListResponse, error)
GetUserGroup(userUUID string) (*UserGroupIntentResponse, error)
ListUserGroup(getEntitiesRequest *DSMetadata) (*UserGroupListResponse, error)
ListAllUserGroup(filter string) (*UserGroupListResponse, error)
}

/*CreateVM Creates a VM
Expand Down Expand Up @@ -1598,3 +1607,223 @@ func (op Operations) DeleteRole(uuid string) (*DeleteResponse, error) {

return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}

/*CreateUser creates a User
* This operation submits a request to create a userbased on the input parameters.
*
* @param request *VMIntentInput
* @return *UserIntentResponse
*/
func (op Operations) CreateUser(request *UserIntentInput) (*UserIntentResponse, error) {
ctx := context.TODO()

req, err := op.client.NewRequest(ctx, http.MethodPost, "/users", request)
if err != nil {
return nil, err
}

UserIntentResponse := new(UserIntentResponse)

return UserIntentResponse, op.client.Do(ctx, req, UserIntentResponse)
}

/*GetUser This operation gets a User.
*
* @param uuid The user uuid - string.
* @return *User
*/
func (op Operations) GetUser(userUUID string) (*UserIntentResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/users/%s", userUUID)
User := new(UserIntentResponse)

req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}

return User, op.client.Do(ctx, req, User)
}

/*UpdateUser Updates a User
* This operation submits a request to update a existing User based on the input parameters
* @param uuid The uuid of the entity - string.
* @param body - *User
* @return *User, error
*/
func (op Operations) UpdateUser(uuid string, body *UserIntentInput) (*UserIntentResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/users/%s", uuid)
UserInput := new(UserIntentResponse)

req, err := op.client.NewRequest(ctx, http.MethodPut, path, body)
if err != nil {
return nil, err
}

return UserInput, op.client.Do(ctx, req, UserInput)
}

/*DeleteUser Deletes a User
* This operation submits a request to delete a existing User.
*
* @param uuid The uuid of the entity.
* @return void
*/
func (op Operations) DeleteUser(uuid string) (*DeleteResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/users/%s", uuid)

req, err := op.client.NewRequest(ctx, http.MethodDelete, path, nil)
deleteResponse := new(DeleteResponse)

if err != nil {
return nil, err
}

return deleteResponse, op.client.Do(ctx, req, deleteResponse)
}

/*ListUser gets a list of Users.
*
* @param metadata allows create filters to get specific data - *DSMetadata.
* @return *UserListResponse
*/
func (op Operations) ListUser(getEntitiesRequest *DSMetadata) (*UserListResponse, error) {
ctx := context.TODO()
path := "/users/list"

UserList := new(UserListResponse)

req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
if err != nil {
return nil, err
}

return UserList, op.client.Do(ctx, req, UserList)
}

// ListAllUser ...
func (op Operations) ListAllUser(filter string) (*UserListResponse, error) {
entities := make([]*UserIntentResponse, 0)

resp, err := op.ListUser(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("user"),
Length: utils.Int64Ptr(itemsPerPage),
})

if err != nil {
return nil, err
}

totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)

if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListUser(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("user"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})

if err != nil {
return nil, err
}

entities = append(entities, resp.Entities...)

offset += itemsPerPage
}

resp.Entities = entities
}

return resp, nil
}

/*GetUserGroup This operation gets a User.
*
* @param uuid The user uuid - string.
* @return *User
*/
func (op Operations) GetUserGroup(userGroupUUID string) (*UserGroupIntentResponse, error) {
ctx := context.TODO()

path := fmt.Sprintf("/user_groups/%s", userGroupUUID)
User := new(UserGroupIntentResponse)

req, err := op.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, err
}

return User, op.client.Do(ctx, req, User)
}

/*ListUserGroup gets a list of UserGroups.
*
* @param metadata allows create filters to get specific data - *DSMetadata.
* @return *UserGroupListResponse
*/
func (op Operations) ListUserGroup(getEntitiesRequest *DSMetadata) (*UserGroupListResponse, error) {
ctx := context.TODO()
path := "/user_groups/list"

UserGroupList := new(UserGroupListResponse)

req, err := op.client.NewRequest(ctx, http.MethodPost, path, getEntitiesRequest)
if err != nil {
return nil, err
}

return UserGroupList, op.client.Do(ctx, req, UserGroupList)
}

// ListAllUserGroup ...
func (op Operations) ListAllUserGroup(filter string) (*UserGroupListResponse, error) {
entities := make([]*UserGroupIntentResponse, 0)

resp, err := op.ListUserGroup(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("user_group"),
Length: utils.Int64Ptr(itemsPerPage),
})

if err != nil {
return nil, err
}

totalEntities := utils.Int64Value(resp.Metadata.TotalMatches)
remaining := totalEntities
offset := utils.Int64Value(resp.Metadata.Offset)

if totalEntities > itemsPerPage {
for hasNext(&remaining) {
resp, err = op.ListUserGroup(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("user"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})

if err != nil {
return nil, err
}

entities = append(entities, resp.Entities...)

offset += itemsPerPage
}

resp.Entities = entities
}

return resp, nil
}
Loading