Skip to content

Commit

Permalink
Merge pull request #121 from terraform-providers/project-rs
Browse files Browse the repository at this point in the history
Project resource and datasources
  • Loading branch information
marinsalinas authored May 19, 2020
2 parents 751ce8f + 5fae6dd commit 8265add
Show file tree
Hide file tree
Showing 643 changed files with 36,747 additions and 17,148 deletions.
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 @@ -1150,3 +1156,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

0 comments on commit 8265add

Please sign in to comment.