(ctx *gin.Context)
| 291 | } |
| 292 | |
| 293 | func (m *Modules) CreateModule(ctx *gin.Context) { |
| 294 | ctx.Header("Access-Control-Allow-Origin", "*") |
| 295 | |
| 296 | var request dto.Module |
| 297 | if err := ctx.BindJSON(&request); err != nil { |
| 298 | fmt.Println("error binding request", request) |
| 299 | ctx.JSON(http.StatusBadRequest, dto.NewError("Error loading template", err.Error())) |
| 300 | return |
| 301 | } |
| 302 | |
| 303 | module, err := mapper.RequestToModule(request) |
| 304 | if err != nil { |
| 305 | fmt.Println(err) |
| 306 | ctx.JSON(http.StatusInternalServerError, dto.NewError("Error mapping module", err.Error())) |
| 307 | return |
| 308 | } |
| 309 | |
| 310 | if len(m.moduleTargetNamespace) > 0 { |
| 311 | module.Spec.TargetNamespace = m.moduleTargetNamespace |
| 312 | } |
| 313 | |
| 314 | m.telemetryClient.ModuleCreation() |
| 315 | |
| 316 | if module.GetAnnotations() != nil && len(module.GetAnnotations()[v1alpha1.GitOpsWriteRepoAnnotation]) != 0 { |
| 317 | err := m.gitWriteClient.Write(module) |
| 318 | if err != nil { |
| 319 | fmt.Println(err) |
| 320 | ctx.JSON(http.StatusInternalServerError, dto.NewError("Error pushing to git", err.Error())) |
| 321 | } |
| 322 | return |
| 323 | } |
| 324 | |
| 325 | err = m.kubernetesClient.CreateModule(module) |
| 326 | if err != nil { |
| 327 | fmt.Println(err) |
| 328 | ctx.JSON(http.StatusInternalServerError, dto.NewError("Error creating module", err.Error())) |
| 329 | return |
| 330 | } |
| 331 | |
| 332 | m.monitor.IncModule() |
| 333 | ctx.Status(http.StatusOK) |
| 334 | } |
| 335 | |
| 336 | func (m *Modules) UpdateModule(ctx *gin.Context) { |
| 337 | ctx.Header("Access-Control-Allow-Origin", "*") |
nothing calls this directly
no test coverage detected