Skip to content

Commit

Permalink
Removed users to significantly simplify implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
beefsack committed May 7, 2015
1 parent 784b619 commit 1d86e91
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git-mirror
12 changes: 0 additions & 12 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type duration struct {
type config struct {
ListenAddr string
Interval duration
Users []string
BasePath string
Repo []repo
}
Expand All @@ -26,8 +25,6 @@ type repo struct {
Name string
Origin string
Interval duration
Private bool
Users []string
}

func (d *duration) UnmarshalText(text []byte) (err error) {
Expand All @@ -54,9 +51,6 @@ func parseConfig(filename string) (cfg config, repos map[string]repo, err error)
if cfg.Interval.Duration == 0 {
cfg.Interval.Duration = 15 * time.Minute
}
if cfg.Users == nil {
cfg.Users = []string{}
}
if cfg.BasePath == "" {
cfg.BasePath = "."
}
Expand Down Expand Up @@ -95,12 +89,6 @@ func parseConfig(filename string) (cfg config, repos map[string]repo, err error)
if r.Interval.Duration == 0 {
r.Interval.Duration = cfg.Interval.Duration
}
if r.Private {
if r.Users == nil {
r.Users = []string{}
}
r.Users = append(r.Users, cfg.Users...)
}
repos[r.Name] = r
}
return
Expand Down
26 changes: 8 additions & 18 deletions example-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ ListenAddr = ":8080"
# Interval is the default interval for updating mirrors, can be overridden per
# repo. Defaults to 15 minutes.
Interval = "15m"
# Top level users have access to all private repos.
Users = [
"bob the admin:crazy-password",
]
# Base path for storing mirrors, absolute or relative. Defaults to "."
BasePath = "/tmp/mirror"

Expand All @@ -18,27 +14,21 @@ BasePath = "/tmp/mirror"
[[Repo]]
Origin = "https://github.com/beefsack/git-mirror.git"

# An example of a private repo with users having access. "bob the admin" also
# has access to this repo.
#
# Will be mirrored at http://localhost:8080/github.com/neovim/neovim.git
[[Repo]]
Origin = "https://github.com/neovim/neovim.git"
Private = true
Interval = "10m"
Users = [
"mary:some-other-password"
]

# Repos whose Origin is not a URL is simplified to the last part after any @
# symbol with any : symbol converted to a /
#
# Will be mirrored at http://localhost:8080/github.com/toml-lang-toml.git
[[Repo]]
Origin = "[email protected]:toml-lang/toml.git"

# It is also possible to set custom names for accessing the repos. This is
# required for remotes not using URL schemes.
# Repos can specify their own Interval to override the global setting.
#
# Will be mirrored at http://localhost:8080/github.com/neovim/neovim.git
[[Repo]]
Origin = "https://github.com/neovim/neovim.git"
Interval = "10m"

# It is also possible to set custom names for accessing the repos.
#
# Will be mirrored at http://localhost:8080/custom-name
[[Repo]]
Expand Down
33 changes: 0 additions & 33 deletions http.go

This file was deleted.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func main() {
}

// Run HTTP server to serve mirrors.
http.HandleFunc("/", handler(cfg, repos))
http.Handle("/", http.FileServer(http.Dir(cfg.BasePath)))
log.Printf("starting web server on %s", cfg.ListenAddr)
if err := http.ListenAndServe(cfg.ListenAddr, nil); err != nil {
log.Fatalf("failed to start server, %s", err)
Expand Down

0 comments on commit 1d86e91

Please sign in to comment.