[CI-SKIP] Upload current
This commit is contained in:
@@ -10,52 +10,42 @@ import (
|
||||
"git.nevets.tech/Steven/certman/common"
|
||||
)
|
||||
|
||||
func WriteCommitHash(hash, dataRoot string) error {
|
||||
//TODO: unfuck this logic, maybe use a domain struct with a flag for non-standard data root?
|
||||
//var dataRoot string
|
||||
//if domainConfig.Certificates.DataRoot == "" {
|
||||
// dataRoot = filepath.Join(config.Certificates.DataRoot, "certificates", domainConfig.Domain.DomainName)
|
||||
//} else {
|
||||
// dataRoot = domainConfig.Certificates.DataRoot
|
||||
//}
|
||||
// hashFile is the filename inside a domain's local data root that records
|
||||
// the last remote commit SHA the client successfully synced from. The daemon
|
||||
// compares it against the remote HEAD to decide whether a sync is needed.
|
||||
const hashFile = "hash"
|
||||
|
||||
err := os.WriteFile(filepath.Join(dataRoot, "hash"), []byte(hash), 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// defaultBranch is the branch the client tracks on the remote repo.
|
||||
const defaultBranch = "master"
|
||||
|
||||
return nil
|
||||
// WriteCommitHash persists hash to <certsDir>/hash. Call it after a
|
||||
// successful sync so the next tick can skip a no-op.
|
||||
func WriteCommitHash(certsDir, hash string) error {
|
||||
return os.WriteFile(filepath.Join(certsDir, hashFile), []byte(hash), 0o644)
|
||||
}
|
||||
|
||||
func LocalCommitHash(domain string, certsDir string) (string, error) {
|
||||
data, err := os.ReadFile(filepath.Join(certsDir, "hash"))
|
||||
// LocalCommitHash returns the commit SHA recorded at <certsDir>/hash. A
|
||||
// missing file is not an error: it returns "" so a fresh client falls
|
||||
// through to the full sync path.
|
||||
func LocalCommitHash(certsDir string) (string, error) {
|
||||
data, err := os.ReadFile(filepath.Join(certsDir, hashFile))
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Printf("Error reading file for domain %s: %v\n", domain, err)
|
||||
return "", err
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return "", nil
|
||||
}
|
||||
return "", fmt.Errorf("read hash file: %w", err)
|
||||
}
|
||||
|
||||
return strings.TrimSpace(string(data)), nil
|
||||
}
|
||||
|
||||
func RemoteCommitHash(domain string, gitSource common.GitSource, config *common.AppConfig, domainConfig *common.DomainConfig) (string, error) {
|
||||
switch gitSource {
|
||||
case common.Gitea:
|
||||
return getRemoteCommitHashGitea(config.Git.OrgName, domain+domainConfig.Repo.RepoSuffix, "master", config)
|
||||
default:
|
||||
fmt.Printf("Unimplemented git source %v\n", gitSource)
|
||||
return "", errors.New("unimplemented git source")
|
||||
}
|
||||
}
|
||||
|
||||
func getRemoteCommitHashGitea(org, repo, branchName string, config *common.AppConfig) (string, error) {
|
||||
giteaClient := common.CreateGiteaClient(config)
|
||||
branch, _, err := giteaClient.GetRepoBranch(org, repo, branchName)
|
||||
// RemoteCommitHash returns the current HEAD commit SHA of the domain's repo
|
||||
// on the configured git host. It returns common.ErrRepoNotFound if the repo
|
||||
// does not exist yet, letting the daemon handle the "not provisioned" case
|
||||
// without string-matching errors.
|
||||
func RemoteCommitHash(config *common.AppConfig, domainConfig *common.DomainConfig, domain string) (string, error) {
|
||||
provider, err := common.ProviderFor(config)
|
||||
if err != nil {
|
||||
fmt.Printf("Error getting repo branch: %v\n", err)
|
||||
return "", err
|
||||
}
|
||||
//TODO catch repo not found as ErrRepoNotInit
|
||||
return branch.Commit.ID, nil
|
||||
return provider.HeadCommit(domain, defaultBranch, domainConfig)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user