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

Access control policies #175

Merged
merged 46 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
46642af
feat: added functions for access control policies in client
Oct 28, 2020
28b52b7
feat: added resource and datasource(s) for access control policies
Oct 28, 2020
da7d8fc
fix: fixes linter make test
Oct 28, 2020
7aa598e
fix: fixes and refactorized to make it work it the testacc
Oct 30, 2020
95a88e6
added validatefunc for some parameters
Oct 30, 2020
437dac5
docs: added docs for access control policies
Oct 30, 2020
63769d9
refactor: refactorized and fixes linters
Nov 1, 2020
2a6a8e2
updated docs
Nov 1, 2020
5935cfe
changed filter_context_list to context_filter_list
Nov 3, 2020
4783c44
feat: renabled the projects resources and datasource(s)
Nov 3, 2020
25d1eb0
renamed files and hardcoded kind for project_reference
Nov 4, 2020
331a899
added return nil in read function
yannickstruyf3 Nov 5, 2020
eda63df
modified code to support project and ACP use case. Also make sure tha…
yannickstruyf3 Nov 5, 2020
341af13
removed api_version hardcoded
yannickstruyf3 Nov 5, 2020
a06c474
chore: updated vendor
Nov 6, 2020
5dc46c0
updated imports
Nov 6, 2020
904ad6c
refactorized some mistakes
Nov 10, 2020
acbb25b
made resource_domain optional -> quotas are also optional in projects
yannickstruyf3 Nov 17, 2020
2f3ea52
added max items to resource_domain
yannickstruyf3 Nov 17, 2020
a93c052
Merge pull request #183 from yannickstruyf3/bugfix/projects-optional-…
marinsalinas Nov 17, 2020
aa1806e
feat: added functions for access control policies in client
Oct 28, 2020
1b1c4ce
feat: added resource and datasource(s) for access control policies
Oct 28, 2020
859a027
fix: fixes linter make test
Oct 28, 2020
5dc4da4
fix: fixes and refactorized to make it work it the testacc
Oct 30, 2020
fc857ef
added validatefunc for some parameters
Oct 30, 2020
aeafde3
docs: added docs for access control policies
Oct 30, 2020
e1de2e9
refactor: refactorized and fixes linters
Nov 1, 2020
b3488fa
updated docs
Nov 1, 2020
5ead910
changed filter_context_list to context_filter_list
Nov 3, 2020
e0226b2
feat: renabled the projects resources and datasource(s)
Nov 3, 2020
0a14a51
renamed files and hardcoded kind for project_reference
Nov 4, 2020
0570d0d
added return nil in read function
yannickstruyf3 Nov 5, 2020
fae5cf3
modified code to support project and ACP use case. Also make sure tha…
yannickstruyf3 Nov 5, 2020
5db9c7d
removed api_version hardcoded
yannickstruyf3 Nov 5, 2020
eaed354
chore: updated vendor
Nov 6, 2020
961a3cf
updated imports
Nov 6, 2020
7982f48
refactorized some mistakes
Nov 10, 2020
392a410
made resource_domain optional -> quotas are also optional in projects
yannickstruyf3 Nov 17, 2020
5ddab05
added max items to resource_domain
yannickstruyf3 Nov 17, 2020
ee6ca52
Merge pull request #185 from nutanix/acp-update
marinsalinas Nov 17, 2020
c80218f
modified typeset casting for user_reference_list and user_group_refer…
yannickstruyf3 Nov 18, 2020
f86555c
Merge pull request #187 from yannickstruyf3/acp_update_typeset
marinsalinas Nov 18, 2020
370943b
fix wwrong assignment of userreferencelist
yannickstruyf3 Nov 19, 2020
19ba3e3
Merge pull request #189 from yannickstruyf3/bugfix/acp-update-user-re…
marinsalinas Nov 19, 2020
2b38de0
git merge
Dec 3, 2020
be80ab2
chore: remove vendor dependencies
marinsalinas Dec 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
151 changes: 151 additions & 0 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ type Service interface {
ListAllProject() (*ProjectListResponse, error)
UpdateProject(uuid string, body *Project) (*Project, error)
DeleteProject(uuid string) error
CreateAccessControlPolicy(request *AccessControlPolicy) (*AccessControlPolicy, error)
GetAccessControlPolicy(projectUUID string) (*AccessControlPolicy, error)
ListAccessControlPolicy(getEntitiesRequest *DSMetadata) (*AccessControlPolicyListResponse, error)
ListAllAccessControlPolicy(filter string) (*AccessControlPolicyListResponse, error)
UpdateAccessControlPolicy(uuid string, body *AccessControlPolicy) (*AccessControlPolicy, error)
DeleteAccessControlPolicy(uuid string) (*DeleteResponse, error)
}

/*CreateVM Creates a VM
Expand Down Expand Up @@ -1296,3 +1302,148 @@ func (op Operations) DeleteProject(uuid string) error {

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

/*CreateAccessControlPolicy creates a access policy
* This operation submits a request to create a access policy based on the input parameters.
*
* @param request *Access Policy
* @return *Access Policy
*/
func (op Operations) CreateAccessControlPolicy(request *AccessControlPolicy) (*AccessControlPolicy, error) {
ctx := context.TODO()

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

AccessControlPolicyResponse := new(AccessControlPolicy)

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

/*GetAccessControlPolicy This operation gets a AccessControlPolicy.
*
* @param uuid The access policy uuid - string.
* @return *AccessControlPolicy
*/
func (op Operations) GetAccessControlPolicy(accessControlPolicyUUID string) (*AccessControlPolicy, error) {
ctx := context.TODO()

path := fmt.Sprintf("/access_control_policies/%s", accessControlPolicyUUID)
AccessControlPolicy := new(AccessControlPolicy)

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

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

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

AccessControlPolicyList := new(AccessControlPolicyListResponse)

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

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

/*ListAllAccessControlPolicy gets a list of AccessControlPolicys
* This operation gets a list of AccessControlPolicys, allowing for sorting and pagination.
* Note: Entities that have not been created successfully are not listed.
* @return *AccessControlPolicyListResponse
*/
func (op Operations) ListAllAccessControlPolicy(filter string) (*AccessControlPolicyListResponse, error) {
entities := make([]*AccessControlPolicy, 0)

resp, err := op.ListAccessControlPolicy(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("access_control_policy"),
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.ListAccessControlPolicy(&DSMetadata{
Filter: &filter,
Kind: utils.StringPtr("access_control_policy"),
Length: utils.Int64Ptr(itemsPerPage),
Offset: utils.Int64Ptr(offset),
})

if err != nil {
return nil, err
}

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

offset += itemsPerPage
log.Printf("[Debug] total=%d, remaining=%d, offset=%d len(entities)=%d\n", totalEntities, remaining, offset, len(entities))
}

resp.Entities = entities
}

return resp, nil
}

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

path := fmt.Sprintf("/access_control_policies/%s", uuid)
AccessControlPolicyInput := new(AccessControlPolicy)

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

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

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

path := fmt.Sprintf("/access_control_policies/%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)
}
Loading