allow organizational prefixes
This commit is contained in:
parent
077d37df7a
commit
5fe473bf74
|
@ -120,9 +120,16 @@ A repo my have its own `.gitdeploy/deploy.sh` at its root, but by default these
|
||||||
You can set `--trust-repos` (or `TRUST_REPOS`) to allow deploy scripts to be run directly
|
You can set `--trust-repos` (or `TRUST_REPOS`) to allow deploy scripts to be run directly
|
||||||
from a repository.
|
from a repository.
|
||||||
|
|
||||||
|
- matches are case-insensitive (`foo` matches `Foo`)
|
||||||
|
- a wildcard `*` may be used (at the end of a string) to define a prefix
|
||||||
|
- the list may be space `' '` or comman `,` delimited
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# trust a few repos to run their own deploy scripts
|
# trust a few repos to run their own deploy scripts
|
||||||
gitdeploy run --listen :3000 --trust-repos 'github.com/org/one,github.com/org/two'
|
gitdeploy run --listen :3000 --trust-repos 'github.com/org/one github.com/org/two'
|
||||||
|
|
||||||
|
# trust an organization
|
||||||
|
gitdeploy run --listen :3000 --trust-repos 'github.com/org/*'
|
||||||
|
|
||||||
# trust all repos
|
# trust all repos
|
||||||
gitdeploy run --listen :3000 --trust-repos '*'
|
gitdeploy run --listen :3000 --trust-repos '*'
|
||||||
|
|
20
main.go
20
main.go
|
@ -169,6 +169,7 @@ func main() {
|
||||||
if len(runOpts.RepoList) > 0 {
|
if len(runOpts.RepoList) > 0 {
|
||||||
runOpts.RepoList = strings.ReplaceAll(runOpts.RepoList, ",", " ")
|
runOpts.RepoList = strings.ReplaceAll(runOpts.RepoList, ",", " ")
|
||||||
runOpts.RepoList = strings.ReplaceAll(runOpts.RepoList, " ", " ")
|
runOpts.RepoList = strings.ReplaceAll(runOpts.RepoList, " ", " ")
|
||||||
|
runOpts.RepoList = strings.ToLower(runOpts.RepoList)
|
||||||
}
|
}
|
||||||
if 0 == len(promotionList) {
|
if 0 == len(promotionList) {
|
||||||
promotionList = os.Getenv("PROMOTIONS")
|
promotionList = os.Getenv("PROMOTIONS")
|
||||||
|
@ -314,9 +315,7 @@ func serve() {
|
||||||
r.Get("/repos", func(w http.ResponseWriter, r *http.Request) {
|
r.Get("/repos", func(w http.ResponseWriter, r *http.Request) {
|
||||||
repos := []Repo{}
|
repos := []Repo{}
|
||||||
|
|
||||||
for _, id := range strings.Fields(
|
for _, id := range strings.Fields(runOpts.RepoList) {
|
||||||
strings.ReplaceAll(runOpts.RepoList, ",", " "),
|
|
||||||
) {
|
|
||||||
repos = append(repos, Repo{
|
repos = append(repos, Repo{
|
||||||
ID: id,
|
ID: id,
|
||||||
CloneURL: fmt.Sprintf("https://%s.git", id),
|
CloneURL: fmt.Sprintf("https://%s.git", id),
|
||||||
|
@ -509,7 +508,20 @@ func runHook(hook webhooks.Ref) {
|
||||||
"GIT_CLONE_URL=" + hook.HTTPSURL,
|
"GIT_CLONE_URL=" + hook.HTTPSURL,
|
||||||
}
|
}
|
||||||
for _, repo := range strings.Fields(runOpts.RepoList) {
|
for _, repo := range strings.Fields(runOpts.RepoList) {
|
||||||
if "*" == repo || repo == repoID {
|
last := len(repo) - 1
|
||||||
|
if len(repo) < 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
repoID = strings.ToLower(repoID)
|
||||||
|
if '*' == repo[last] {
|
||||||
|
// Wildcard match a prefix, for example:
|
||||||
|
// github.com/whatever/* MATCHES github.com/whatever/foo
|
||||||
|
// github.com/whatever/ProjectX-* MATCHES github.com/whatever/ProjectX-Foo
|
||||||
|
if strings.HasPrefix(repoID, repo[:last]) {
|
||||||
|
envs = append(envs, "GIT_REPO_TRUSTED=true")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
} else if repo == repoID {
|
||||||
envs = append(envs, "GIT_REPO_TRUSTED=true")
|
envs = append(envs, "GIT_REPO_TRUSTED=true")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue