forked from openshift/geard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extend.go
53 lines (47 loc) · 1.24 KB
/
extend.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// +build linux
package linux
import (
"log"
"github.com/openshift/geard/config"
gjobs "github.com/openshift/geard/git/jobs"
"github.com/openshift/geard/jobs"
"github.com/openshift/geard/systemd"
)
// Return a job extension that casts requests directly to jobs
// TODO: Move implementation out of request object and into a
// specific package
func NewGitExtension() jobs.JobExtension {
return &jobs.JobInitializer{
Extension: jobs.JobExtensionFunc(implementsJob),
Func: initGit,
}
}
func implementsJob(request interface{}) (jobs.Job, error) {
switch r := request.(type) {
case *gjobs.CreateRepositoryRequest:
conn, err := systemd.NewConnection()
if err != nil {
log.Print("create_repository:", err)
return nil, err
}
return &createRepository{r, conn}, nil
case *gjobs.GitArchiveContentRequest:
return &archiveRepository{r}, nil
}
return nil, jobs.ErrNoJobForRequest
}
// All git jobs depend on these invariants.
// TODO: refactor jobs to take systemd and config
// as injected dependencies
func initGit() error {
if err := config.HasRequiredDirectories(); err != nil {
return err
}
if err := systemd.Start(); err != nil {
return err
}
if err := InitializeServices(); err != nil {
return err
}
return nil
}