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

Project resource and datasources #121

Merged
merged 8 commits into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ linters:
- wsl
- nestif
- godot
- goconst

issues:
exclude:
Expand Down
146 changes: 146 additions & 0 deletions client/v3/v3_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ type Service interface {
GetHost(taskUUID string) (*HostResponse, error)
ListHost(getEntitiesRequest *DSMetadata) (*HostListResponse, error)
ListAllHost() (*HostListResponse, error)
CreateProject(request *Project) (*Project, error)
GetProject(projectUUID string) (*Project, error)
ListProject(getEntitiesRequest *DSMetadata) (*ProjectListResponse, error)
ListAllProject() (*ProjectListResponse, error)
UpdateProject(uuid string, body *Project) (*Project, error)
DeleteProject(uuid string) error
}

/*CreateVM Creates a VM
Expand Down Expand Up @@ -1140,3 +1146,143 @@ func (op Operations) ListAllHost() (*HostListResponse, error) {

return resp, nil
}

/*CreateProject creates a project
* This operation submits a request to create a project based on the input parameters.
*
* @param request *Project
* @return *Project
*/
func (op Operations) CreateProject(request *Project) (*Project, error) {
ctx := context.TODO()

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

projectResponse := new(Project)

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

/*GetProject This operation gets a project.
*
* @param uuid The prject uuid - string.
* @return *Project
*/
func (op Operations) GetProject(projectUUID string) (*Project, error) {
ctx := context.TODO()

path := fmt.Sprintf("/projects/%s", projectUUID)
project := new(Project)

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

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

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

projectList := new(ProjectListResponse)

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

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

/*ListAllProject gets a list of projects
* This operation gets a list of Projects, allowing for sorting and pagination.
* Note: Entities that have not been created successfully are not listed.
* @return *ProjectListResponse
*/
func (op Operations) ListAllProject() (*ProjectListResponse, error) {
entities := make([]*Project, 0)

resp, err := op.ListProject(&DSMetadata{
Kind: utils.StringPtr("project"),
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.ListProject(&DSMetadata{
Kind: utils.StringPtr("project"),
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
}

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

path := fmt.Sprintf("/projects/%s", uuid)
projectInput := new(Project)

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

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

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

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

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

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