verify.go

v1.0.0
Doc Versions Source
1
package store
2
3
import (
4
	"context"
5
	"fmt"
6
	"os/exec"
7
	"regexp"
8
	"time"
9
)
10
11
// VerifyModule checks that a git repository is accessible via git ls-remote.
12
func VerifyModule(repo string, timeout time.Duration) error {
13
	ctx, cancel := context.WithTimeout(context.Background(), timeout)
14
	defer cancel()
15
16
	cmd := exec.CommandContext(ctx, "git", "ls-remote", "--exit-code", repo)
17
	output, err := cmd.CombinedOutput()
18
	if err != nil {
19
		return fmt.Errorf("git ls-remote failed for %s: %s: %w", repo, string(output), err)
20
	}
21
	return nil
22
}
23
24
// VerifyPattern checks that a regex pattern compiles.
25
func VerifyPattern(pattern string) error {
26
	_, err := regexp.Compile("^" + pattern + "$")
27
	if err != nil {
28
		return fmt.Errorf("invalid regex pattern %q: %w", pattern, err)
29
	}
30
	return nil
31
}
32

Source Files