in app/registry/public_api.go [133:181]
func (a *App) disablePublicAPIReg(ctx *gin.Context) (router.Response, error) {
registryName := ctx.Param("name")
systemName := ctx.PostForm("reg-name")
if systemName == "" {
return nil, errors.New("reg-name is required")
}
vals, err := GetValuesFromGit(registryName, MasterBranch, a.Gerrit)
if err != nil {
return nil, fmt.Errorf("unable to get values from git, %w", err)
}
found := false
var action string
for i, v := range vals.PublicApi {
if v.Name == systemName {
vals.PublicApi[i].Enabled = !vals.PublicApi[i].Enabled
found = true
if vals.PublicApi[i].Enabled {
action = "enable"
} else {
action = "disable"
}
break
}
}
if !found {
return nil, errors.New("reg-name not found")
}
vals.OriginalYaml[publicAPIValuesIndex] = vals.PublicApi
if err := CreateEditMergeRequest(
ctx,
registryName,
vals.OriginalYaml,
a.Gerrit, []string{},
MRLabel{Key: MRLabelPublicApiTarget, Value: mrTargetPublicAPIReg},
MRLabel{Key: MRLabelPublicApiName, Value: ctx.PostForm("reg-name")},
MRLabel{Key: MRLabelPublicApiSubTarget, Value: action},
); err != nil {
return nil, fmt.Errorf("unable to create MR, %w", err)
}
return router.MakeRedirectResponse(http.StatusFound,
fmt.Sprintf("/admin/registry/view/%s", registryName)), nil
}