MCPcopy Create free account
hub / github.com/cloud66-oss/starter / upload

Method upload

api.go:174–222  ·  view source on GitHub ↗
(w rest.ResponseWriter, r *rest.Request)

Source from the content-addressed store, hash-verified

172}
173
174func (a *API) upload(w rest.ResponseWriter, r *rest.Request) {
175 uuid := uuid.NewV4().String()
176
177 git_repo := r.FormValue("git_repo")
178 git_branch := r.FormValue("git_branch")
179
180 //save the file to a random location
181 file, handler, err := r.FormFile("source")
182 if err != nil {
183 a.Error(w, err.Error(), 2, http.StatusInternalServerError)
184 return
185 }
186 defer file.Close()
187
188 filename := "/tmp/" + uuid + "/" + handler.Filename
189 source_dir := "/tmp/" + uuid
190 err = os.MkdirAll(source_dir, 0777)
191
192 if err != nil {
193 a.Error(w, err.Error(), 3, http.StatusInternalServerError)
194 return
195 }
196 f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE, 0666)
197 if err != nil {
198 a.Error(w, err.Error(), 4, http.StatusInternalServerError)
199 return
200 }
201 defer f.Close()
202 io.Copy(f, file)
203
204 //unzip the file
205 unzip(filename, source_dir)
206
207 //analyse
208 analysis := analyze_sourcecode(config, source_dir, "dockerfile,docker-compose,service", git_repo, git_branch)
209
210 //cleanup
211 err = os.RemoveAll(source_dir)
212 if err != nil {
213 a.Error(w, err.Error(), 5, http.StatusInternalServerError)
214 return
215 }
216
217 if analysis != nil {
218 w.WriteJson(analysis)
219 } else {
220 a.Error(w, "No supported language and/or framework detected", 6, http.StatusOK)
221 }
222}
223
224// routes parsing
225

Callers

nothing calls this directly

Calls 3

ErrorMethod · 0.95
unzipFunction · 0.85
analyze_sourcecodeFunction · 0.85

Tested by

no test coverage detected