Skip to content

Commit d8ddf06

Browse files
committed
resolve #22
1 parent 5345947 commit d8ddf06

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
_ "github.com/picostack/pico/logger"
1515
"github.com/picostack/pico/service"
16+
"github.com/picostack/pico/task"
1617
)
1718

1819
var version = "master"
@@ -38,6 +39,8 @@ this repository has new commits, Pico will automatically reconfigure.`,
3839
Usage: "argument `target` specifies Git repository for configuration.",
3940
ArgsUsage: "target",
4041
Flags: []cli.Flag{
42+
cli.StringFlag{Name: "git-username", EnvVar: "GIT_USERNAME"},
43+
cli.StringFlag{Name: "git-password", EnvVar: "GIT_PASSWORD"},
4144
cli.StringFlag{Name: "hostname", EnvVar: "HOSTNAME"},
4245
cli.StringFlag{Name: "directory", EnvVar: "DIRECTORY", Value: "./cache/"},
4346
cli.BoolFlag{Name: "ssh", EnvVar: "SSH"},
@@ -68,7 +71,11 @@ this repository has new commits, Pico will automatically reconfigure.`,
6871
zap.L().Debug("initialising service")
6972

7073
svc, err := service.Initialise(service.Config{
71-
Target: c.Args().First(),
74+
Target: task.Repo{
75+
URL: c.Args().First(),
76+
User: c.String("git-username"),
77+
Pass: c.String("git-password"),
78+
},
7279
Hostname: hostname,
7380
Directory: c.String("directory"),
7481
SSH: c.Bool("ssh"),

reconfigurer/git.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type GitProvider struct {
2323
hostname string
2424
configRepo string
2525
checkInterval time.Duration
26-
ssh transport.AuthMethod
26+
authMethod transport.AuthMethod
2727

2828
configWatcher *gitwatch.Session
2929
}
@@ -34,14 +34,14 @@ func New(
3434
hostname string,
3535
configRepo string,
3636
checkInterval time.Duration,
37-
ssh transport.AuthMethod,
37+
authMethod transport.AuthMethod,
3838
) *GitProvider {
3939
return &GitProvider{
4040
directory: directory,
4141
hostname: hostname,
4242
configRepo: configRepo,
4343
checkInterval: checkInterval,
44-
ssh: ssh,
44+
authMethod: authMethod,
4545
}
4646
}
4747

@@ -104,7 +104,7 @@ func (p *GitProvider) watchConfig() (err error) {
104104
[]gitwatch.Repository{{URL: p.configRepo}},
105105
p.checkInterval,
106106
p.directory,
107-
p.ssh,
107+
p.authMethod,
108108
false)
109109
if err != nil {
110110
return errors.Wrap(err, "failed to watch config target")

service/service.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go.uber.org/zap"
1313
"golang.org/x/sync/errgroup"
1414
"gopkg.in/src-d/go-git.v4/plumbing/transport"
15+
"gopkg.in/src-d/go-git.v4/plumbing/transport/http"
1516
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
1617

1718
"github.com/picostack/pico/executor"
@@ -25,7 +26,7 @@ import (
2526

2627
// Config specifies static configuration parameters (from CLI or environment)
2728
type Config struct {
28-
Target string
29+
Target task.Repo
2930
Hostname string
3031
SSH bool
3132
Directory string
@@ -57,6 +58,11 @@ func Initialise(c Config) (app *App, err error) {
5758
if err != nil {
5859
return nil, errors.Wrap(err, "failed to set up SSH authentication")
5960
}
61+
} else if c.Target.User != "" {
62+
authMethod = &http.BasicAuth{
63+
Username: c.Target.User,
64+
Password: c.Target.Pass,
65+
}
6066
}
6167

6268
var secretStore secret.Store
@@ -85,7 +91,7 @@ func Initialise(c Config) (app *App, err error) {
8591
app.reconfigurer = reconfigurer.New(
8692
c.Directory,
8793
c.Hostname,
88-
c.Target,
94+
c.Target.URL,
8995
c.CheckInterval,
9096
authMethod,
9197
)

task/target.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ type ExecutionTask struct {
1515
Env map[string]string
1616
}
1717

18+
// Repo represents a Git repo with credentials
19+
type Repo struct {
20+
URL string
21+
User string
22+
Pass string
23+
}
24+
1825
// Targets is just a list of target objects, to implement the Sort interface
1926
type Targets []Target
2027

0 commit comments

Comments
 (0)