Skip to content

Commit f7ed1cd

Browse files
authored
Merge branch 'master' into prunehooktask
2 parents 14b6bef + 0f726ca commit f7ed1cd

File tree

787 files changed

+61712
-24951
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

787 files changed

+61712
-24951
lines changed

.drone.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ steps:
6969

7070
- name: checks-backend
7171
pull: always
72-
image: golang:1.14
72+
image: golang:1.15
7373
commands:
7474
- make checks-backend
7575
depends_on: [lint-backend]
@@ -82,7 +82,7 @@ steps:
8282

8383
- name: build-backend-no-gcc
8484
pull: always
85-
image: golang:1.13 # this step is kept as the lowest version of golang that we support
85+
image: golang:1.14 # this step is kept as the lowest version of golang that we support
8686
environment:
8787
GO111MODULE: on
8888
GOPROXY: off

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ issues:
7070
- path: modules/log/
7171
linters:
7272
- errcheck
73-
- path: routers/routes/macaron.go
73+
- path: routers/routes/web.go
7474
linters:
7575
- dupl
7676
- path: routers/api/v1/repo/issue_subscription.go

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
2525
COMMA := ,
2626

2727
XGO_VERSION := go-1.15.x
28-
MIN_GO_VERSION := 001013000
28+
MIN_GO_VERSION := 001014000
2929
MIN_NODE_VERSION := 010013000
3030

3131
DOCKER_IMAGE ?= gitea/gitea

cmd/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"code.gitea.io/gitea/modules/storage"
2222
"code.gitea.io/gitea/modules/util"
2323

24-
"gitea.com/macaron/session"
24+
"gitea.com/go-chi/session"
2525
archiver "github.com/mholt/archiver/v3"
2626
"github.com/urfave/cli"
2727
)

cmd/web.go

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
context2 "github.com/gorilla/context"
2424
"github.com/urfave/cli"
25-
"golang.org/x/crypto/acme/autocert"
2625
ini "gopkg.in/ini.v1"
2726
)
2827

@@ -72,36 +71,6 @@ func runHTTPRedirector() {
7271
}
7372
}
7473

75-
func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler) error {
76-
certManager := autocert.Manager{
77-
Prompt: autocert.AcceptTOS,
78-
HostPolicy: autocert.HostWhitelist(domain),
79-
Cache: autocert.DirCache(directory),
80-
Email: email,
81-
}
82-
go func() {
83-
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
84-
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
85-
var err = runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, certManager.HTTPHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
86-
if err != nil {
87-
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
88-
}
89-
}()
90-
return runHTTPSWithTLSConfig("tcp", listenAddr, certManager.TLSConfig(), context2.ClearHandler(m))
91-
}
92-
93-
func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
94-
if r.Method != "GET" && r.Method != "HEAD" {
95-
http.Error(w, "Use HTTPS", http.StatusBadRequest)
96-
return
97-
}
98-
// Remove the trailing slash at the end of setting.AppURL, the request
99-
// URI always contains a leading slash, which would result in a double
100-
// slash
101-
target := strings.TrimSuffix(setting.AppURL, "/") + r.URL.RequestURI()
102-
http.Redirect(w, r, target, http.StatusFound)
103-
}
104-
10574
func runWeb(ctx *cli.Context) error {
10675
managerCtx, cancel := context.WithCancel(context.Background())
10776
graceful.InitManager(managerCtx)
@@ -133,8 +102,7 @@ func runWeb(ctx *cli.Context) error {
133102
return err
134103
}
135104
}
136-
c := routes.NewChi()
137-
routes.RegisterInstallRoute(c)
105+
c := routes.InstallRoutes()
138106
err := listen(c, false)
139107
select {
140108
case <-graceful.GetManager().IsShutdown():
@@ -165,11 +133,9 @@ func runWeb(ctx *cli.Context) error {
165133
return err
166134
}
167135
}
168-
// Set up Chi routes
169-
c := routes.NewChi()
170-
c.Mount("/", routes.NormalRoutes())
171-
routes.DelegateToMacaron(c)
172136

137+
// Set up Chi routes
138+
c := routes.NormalRoutes()
173139
err := listen(c, true)
174140
<-graceful.GetManager().Done()
175141
log.Info("PID: %d Gitea Web Finished", os.Getpid())

cmd/web_letsencrypt.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2020 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package cmd
6+
7+
import (
8+
"net/http"
9+
"strings"
10+
11+
"code.gitea.io/gitea/modules/log"
12+
"code.gitea.io/gitea/modules/setting"
13+
14+
"github.com/caddyserver/certmagic"
15+
context2 "github.com/gorilla/context"
16+
)
17+
18+
func runLetsEncrypt(listenAddr, domain, directory, email string, m http.Handler) error {
19+
20+
// If HTTP Challenge enabled, needs to be serving on port 80. For TLSALPN needs 443.
21+
// Due to docker port mapping this can't be checked programatically
22+
// TODO: these are placeholders until we add options for each in settings with appropriate warning
23+
enableHTTPChallenge := true
24+
enableTLSALPNChallenge := true
25+
26+
magic := certmagic.NewDefault()
27+
magic.Storage = &certmagic.FileStorage{Path: directory}
28+
myACME := certmagic.NewACMEManager(magic, certmagic.ACMEManager{
29+
Email: email,
30+
Agreed: setting.LetsEncryptTOS,
31+
DisableHTTPChallenge: !enableHTTPChallenge,
32+
DisableTLSALPNChallenge: !enableTLSALPNChallenge,
33+
})
34+
35+
magic.Issuer = myACME
36+
37+
// this obtains certificates or renews them if necessary
38+
err := magic.ManageSync([]string{domain})
39+
if err != nil {
40+
return err
41+
}
42+
43+
tlsConfig := magic.TLSConfig()
44+
45+
if enableHTTPChallenge {
46+
go func() {
47+
log.Info("Running Let's Encrypt handler on %s", setting.HTTPAddr+":"+setting.PortToRedirect)
48+
// all traffic coming into HTTP will be redirect to HTTPS automatically (LE HTTP-01 validation happens here)
49+
var err = runHTTP("tcp", setting.HTTPAddr+":"+setting.PortToRedirect, myACME.HTTPChallengeHandler(http.HandlerFunc(runLetsEncryptFallbackHandler)))
50+
if err != nil {
51+
log.Fatal("Failed to start the Let's Encrypt handler on port %s: %v", setting.PortToRedirect, err)
52+
}
53+
}()
54+
}
55+
56+
return runHTTPSWithTLSConfig("tcp", listenAddr, tlsConfig, context2.ClearHandler(m))
57+
}
58+
59+
func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
60+
if r.Method != "GET" && r.Method != "HEAD" {
61+
http.Error(w, "Use HTTPS", http.StatusBadRequest)
62+
return
63+
}
64+
// Remove the trailing slash at the end of setting.AppURL, the request
65+
// URI always contains a leading slash, which would result in a double
66+
// slash
67+
target := strings.TrimSuffix(setting.AppURL, "/") + r.URL.RequestURI()
68+
http.Redirect(w, r, target, http.StatusFound)
69+
}

contrib/pr/checkout.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ func runPR() {
116116
//routers.GlobalInit()
117117
external.RegisterParsers()
118118
markup.Init()
119-
c := routes.NewChi()
120-
c.Mount("/", routes.NormalRoutes())
121-
routes.DelegateToMacaron(c)
119+
c := routes.NormalRoutes()
122120

123121
log.Printf("[PR] Ready for testing !\n")
124122
log.Printf("[PR] Login with user1, user2, user3, ... with pass: password\n")

docs/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ params:
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
2121
version: 1.13.1
22-
minGoVersion: 1.13
22+
minGoVersion: 1.14
2323
goVersion: 1.15
2424
minNodeVersion: 10.13
2525

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
549549

550550
## Session (`session`)
551551

552-
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, mysql, couchbase, memcache, nodb, postgres\].
552+
- `PROVIDER`: **memory**: Session engine provider \[memory, file, redis, mysql, couchbase, memcache, postgres\].
553553
- `PROVIDER_CONFIG`: **data/sessions**: For file, the root path; for others, the connection string.
554554
- `COOKIE_SECURE`: **false**: Enable this to force using HTTPS for all session access.
555555
- `COOKIE_NAME`: **i\_like\_gitea**: The name of the cookie used for the session ID.
@@ -609,16 +609,14 @@ Default templates for project boards:
609609
- `MODE`: **console**: Logging mode. For multiple modes, use a comma to separate values. You can configure each mode in per mode log subsections `\[log.modename\]`. By default the file mode will log to `$ROOT_PATH/gitea.log`.
610610
- `LEVEL`: **Info**: General log level. \[Trace, Debug, Info, Warn, Error, Critical, Fatal, None\]
611611
- `STACKTRACE_LEVEL`: **None**: Default log level at which to log create stack traces. \[Trace, Debug, Info, Warn, Error, Critical, Fatal, None\]
612-
- `REDIRECT_MACARON_LOG`: **false**: Redirects the Macaron log to its own logger or the default logger.
613-
- `MACARON`: **file**: Logging mode for the macaron logger, use a comma to separate values. Configure each mode in per mode log subsections `\[log.modename.macaron\]`. By default the file mode will log to `$ROOT_PATH/macaron.log`. (If you set this to `,` it will log to default gitea logger.)
614612
- `ROUTER_LOG_LEVEL`: **Info**: The log level that the router should log at. (If you are setting the access log, its recommended to place this at Debug.)
615613
- `ROUTER`: **console**: The mode or name of the log the router should log to. (If you set this to `,` it will log to default gitea logger.)
616614
NB: You must `REDIRECT_MACARON_LOG` and have `DISABLE_ROUTER_LOG` set to `false` for this option to take effect. Configure each mode in per mode log subsections `\[log.modename.router\]`.
617615
- `ENABLE_ACCESS_LOG`: **false**: Creates an access.log in NCSA common log format, or as per the following template
618616
- `ACCESS`: **file**: Logging mode for the access logger, use a comma to separate values. Configure each mode in per mode log subsections `\[log.modename.access\]`. By default the file mode will log to `$ROOT_PATH/access.log`. (If you set this to `,` it will log to the default gitea logger.)
619617
- `ACCESS_LOG_TEMPLATE`: **`{{.Ctx.RemoteAddr}} - {{.Identity}} {{.Start.Format "[02/Jan/2006:15:04:05 -0700]" }} "{{.Ctx.Req.Method}} {{.Ctx.Req.URL.RequestURI}} {{.Ctx.Req.Proto}}" {{.ResponseWriter.Status}} {{.ResponseWriter.Size}} "{{.Ctx.Req.Referer}}\" \"{{.Ctx.Req.UserAgent}}"`**: Sets the template used to create the access log.
620618
- The following variables are available:
621-
- `Ctx`: the `macaron.Context` of the request.
619+
- `Ctx`: the `context.Context` of the request.
622620
- `Identity`: the SignedUserName or `"-"` if not logged in.
623621
- `Start`: the start time of the request.
624622
- `ResponseWriter`: the responseWriter from the request.

docs/content/doc/advanced/logging-documentation.en-us.md

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,40 +67,11 @@ The provider type of the sublogger can be set using the `MODE` value in
6767
its subsection, but will default to the name. This allows you to have
6868
multiple subloggers that will log to files.
6969

70-
### The "Macaron" logger
71-
72-
By default Macaron will log to its own go `log` instance. This writes
73-
to `os.Stdout`. You can redirect this log to a Gitea configurable logger
74-
through setting the `REDIRECT_MACARON_LOG` setting in the `[log]`
75-
section which you can configure the outputs of by setting the `MACARON`
76-
value in the `[log]` section of the configuration. `MACARON` defaults
77-
to `file` if unset.
78-
79-
Please note, the macaron logger will log at `INFO` level, setting the
80-
`LEVEL` of this logger to `WARN` or above will result in no macaron logs.
81-
82-
Each output sublogger for this logger is configured in
83-
`[log.sublogger.macaron]` sections. There are certain default values
84-
which will not be inherited from the `[log]` or relevant
85-
`[log.sublogger]` sections:
86-
87-
- `FLAGS` is `stdflags` (Equal to
88-
`date,time,medfile,shortfuncname,levelinitial`)
89-
- `FILE_NAME` will default to `%(ROOT_PATH)/macaron.log`
90-
- `EXPRESSION` will default to `""`
91-
- `PREFIX` will default to `""`
92-
93-
NB: You can redirect the macaron logger to send its events to the gitea
94-
log using the value: `MACARON = ,`
95-
9670
### The "Router" logger
9771

98-
There are two types of Router log. By default Macaron send its own
99-
router log which will be directed to Macaron's go `log`, however if you
100-
`REDIRECT_MACARON_LOG` you will enable Gitea's router log. You can
101-
disable both types of Router log by setting `DISABLE_ROUTER_LOG`.
72+
You can disable Router log by setting `DISABLE_ROUTER_LOG`.
10273

103-
If you enable the redirect, you can configure the outputs of this
74+
You can configure the outputs of this
10475
router log by setting the `ROUTER` value in the `[log]` section of the
10576
configuration. `ROUTER` will default to `console` if unset. The Gitea
10677
Router logs the same data as the Macaron log but has slightly different
@@ -162,11 +133,11 @@ This value represent a go template. It's default value is:
162133

163134
The template is passed following options:
164135

165-
- `Ctx` is the `macaron.Context`
136+
- `Ctx` is the `context.Context`
166137
- `Identity` is the `SignedUserName` or `"-"` if the user is not logged
167138
in
168139
- `Start` is the start time of the request
169-
- `ResponseWriter` is the `macaron.ResponseWriter`
140+
- `ResponseWriter` is the `http.ResponseWriter`
170141

171142
Caution must be taken when changing this template as it runs outside of
172143
the standard panic recovery trap. The template should also be as simple

0 commit comments

Comments
 (0)