@@ -2,7 +2,6 @@ package coder
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"io"
7
6
"net/http"
8
7
"net/url"
@@ -88,9 +87,8 @@ type CreateEnvironmentRequest struct {
88
87
Namespace string `json:"namespace"`
89
88
EnableAutoStart bool `json:"autostart_enabled"`
90
89
91
- // Template comes from the parse template route on cemanager.
92
- // This field should never be manually populated
93
- Template Template `json:"template,omitempty"`
90
+ // TemplateID comes from the parse template route on cemanager.
91
+ TemplateID string `json:"template_id,omitempty"`
94
92
}
95
93
96
94
// CreateEnvironment sends a request to create an environment.
@@ -105,46 +103,62 @@ func (c *DefaultClient) CreateEnvironment(ctx context.Context, req CreateEnviron
105
103
// ParseTemplateRequest parses a template. If Local is a non-nil reader
106
104
// it will obviate any other fields on the request.
107
105
type ParseTemplateRequest struct {
108
- RepoURL string `json:"repo_url"`
109
- Ref string `json:"ref"`
110
- Local io.Reader `json:"-"`
106
+ RepoURL string `json:"repo_url"`
107
+ Ref string `json:"ref"`
108
+ Filepath string `json:"filepath"`
109
+ OrgID string `json:"-"`
110
+ Local io.Reader `json:"-"`
111
111
}
112
112
113
- // Template is a Workspaces As Code (WAC) template.
113
+ // TemplateVersion is a Workspaces As Code (WAC) template.
114
114
// For now, let's not interpret it on the CLI level. We just need
115
115
// to forward this as part of the create env request.
116
- type Template = json.RawMessage
116
+ type TemplateVersion struct {
117
+ ID string `json:"id"`
118
+ TemplateID string `json:"template_id"`
119
+ // FileHash is the sha256 hash of the template's file contents.
120
+ FileHash string `json:"file_hash"`
121
+ // Commit is the git commit from which the template was derived.
122
+ Commit string `json:"commit"`
123
+ CommitMessage string `json:"commit_message"`
124
+ CreatedAt time.Time `json:"created_at"`
125
+ }
117
126
118
127
// ParseTemplate parses a template config. It support both remote repositories and local files.
119
128
// If a local file is specified then all other values in the request are ignored.
120
- func (c * DefaultClient ) ParseTemplate (ctx context.Context , req ParseTemplateRequest ) (Template , error ) {
129
+ func (c * DefaultClient ) ParseTemplate (ctx context.Context , req ParseTemplateRequest ) (* TemplateVersion , error ) {
121
130
const path = "/api/private/environments/template/parse"
122
131
var (
123
- tpl Template
132
+ tpl TemplateVersion
124
133
opts []requestOption
125
134
headers = http.Header {}
135
+ query = url.Values {}
126
136
)
127
137
138
+ query .Set ("org-id" , req .OrgID )
139
+
140
+ opts = append (opts , withQueryParams (query ))
141
+
128
142
if req .Local == nil {
129
- if err := c .requestBody (ctx , http .MethodPost , path , req , & tpl ); err != nil {
130
- return tpl , err
143
+ if err := c .requestBody (ctx , http .MethodPost , path , req , & tpl , opts ... ); err != nil {
144
+ return & tpl , err
131
145
}
132
- return tpl , nil
146
+ return & tpl , nil
133
147
}
134
148
135
149
headers .Set ("Content-Type" , "application/octet-stream" )
136
150
opts = append (opts , withBody (req .Local ), withHeaders (headers ))
137
151
138
152
err := c .requestBody (ctx , http .MethodPost , path , nil , & tpl , opts ... )
139
153
if err != nil {
140
- return tpl , err
154
+ return & tpl , err
141
155
}
142
156
143
- return tpl , nil
157
+ return & tpl , nil
144
158
}
145
159
146
160
// CreateEnvironmentFromRepo sends a request to create an environment from a repository.
147
- func (c * DefaultClient ) CreateEnvironmentFromRepo (ctx context.Context , orgID string , req Template ) (* Environment , error ) {
161
+ func (c * DefaultClient ) CreateEnvironmentFromRepo (ctx context.Context , orgID string , req TemplateVersion ) (* Environment , error ) {
148
162
var env Environment
149
163
if err := c .requestBody (ctx , http .MethodPost , "/api/private/orgs/" + orgID + "/environments/from-repo" , req , & env ); err != nil {
150
164
return nil , err
0 commit comments