Skip to content

Commit

Permalink
Merge pull request nutanix#175 from nutanix/access-policies
Browse files Browse the repository at this point in the history
Access control policies
  • Loading branch information
marinsalinas authored Dec 3, 2020
2 parents 9cbc389 + 831f9c7 commit 3e56cf2
Show file tree
Hide file tree
Showing 562 changed files with 102,626 additions and 59,174 deletions.
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

0 comments on commit 3e56cf2

Please sign in to comment.