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")
|
||||
lokiUrl := ctx.String("loki-url")
|
||||
metricsBotList := ctx.String("metrics-bot-list")
|
||||
tokenFile := ctx.String("token-file")
|
||||
|
||||
// Init Logging
|
||||
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
|
||||
httpClient := http.Client{Timeout: 10 * time.Second}
|
||||
giteaApiClient, err := gitea.NewClient(
|
||||
giteaUrl,
|
||||
gitea.SetHTTPClient(&httpClient),
|
||||
gitea.SetToken(token),
|
||||
gitea.SetToken(""),
|
||||
gitea.SetUserAgent("rio"),
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
giteaClient := riogitea.NewGiteaClient(giteaUrl, token, giteaApiClient)
|
||||
giteaClient := riogitea.NewGiteaClient(giteaUrl, giteaApiClient)
|
||||
|
||||
// Listen on the port
|
||||
addr := ctx.String("listen-host") + ":" + ctx.String("listen-port")
|
||||
@ -210,6 +199,16 @@ func runServer(ctx *cli.Context) error {
|
||||
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
|
||||
cacheCtx := context.CacheContext{
|
||||
RepositoryInformationCache: context.MakeRepoInfoCache(),
|
||||
@ -292,7 +291,7 @@ func runServer(ctx *cli.Context) error {
|
||||
go func() {
|
||||
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 {
|
||||
log.Fatal(fmt.Errorf("Listening failed: %v", err))
|
||||
}
|
||||
@ -300,16 +299,6 @@ func runServer(ctx *cli.Context) error {
|
||||
}()
|
||||
|
||||
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() {
|
||||
defer waitGroup.Done()
|
||||
|
||||
@ -425,12 +414,6 @@ func main() {
|
||||
Value: "",
|
||||
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"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"git.polynom.me/rio/internal/dns"
|
||||
)
|
||||
@ -39,8 +38,6 @@ type Repository struct {
|
||||
}
|
||||
|
||||
type GiteaClient struct {
|
||||
Token string
|
||||
|
||||
GetRepository GetRepositoryMethod
|
||||
HasBranch HasBranchMethod
|
||||
HasUser HasUserMethod
|
||||
@ -49,9 +46,8 @@ type GiteaClient struct {
|
||||
LookupRepoTXT LookupRepoTXTMethod
|
||||
}
|
||||
|
||||
func NewGiteaClient(giteaUrl string, token string, giteaClient *gitea.Client) GiteaClient {
|
||||
func NewGiteaClient(giteaUrl string, giteaClient *gitea.Client) GiteaClient {
|
||||
return GiteaClient{
|
||||
Token: token,
|
||||
GetRepository: func(username, repositoryName string) (Repository, error) {
|
||||
repo, _, err := giteaClient.GetRepo(username, repositoryName)
|
||||
if err != nil {
|
||||
@ -90,19 +86,12 @@ func NewGiteaClient(giteaUrl string, token string, giteaClient *gitea.Client) Gi
|
||||
path,
|
||||
branch,
|
||||
)
|
||||
log.Debugf("GetFile: Requesting '%s'", apiUrl)
|
||||
client := &http.Client{}
|
||||
req, err := http.NewRequest("GET", apiUrl, nil)
|
||||
if since != nil {
|
||||
sinceFormat := since.Format(time.RFC1123)
|
||||
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)
|
||||
if err != nil {
|
||||
return []byte{}, true, err
|
||||
|
Loading…
Reference in New Issue
Block a user