(w rest.ResponseWriter, r *rest.Request)
| 172 | } |
| 173 | |
| 174 | func (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 |
nothing calls this directly
no test coverage detected