Lots of progress
This commit is contained in:
28
git.go
28
git.go
@@ -1,15 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/google/go-github/v55/github"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/sdk/gitea"
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/google/go-github/v55/github"
|
||||
)
|
||||
|
||||
func createGithubClient() *github.Client {
|
||||
@@ -49,13 +50,14 @@ func createGithubRepo(domain *Domain, client *github.Client) string {
|
||||
}
|
||||
|
||||
func createGiteaRepo() string {
|
||||
domainConfig := getDomainConfig(domain)
|
||||
options := gitea.CreateRepoFromTemplateOption{
|
||||
Avatar: true,
|
||||
Description: "Certificates storage for " + domain,
|
||||
GitContent: true,
|
||||
GitHooks: true,
|
||||
Labels: true,
|
||||
Name: domain + "-certificates",
|
||||
Name: domain + domainConfig.GetAsString("Repo.repo_suffix"),
|
||||
Owner: config.GetAsString("Git.org_name"),
|
||||
Private: true,
|
||||
Topics: true,
|
||||
@@ -85,19 +87,19 @@ func cloneRepo(url string) (*git.Repository, *git.Worktree) {
|
||||
}
|
||||
|
||||
func addAndPushCerts() {
|
||||
certs, err := os.ReadDir(config.GetAsString("Certificates.certs_path") + "/certificates")
|
||||
certFiles, err := os.ReadDir(config.GetAsString("Certificates.certs_path") + "/certificates")
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading from directory: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
for _, cert := range certs {
|
||||
if strings.HasPrefix(cert.Name(), domain) {
|
||||
file, err := fs.Create(cert.Name())
|
||||
for _, file := range certFiles {
|
||||
if strings.HasPrefix(file.Name(), domain) {
|
||||
file, err := fs.Create(file.Name())
|
||||
if err != nil {
|
||||
fmt.Printf("Error copying cert to memfs: %v\n", err)
|
||||
fmt.Printf("Error copying file to memfs: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
certFile, err := os.ReadFile(config.GetAsString("Certificates.certs_path") + "/certificates/" + cert.Name())
|
||||
certFile, err := os.ReadFile(config.GetAsString("Certificates.certs_path") + "/certificates/" + file.Name())
|
||||
//certFile = encryptBytes(certFile)
|
||||
_, err = file.Write(certFile)
|
||||
err = file.Close()
|
||||
@@ -105,9 +107,9 @@ func addAndPushCerts() {
|
||||
fmt.Printf("Error writing to memfs: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
_, err = workTree.Add(cert.Name())
|
||||
_, err = workTree.Add(file.Name())
|
||||
if err != nil {
|
||||
fmt.Printf("Error adding certificate %v: %v", cert.Name(), err)
|
||||
fmt.Printf("Error adding file %v: %v", file.Name(), err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user