|
| 1 | +package coderd |
| 2 | + |
| 3 | +import ( |
| 4 | + "net/http" |
| 5 | + |
| 6 | + "github.com/coder/coder/xjson" |
| 7 | +) |
| 8 | + |
| 9 | +type ProjectParameter struct { |
| 10 | + Id string `json:"id" validate:"required"` |
| 11 | + Name string `json:"name" validate:"required"` |
| 12 | + Description string `json:"description"` |
| 13 | + |
| 14 | + // Validation Parameters |
| 15 | + ValueType string `json:"validation_value_type"` |
| 16 | +} |
| 17 | + |
| 18 | +// Project is a Go representation of the workspaces v2 project, |
| 19 | +// defined here: https://www.notion.so/coderhq/Workspaces-v2-e908a8cd54804ddd910367abf03c8d0a#befa328add894231979e6cf8a378d2ec |
| 20 | +type Project struct { |
| 21 | + Id string `json:"id" validate:"required"` |
| 22 | + Name string `json:"name" validate:"required"` |
| 23 | + Description string `json:"description" validate:"required"` |
| 24 | + ProvisionerType string `json:"provisioner_type" validate:"required"` |
| 25 | + |
| 26 | + Parameters []ProjectParameter `json:"parameters" validate:"required"` |
| 27 | +} |
| 28 | + |
| 29 | +// Placeholder type of projectService |
| 30 | +type projectService struct { |
| 31 | +} |
| 32 | + |
| 33 | +func newProjectService() *projectService { |
| 34 | + projectService := &projectService{} |
| 35 | + return projectService |
| 36 | +} |
| 37 | + |
| 38 | +func (ps *projectService) getProjects(w http.ResponseWriter, r *http.Request) { |
| 39 | + |
| 40 | + // Construct a couple hard-coded projects to return the UI |
| 41 | + |
| 42 | + terraformProject := Project{ |
| 43 | + Id: "test_terraform_project_id", |
| 44 | + Name: "Terraform", |
| 45 | + Description: "Kubernetes on Terraform", |
| 46 | + Parameters: []ProjectParameter{ |
| 47 | + { |
| 48 | + Id: "parameter_cluster_namespace", |
| 49 | + Name: "Namespace", |
| 50 | + Description: "Kubernetes namespace to host workspace pod", |
| 51 | + ValueType: "string", |
| 52 | + }, |
| 53 | + { |
| 54 | + Id: "parameter_cpu", |
| 55 | + Name: "CPU", |
| 56 | + Description: "CPU Cores to Allocate", |
| 57 | + ValueType: "number", |
| 58 | + }, |
| 59 | + }, |
| 60 | + } |
| 61 | + |
| 62 | + echoProject := Project{ |
| 63 | + Id: "test_echo_project_id", |
| 64 | + Name: "Echo Project", |
| 65 | + Description: "A simple echo provider", |
| 66 | + Parameters: []ProjectParameter{ |
| 67 | + { |
| 68 | + Id: "parameter_echo_string", |
| 69 | + Name: "Echo String", |
| 70 | + Description: "String that should be echo'd out in build log", |
| 71 | + ValueType: "string", |
| 72 | + }, |
| 73 | + }, |
| 74 | + } |
| 75 | + |
| 76 | + projects := []Project{ |
| 77 | + terraformProject, |
| 78 | + echoProject, |
| 79 | + } |
| 80 | + |
| 81 | + xjson.Write(w, http.StatusOK, projects) |
| 82 | +} |
| 83 | + |
| 84 | +func (ps *projectService) createProject(w http.ResponseWriter, r *http.Request) { |
| 85 | + // TODO: Validate arguments |
| 86 | + // Organization context |
| 87 | + // User |
| 88 | + // Parameter values |
| 89 | + // Submit to provisioner |
| 90 | + xjson.Write(w, http.StatusOK, nil) |
| 91 | +} |
0 commit comments