security fixes and branch listing

This commit is contained in:
crapStone 2021-05-05 11:53:27 +02:00
parent fc73cc3156
commit ea3c106944
Signed by: crapStone
GPG Key ID: 0E1380C01B1D51B8
2 changed files with 16 additions and 8 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/vendor
.idea/
.cache.json

23
main.go
View File

@ -16,11 +16,11 @@ var (
)

type Cache struct {
token string `json:token`
baseURL string `json:baseURL`
orgName string `json:orgName`
repoExclude string `json:repoExclude`
pullBaseBranch string `json:pullBaseBranch`
token string `json:"token"`
baseURL string `json:"baseURL"`
orgName string `json:"orgName"`
repoExclude string `json:"repoExclude"`
pullBaseBranch string `json:"pullBaseBranch"`
}

func loadCache() (cache *Cache) {
@ -49,7 +49,7 @@ func saveCache(cache *Cache) {
if err != nil {
fmt.Printf("ERROR: marshal cache: %v\n", err)
}
err = ioutil.WriteFile(".cache.json", data, 0666)
err = ioutil.WriteFile(".cache.json", data, 0600)
if err != nil {
fmt.Printf("ERROR: save cache: %v\n", err)
}
@ -102,8 +102,9 @@ func main() {

var repoList []*gitlab.Project
var page = 1
fmt.Printf("Retrieving repository list...\n")
for {
fmt.Printf("Get Repo List Page %d", page)
fmt.Printf("%d", page)
repos, _, err := client.Groups.ListGroupProjects(org.ID, &gitlab.ListGroupProjectsOptions{
ListOptions: gitlab.ListOptions{PerPage: 10, Page: page},
Archived: optBool(false),
@ -121,6 +122,7 @@ func main() {

page++
}
fmt.Println()

for i := range repoList {
if !excludeRule.Match(repoList[i].Name) {
@ -140,7 +142,12 @@ func threatRepo(baseBranchRule glob.Glob, client *gitlab.Client, repo *gitlab.Pr
error(10, "Could not obtain branch list from '%s': %v\n", repo.Name, err)
}

fmt.Printf(" found %d branches\n", len(branchList))
fmt.Printf(" found %d branches:", len(branchList))
fmt.Printf(" ")
for _, b := range branchList {
fmt.Printf("'%s' ", b.Name)
}
fmt.Println()

for _, baseBranch := range branchList {
if baseBranchRule.Match(baseBranch.Name) && !baseBranch.Default {