From 92ff3204297082fde0debf7d510ad8b09d73cbc4 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Fri, 9 Aug 2024 16:50:35 +0200 Subject: [PATCH] Remove various deprecations (#4017) --- cmd/cli/app.go | 3 -- .../100-external-configuration-api.md | 11 ++-- docs/docs/91-migrations.md | 3 ++ server/api/login.go | 51 ------------------- server/router/api.go | 7 --- server/router/router.go | 1 - server/services/config/http.go | 19 +++---- 7 files changed, 14 insertions(+), 81 deletions(-) diff --git a/cmd/cli/app.go b/cmd/cli/app.go index 4b3fe6698..086914804 100644 --- a/cmd/cli/app.go +++ b/cmd/cli/app.go @@ -29,7 +29,6 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/org" "go.woodpecker-ci.org/woodpecker/v2/cli/pipeline" "go.woodpecker-ci.org/woodpecker/v2/cli/repo" - "go.woodpecker-ci.org/woodpecker/v2/cli/repo/registry" "go.woodpecker-ci.org/woodpecker/v2/cli/secret" "go.woodpecker-ci.org/woodpecker/v2/cli/setup" "go.woodpecker-ci.org/woodpecker/v2/cli/update" @@ -57,8 +56,6 @@ func newApp() *cli.Command { deploy.Command, exec.Command, info.Command, - // TODO: Remove in 3.x - registry.Command, secret.Command, user.Command, lint.Command, diff --git a/docs/docs/30-administration/40-advanced/100-external-configuration-api.md b/docs/docs/30-administration/40-advanced/100-external-configuration-api.md index db112126d..a24abd3bd 100644 --- a/docs/docs/30-administration/40-advanced/100-external-configuration-api.md +++ b/docs/docs/30-administration/40-advanced/100-external-configuration-api.md @@ -81,12 +81,11 @@ WOODPECKER_CONFIG_SERVICE_ENDPOINT=https://example.com/ciconfig "updated_at": 0, "verified": false }, - "configs": [ - { - "name": ".woodpecker.yaml", - "data": "steps:\n - name: backend\n image: alpine\n commands:\n - echo \"Hello there from Repo (.woodpecker.yaml)\"\n" - } - ] + "netrc": { + "machine": "https://example.com", + "login": "user", + "password": "password" + } } ``` diff --git a/docs/docs/91-migrations.md b/docs/docs/91-migrations.md index 9e8603be8..88d4c426d 100644 --- a/docs/docs/91-migrations.md +++ b/docs/docs/91-migrations.md @@ -20,6 +20,9 @@ Some versions need some changes to the server configuration or the pipeline conf - Renamed `start_time`, `end_time`, `created_at`, `started_at`, `finished_at` and `reviewed_at` JSON fields to `started`, `finished`, `created`, `started`, `finished`, `reviewed` - Update all webhooks by pressing the "Repair all" button in the admin settings as the webhook token claims have changed - Crons now use standard Linux syntax without seconds +- Replaced `configs` object by `netrc` in external configuration APIs +- Removed old API routes: `registry/` -> `registries`, `/authorize/token` +- Replaced `registry` command with `repo registry` in cli ## 2.0.0 diff --git a/server/api/login.go b/server/api/login.go index ebe6cf7b3..57bd91eae 100644 --- a/server/api/login.go +++ b/server/api/login.go @@ -297,54 +297,3 @@ func GetLogout(c *gin.Context) { httputil.DelCookie(c.Writer, c.Request, "user_last") c.Redirect(http.StatusSeeOther, server.Config.Server.RootPath+"/") } - -// TODO: remove in 3.0 -func DeprecatedGetLoginToken(c *gin.Context) { - _store := store.FromContext(c) - - _forge, err := server.Config.Services.Manager.ForgeByID(1) - if err != nil { - log.Error().Err(err).Msg("Cannot get main forge") - c.AbortWithStatus(http.StatusInternalServerError) - return - } - - in := &tokenPayload{} - err = c.Bind(in) - if err != nil { - _ = c.AbortWithError(http.StatusBadRequest, err) - return - } - - login, err := _forge.Auth(c, in.Access, in.Refresh) - if err != nil { - _ = c.AbortWithError(http.StatusUnauthorized, err) - return - } - - user, err := _store.GetUserLogin(login) - if err != nil { - handleDBError(c, err) - return - } - - exp := time.Now().Add(server.Config.Server.SessionExpires).Unix() - newToken := token.New(token.SessToken) - newToken.Set("user-id", strconv.FormatInt(user.ID, 10)) - tokenStr, err := newToken.SignExpires(user.Hash, exp) - if err != nil { - _ = c.AbortWithError(http.StatusInternalServerError, err) - return - } - - c.JSON(http.StatusOK, &tokenPayload{ - Access: tokenStr, - Expires: exp - time.Now().Unix(), - }) -} - -type tokenPayload struct { - Access string `json:"access_token,omitempty"` - Refresh string `json:"refresh_token,omitempty"` - Expires int64 `json:"expires_in,omitempty"` -} diff --git a/server/router/api.go b/server/router/api.go index 3fb760760..a7c9f8f5e 100644 --- a/server/router/api.go +++ b/server/router/api.go @@ -129,13 +129,6 @@ func apiRoutes(e *gin.RouterGroup) { repo.PATCH("/registries/:registry", session.MustPush, api.PatchRegistry) repo.DELETE("/registries/:registry", session.MustPush, api.DeleteRegistry) - // TODO: remove with 3.x - repo.GET("/registry", session.MustPush, api.GetRegistryList) - repo.POST("/registry", session.MustPush, api.PostRegistry) - repo.GET("/registry/:registry", session.MustPush, api.GetRegistry) - repo.PATCH("/registry/:registry", session.MustPush, api.PatchRegistry) - repo.DELETE("/registry/:registry", session.MustPush, api.DeleteRegistry) - // requires push permissions repo.GET("/cron", session.MustPush, api.GetCronList) repo.POST("/cron", session.MustPush, api.PostCron) diff --git a/server/router/router.go b/server/router/router.go index 89e1046f9..c873062d3 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -62,7 +62,6 @@ func Load(noRouteHandler http.HandlerFunc, middleware ...gin.HandlerFunc) http.H { auth.GET("", api.HandleAuth) auth.POST("", api.HandleAuth) - auth.POST("/token", api.DeprecatedGetLoginToken) } base.GET("/metrics", metrics.PromHandler()) diff --git a/server/services/config/http.go b/server/services/config/http.go index 3eb512cd4..33dcfc756 100644 --- a/server/services/config/http.go +++ b/server/services/config/http.go @@ -38,10 +38,9 @@ type configData struct { } type requestStructure struct { - Repo *model.Repo `json:"repo"` - Pipeline *model.Pipeline `json:"pipeline"` - Netrc *model.Netrc `json:"netrc"` - Configuration []*configData `json:"configs"` // TODO: deprecate in favor of netrc and remove in next major release + Repo *model.Repo `json:"repo"` + Pipeline *model.Pipeline `json:"pipeline"` + Netrc *model.Netrc `json:"netrc"` } type responseStructure struct { @@ -53,11 +52,6 @@ func NewHTTP(endpoint string, privateKey ed25519.PrivateKey) Service { } func (h *http) Fetch(ctx context.Context, forge forge.Forge, user *model.User, repo *model.Repo, pipeline *model.Pipeline, oldConfigData []*types.FileMeta, _ bool) ([]*types.FileMeta, error) { - currentConfigs := make([]*configData, len(oldConfigData)) - for i, pipe := range oldConfigData { - currentConfigs[i] = &configData{Name: pipe.Name, Data: string(pipe.Data)} - } - netrc, err := forge.Netrc(user, repo) if err != nil { return nil, fmt.Errorf("could not get Netrc data from forge: %w", err) @@ -65,10 +59,9 @@ func (h *http) Fetch(ctx context.Context, forge forge.Forge, user *model.User, r response := new(responseStructure) body := requestStructure{ - Repo: repo, - Pipeline: pipeline, - Configuration: currentConfigs, - Netrc: netrc, + Repo: repo, + Pipeline: pipeline, + Netrc: netrc, } status, err := utils.Send(ctx, net_http.MethodPost, h.endpoint, h.privateKey, body, response)