chore: Format
This commit is contained in:
parent
1154eff9ae
commit
85bd71cff3
@ -5,8 +5,8 @@ import (
|
|||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"crypto/elliptic"
|
"crypto/elliptic"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
"encoding/json"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/go-acme/lego/v4/acme"
|
"github.com/go-acme/lego/v4/acme"
|
||||||
@ -61,7 +61,6 @@ func ClientFromFile(storage, acmeServer string) (*lego.Client, error) {
|
|||||||
contacts = append(contacts, v.(string))
|
contacts = append(contacts, v.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
registration := registration.Resource{
|
registration := registration.Resource{
|
||||||
URI: reg["uri"].(string),
|
URI: reg["uri"].(string),
|
||||||
Body: acme.Account{
|
Body: acme.Account{
|
||||||
|
6
acme.go
6
acme.go
@ -74,7 +74,7 @@ type CertificateWrapper struct {
|
|||||||
|
|
||||||
func (c *CertificateWrapper) GetPrivateKey() *rsa.PrivateKey {
|
func (c *CertificateWrapper) GetPrivateKey() *rsa.PrivateKey {
|
||||||
data, _ := base64.StdEncoding.DecodeString(c.PrivateKeyEncoded)
|
data, _ := base64.StdEncoding.DecodeString(c.PrivateKeyEncoded)
|
||||||
pk, _ := certcrypto.ParsePEMPrivateKey(data);
|
pk, _ := certcrypto.ParsePEMPrivateKey(data)
|
||||||
|
|
||||||
return pk.(*rsa.PrivateKey)
|
return pk.(*rsa.PrivateKey)
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ func fallbackCert(pagesDomain string) (*CertificateWrapper, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
notAfter := time.Now().Add(time.Hour*24*7);
|
notAfter := time.Now().Add(time.Hour * 24 * 7)
|
||||||
cert := x509.Certificate{
|
cert := x509.Certificate{
|
||||||
SerialNumber: big.NewInt(1),
|
SerialNumber: big.NewInt(1),
|
||||||
Subject: pkix.Name{
|
Subject: pkix.Name{
|
||||||
@ -222,7 +222,7 @@ func isCertStillValid(cert CertificateWrapper) bool {
|
|||||||
func makeTlsConfig(pagesDomain, path string, acmeClient *lego.Client) *tls.Config {
|
func makeTlsConfig(pagesDomain, path string, acmeClient *lego.Client) *tls.Config {
|
||||||
return &tls.Config{
|
return &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
GetCertificate: func (info *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
GetCertificate: func(info *tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||||
// Validate that we should even care about this domain
|
// Validate that we should even care about this domain
|
||||||
if !strings.HasSuffix(info.ServerName, pagesDomain) {
|
if !strings.HasSuffix(info.ServerName, pagesDomain) {
|
||||||
// Note: We do not check err here because err != nil
|
// Note: We do not check err here because err != nil
|
||||||
|
4
dns.go
4
dns.go
@ -14,8 +14,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cnameCache = cache.New(1 * time.Hour, 1 * time.Hour)
|
cnameCache = cache.New(1*time.Hour, 1*time.Hour)
|
||||||
txtRepoCache = cache.New(1 * time.Hour, 1 * time.Hour)
|
txtRepoCache = cache.New(1*time.Hour, 1*time.Hour)
|
||||||
)
|
)
|
||||||
|
|
||||||
func lookupRepoTXT(domain string) (string, error) {
|
func lookupRepoTXT(domain string) (string, error) {
|
||||||
|
7
main.go
7
main.go
@ -2,18 +2,18 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"os"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/sdk/gitea"
|
"code.gitea.io/sdk/gitea"
|
||||||
"github.com/urfave/cli/v2"
|
|
||||||
"github.com/go-acme/lego/v4/challenge/http01"
|
"github.com/go-acme/lego/v4/challenge/http01"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -35,7 +35,6 @@ func handleSubdomain(domain string, cname string, path, giteaUrl string, giteaCl
|
|||||||
cname,
|
cname,
|
||||||
path,
|
path,
|
||||||
giteaClient,
|
giteaClient,
|
||||||
|
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to get repo: %s", err)
|
log.Errorf("Failed to get repo: %s", err)
|
||||||
@ -50,7 +49,7 @@ func Handler(pagesDomain, giteaUrl string, giteaClient *gitea.Client) http.Handl
|
|||||||
return func(w http.ResponseWriter, req *http.Request) {
|
return func(w http.ResponseWriter, req *http.Request) {
|
||||||
w.Header().Set("Server", "rio")
|
w.Header().Set("Server", "rio")
|
||||||
|
|
||||||
if strings.HasSuffix(req.Host, pagesDomain){
|
if strings.HasSuffix(req.Host, pagesDomain) {
|
||||||
if handleLetsEncryptChallenge(w, req) {
|
if handleLetsEncryptChallenge(w, req) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
4
pages.go
4
pages.go
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pageCache = cache.New(6 * time.Hour, 1 * time.Hour)
|
pageCache = cache.New(6*time.Hour, 1*time.Hour)
|
||||||
)
|
)
|
||||||
|
|
||||||
type PageContentCache struct {
|
type PageContentCache struct {
|
||||||
@ -98,7 +98,7 @@ func serveFile(username, reponame, path, giteaUrl string, w http.ResponseWriter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pathParts := strings.Split(path, ".")
|
pathParts := strings.Split(path, ".")
|
||||||
ext := pathParts[len(pathParts) - 1]
|
ext := pathParts[len(pathParts)-1]
|
||||||
mimeType = mime.TypeByExtension("." + ext)
|
mimeType = mime.TypeByExtension("." + ext)
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
15
repo.go
15
repo.go
@ -11,10 +11,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pathCache = cache.New(1 * time.Hour, 1 * time.Hour)
|
pathCache = cache.New(1*time.Hour, 1*time.Hour)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
type PageCacheEntry struct {
|
type PageCacheEntry struct {
|
||||||
Repository *gitea.Repository
|
Repository *gitea.Repository
|
||||||
Path string
|
Path string
|
||||||
@ -24,10 +23,10 @@ func makePageCacheKey(domain, path string) string {
|
|||||||
return domain + "/" + path
|
return domain + "/" + path
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to find the repository with name @reponame of the user @username. If @cname
|
// / Try to find the repository with name @reponame of the user @username. If @cname
|
||||||
/// is not "", then it also verifies that the repository contains a "CNAME" with
|
// / is not "", then it also verifies that the repository contains a "CNAME" with
|
||||||
/// the value of @cname as its content. @host, @domain, and @path are passed for
|
// / the value of @cname as its content. @host, @domain, and @path are passed for
|
||||||
/// caching on success.
|
// / caching on success.
|
||||||
func lookupRepositoryAndCache(username, reponame, host, domain, path, cname string, giteaClient *gitea.Client) (*gitea.Repository, error) {
|
func lookupRepositoryAndCache(username, reponame, host, domain, path, cname string, giteaClient *gitea.Client) (*gitea.Repository, error) {
|
||||||
log.Debugf("Looking up repository %s/%s", username, reponame)
|
log.Debugf("Looking up repository %s/%s", username, reponame)
|
||||||
repo, _, err := giteaClient.GetRepo(username, reponame)
|
repo, _, err := giteaClient.GetRepo(username, reponame)
|
||||||
@ -113,9 +112,9 @@ func RepoFromPath(username, host, cname, path string, giteaClient *gitea.Client)
|
|||||||
repoLookup,
|
repoLookup,
|
||||||
)
|
)
|
||||||
reponame = repoLookup
|
reponame = repoLookup
|
||||||
} else if (cname != "") {
|
} else if cname != "" {
|
||||||
// Allow naming the repository "example.org" (But give the TXT record preference)
|
// Allow naming the repository "example.org" (But give the TXT record preference)
|
||||||
reponame = cname;
|
reponame = cname
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Trying repository %s/%s", username, reponame)
|
log.Debugf("Trying repository %s/%s", username, reponame)
|
||||||
|
Loading…
Reference in New Issue
Block a user