Compare commits
No commits in common. "4b4bc9792b21e1bc37c9876f628e4636a9ad23cd" and "3747f02ed84cf1a166067b02330fefcab9e442d5" have entirely different histories.
4b4bc9792b
...
3747f02ed8
@ -147,7 +147,6 @@ func runServer(ctx *cli.Context) error {
|
|||||||
defaultCsp := ctx.String("default-csp")
|
defaultCsp := ctx.String("default-csp")
|
||||||
lokiUrl := ctx.String("loki-url")
|
lokiUrl := ctx.String("loki-url")
|
||||||
metricsBotList := ctx.String("metrics-bot-list")
|
metricsBotList := ctx.String("metrics-bot-list")
|
||||||
tokenFile := ctx.String("token-file")
|
|
||||||
|
|
||||||
// Init Logging
|
// Init Logging
|
||||||
if ctx.Bool("debug") {
|
if ctx.Bool("debug") {
|
||||||
@ -178,28 +177,18 @@ func runServer(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If specified, read in an access token
|
|
||||||
token := ""
|
|
||||||
if tokenFile != "" {
|
|
||||||
t, err := readSecret(tokenFile)
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("Failed to read secret: %v", err)
|
|
||||||
}
|
|
||||||
token = t
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup the Gitea stuff
|
// Setup the Gitea stuff
|
||||||
httpClient := http.Client{Timeout: 10 * time.Second}
|
httpClient := http.Client{Timeout: 10 * time.Second}
|
||||||
giteaApiClient, err := gitea.NewClient(
|
giteaApiClient, err := gitea.NewClient(
|
||||||
giteaUrl,
|
giteaUrl,
|
||||||
gitea.SetHTTPClient(&httpClient),
|
gitea.SetHTTPClient(&httpClient),
|
||||||
gitea.SetToken(token),
|
gitea.SetToken(""),
|
||||||
gitea.SetUserAgent("rio"),
|
gitea.SetUserAgent("rio"),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
giteaClient := riogitea.NewGiteaClient(giteaUrl, token, giteaApiClient)
|
giteaClient := riogitea.NewGiteaClient(giteaUrl, giteaApiClient)
|
||||||
|
|
||||||
// Listen on the port
|
// Listen on the port
|
||||||
addr := ctx.String("listen-host") + ":" + ctx.String("listen-port")
|
addr := ctx.String("listen-host") + ":" + ctx.String("listen-port")
|
||||||
@ -210,6 +199,16 @@ func runServer(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Listen on the HTTP port
|
||||||
|
httpAddr := ctx.String("http-host") + ":" + ctx.String("http-port")
|
||||||
|
httpListener, err := net.Listen("tcp", httpAddr)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(
|
||||||
|
fmt.Errorf("Failed to create HTTP listener: %v", err),
|
||||||
|
)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare the context
|
// Prepare the context
|
||||||
cacheCtx := context.CacheContext{
|
cacheCtx := context.CacheContext{
|
||||||
RepositoryInformationCache: context.MakeRepoInfoCache(),
|
RepositoryInformationCache: context.MakeRepoInfoCache(),
|
||||||
@ -292,7 +291,7 @@ func runServer(ctx *cli.Context) error {
|
|||||||
go func() {
|
go func() {
|
||||||
defer waitGroup.Done()
|
defer waitGroup.Done()
|
||||||
|
|
||||||
log.Infof("Listening on main HTTP server %s", addr)
|
log.Infof("Listening on main HTTP server %s", httpAddr)
|
||||||
if err := http.Serve(listener, Handler(globalCtx)); err != nil {
|
if err := http.Serve(listener, Handler(globalCtx)); err != nil {
|
||||||
log.Fatal(fmt.Errorf("Listening failed: %v", err))
|
log.Fatal(fmt.Errorf("Listening failed: %v", err))
|
||||||
}
|
}
|
||||||
@ -300,16 +299,6 @@ func runServer(ctx *cli.Context) error {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
if !acmeDisable {
|
if !acmeDisable {
|
||||||
// Listen on the HTTP port
|
|
||||||
httpAddr := ctx.String("http-host") + ":" + ctx.String("http-port")
|
|
||||||
httpListener, err := net.Listen("tcp", httpAddr)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println(
|
|
||||||
fmt.Errorf("Failed to create HTTP listener: %v", err),
|
|
||||||
)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer waitGroup.Done()
|
defer waitGroup.Done()
|
||||||
|
|
||||||
@ -425,12 +414,6 @@ func main() {
|
|||||||
Value: "",
|
Value: "",
|
||||||
EnvVars: []string{"METRICS_BOT_LIST"},
|
EnvVars: []string{"METRICS_BOT_LIST"},
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "token-file",
|
|
||||||
Usage: "File containing a access token. Required for serving private repositories",
|
|
||||||
Value: "",
|
|
||||||
EnvVars: []string{"TOKEN_FILE"},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,16 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Read a secret file and return its (cleaned) content.
|
|
||||||
func readSecret(path string) (string, error) {
|
|
||||||
content, err := os.ReadFile(path)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Trim(string(content), "\n\r "), nil
|
|
||||||
}
|
|
@ -7,7 +7,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"git.polynom.me/rio/internal/dns"
|
"git.polynom.me/rio/internal/dns"
|
||||||
)
|
)
|
||||||
@ -39,8 +38,6 @@ type Repository struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GiteaClient struct {
|
type GiteaClient struct {
|
||||||
Token string
|
|
||||||
|
|
||||||
GetRepository GetRepositoryMethod
|
GetRepository GetRepositoryMethod
|
||||||
HasBranch HasBranchMethod
|
HasBranch HasBranchMethod
|
||||||
HasUser HasUserMethod
|
HasUser HasUserMethod
|
||||||
@ -49,9 +46,8 @@ type GiteaClient struct {
|
|||||||
LookupRepoTXT LookupRepoTXTMethod
|
LookupRepoTXT LookupRepoTXTMethod
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGiteaClient(giteaUrl string, token string, giteaClient *gitea.Client) GiteaClient {
|
func NewGiteaClient(giteaUrl string, giteaClient *gitea.Client) GiteaClient {
|
||||||
return GiteaClient{
|
return GiteaClient{
|
||||||
Token: token,
|
|
||||||
GetRepository: func(username, repositoryName string) (Repository, error) {
|
GetRepository: func(username, repositoryName string) (Repository, error) {
|
||||||
repo, _, err := giteaClient.GetRepo(username, repositoryName)
|
repo, _, err := giteaClient.GetRepo(username, repositoryName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -90,19 +86,12 @@ func NewGiteaClient(giteaUrl string, token string, giteaClient *gitea.Client) Gi
|
|||||||
path,
|
path,
|
||||||
branch,
|
branch,
|
||||||
)
|
)
|
||||||
log.Debugf("GetFile: Requesting '%s'", apiUrl)
|
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
req, err := http.NewRequest("GET", apiUrl, nil)
|
req, err := http.NewRequest("GET", apiUrl, nil)
|
||||||
if since != nil {
|
if since != nil {
|
||||||
sinceFormat := since.Format(time.RFC1123)
|
sinceFormat := since.Format(time.RFC1123)
|
||||||
req.Header.Add("If-Modified-Since", sinceFormat)
|
req.Header.Add("If-Modified-Since", sinceFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add authentication, if we have a token
|
|
||||||
if token != "" {
|
|
||||||
req.Header.Add("Authorization", "token "+token)
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, true, err
|
return []byte{}, true, err
|
||||||
|
Loading…
Reference in New Issue
Block a user