mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-02-27 20:01:34 -05:00
* Remove `make updatedeps` from Travis build. We'll follow up with more specific plans around dependency updating in subsequent PRs. * Update all `make` targets to set `GO15VENDOREXPERIMENT=1` and to filter out `/vendor/` from `./...` where appropriate. * Temporarily remove `vet` from the `make test` target until we can figure out how to get it to not vet `vendor/`. (Initial experimentation failed to yield the proper incantation.) Everything is pinned to current master, with the exception of: * Azure/azure-sdk-for-go which is pinned before the breaking change today * aws/aws-sdk-go which is pinned to the most recent tag The documentation still needs to be updated, which we can do in a follow up PR. The goal here is to unblock release.
137 lines
3.4 KiB
Go
137 lines
3.4 KiB
Go
package packngo
|
|
|
|
import "fmt"
|
|
|
|
const projectBasePath = "/projects"
|
|
|
|
// ProjectService interface defines available project methods
|
|
type ProjectService interface {
|
|
List() ([]Project, *Response, error)
|
|
Get(string) (*Project, *Response, error)
|
|
Create(*ProjectCreateRequest) (*Project, *Response, error)
|
|
Update(*ProjectUpdateRequest) (*Project, *Response, error)
|
|
Delete(string) (*Response, error)
|
|
}
|
|
|
|
type projectsRoot struct {
|
|
Projects []Project `json:"projects"`
|
|
}
|
|
// Project represents a Packet project
|
|
type Project struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name,omitempty"`
|
|
Created string `json:"created_at,omitempty"`
|
|
Updated string `json:"updated_at,omitempty"`
|
|
Users []User `json:"members,omitempty"`
|
|
Devices []Device `json:"devices,omitempty"`
|
|
SSHKeys []SSHKey `json:"ssh_keys,omitempty"`
|
|
URL string `json:"href,omitempty"`
|
|
}
|
|
func (p Project) String() string {
|
|
return Stringify(p)
|
|
}
|
|
|
|
// ProjectCreateRequest type used to create a Packet project
|
|
type ProjectCreateRequest struct {
|
|
Name string `json:"name"`
|
|
PaymentMethod string `json:"payment_method,omitempty"`
|
|
}
|
|
func (p ProjectCreateRequest) String() string {
|
|
return Stringify(p)
|
|
}
|
|
|
|
// ProjectUpdateRequest type used to update a Packet project
|
|
type ProjectUpdateRequest struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name,omitempty"`
|
|
PaymentMethod string `json:"payment_method,omitempty"`
|
|
}
|
|
func (p ProjectUpdateRequest) String() string {
|
|
return Stringify(p)
|
|
}
|
|
|
|
// ProjectServiceOp implements ProjectService
|
|
type ProjectServiceOp struct {
|
|
client *Client
|
|
}
|
|
|
|
// List returns the user's projects
|
|
func (s *ProjectServiceOp) List() ([]Project, *Response, error) {
|
|
req, err := s.client.NewRequest("GET", projectBasePath, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
root := new(projectsRoot)
|
|
resp, err := s.client.Do(req, root)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return root.Projects, resp, err
|
|
}
|
|
|
|
// Get returns a project by id
|
|
func (s *ProjectServiceOp) Get(projectID string) (*Project, *Response, error) {
|
|
path := fmt.Sprintf("%s/%s", projectBasePath, projectID)
|
|
req, err := s.client.NewRequest("GET", path, nil)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
project := new(Project)
|
|
resp, err := s.client.Do(req, project)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return project, resp, err
|
|
}
|
|
|
|
// Create creates a new project
|
|
func (s *ProjectServiceOp) Create(createRequest *ProjectCreateRequest) (*Project, *Response, error) {
|
|
req, err := s.client.NewRequest("POST", projectBasePath, createRequest)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
project := new(Project)
|
|
resp, err := s.client.Do(req, project)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return project, resp, err
|
|
}
|
|
|
|
// Update updates a project
|
|
func (s *ProjectServiceOp) Update(updateRequest *ProjectUpdateRequest) (*Project, *Response, error) {
|
|
path := fmt.Sprintf("%s/%s", projectBasePath, updateRequest.ID)
|
|
req, err := s.client.NewRequest("PATCH", path, updateRequest)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
|
|
project := new(Project)
|
|
resp, err := s.client.Do(req, project)
|
|
if err != nil {
|
|
return nil, resp, err
|
|
}
|
|
|
|
return project, resp, err
|
|
}
|
|
|
|
// Delete deletes a project
|
|
func (s *ProjectServiceOp) Delete(projectID string) (*Response, error) {
|
|
path := fmt.Sprintf("%s/%s", projectBasePath, projectID)
|
|
|
|
req, err := s.client.NewRequest("DELETE", path, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp, err := s.client.Do(req, nil)
|
|
|
|
return resp, err
|
|
}
|