-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
114 lines (108 loc) · 3.49 KB
/
runner.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"cuddly-eureka-/appconstants"
"cuddly-eureka-/conf/initialize"
"cuddly-eureka-/github"
"cuddly-eureka-/output/csv"
"cuddly-eureka-/types"
"fmt"
"path/filepath"
"plugin"
)
var (
appConstants appconstants.Constants
)
func getRepos(token string, owner string) []github.RepoLanguageDetails {
repoLanguageDetails := make([]github.RepoLanguageDetails, 0)
if appConstants.ScanAllGitHub {
fmt.Println("Info: Configuration to scan all github set to TRUE .. Will scan all repos for " + owner)
g := &github.GitHub{}
g = g.Init(token)
repoNames, rErr := g.GetAuthenticatedUserRepos()
if rErr != nil {
panic("Failed to fetch the repo names. Check token." + rErr.Error())
}
fmt.Printf("Fetched %d repos for %s\n", len(repoNames), owner)
repoLanguageDetails = g.GetRepoLanguages(repoNames, owner)
} else {
fmt.Println("Info: Configuration to scan all github set to FALSE .. Will not scan github for " + owner)
if appConstants.MaturityRepoDetails != nil {
for _, b := range *appConstants.MaturityRepoDetails {
d := github.RepoLanguageDetails{
Name: b.Name,
Languages: []string{},
ECR: b.ECR,
AWS: b.AWS,
CodeCov: appconstants.CodeCov{Bearer: b.CodeCov.Bearer},
}
repoLanguageDetails = append(repoLanguageDetails, d)
}
}
}
return repoLanguageDetails
}
func write(data [][]string, repoName string) {
headers := make([]string, 0)
headers = append(headers, "Type", "Name", "Maturity Value")
filename := repoName + "_out.csv"
dir := "gen_csv"
csv.Generate(headers, data, filename, &dir)
fmt.Printf("Generated %s 📝\n", filename)
}
func main() {
matches, _ := filepath.Glob(filepath.Join("assets", "plugins", "*.so"))
appConstants = initialize.GetAppConstants()
repos := getRepos(appConstants.GitHubToken, appConstants.GitHubOwner)
for _, repo := range repos {
repoMaturityValues := make([][]string, 0)
for _, pluginFilePath := range matches {
pluginResult := make([]string, 0)
/**
Load all the plugins and run for each repo
*/
plug, plugErr := plugin.Open(pluginFilePath)
if plugErr != nil {
panic(plugErr)
}
symbol, sErr := plug.Lookup("Check")
if sErr != nil {
panic(sErr)
}
var maturity types.Maturity
maturity, ok := symbol.(types.Maturity)
if !ok {
panic("Type mismatch")
}
/**
Now we extract the ProductVersion and cast that into the
new type which is distinct but derives from the ProductVersion
*/
maturityMeta := maturity.Meta()
var maturityValue types.MaturityCheck
var maturityInput string
var opts = make([]*string, 0)
if maturityMeta.EcrType {
if len(repo.ECR) > 0 {
maturityInput = repo.ECR
} else {
fmt.Println("Warning: ECR value not supplied for " + repo.Name)
maturityInput = ""
}
} else if maturityMeta.Type == types.MaturityObservability {
maturityInput = repo.AWS.LogGroup + "_" + repo.AWS.LogStream
if len(repo.AWS.CWLQuery) > 0 {
opts = append(opts, &repo.AWS.CWLQuery)
}
} else if maturityMeta.CodeCovType == true {
maturityInput = fmt.Sprintf("%s_%s_%s_%s", repo.Name, appConstants.GitHubOwner, "github", repo.CodeCov.Bearer)
} else {
maturityInput = repo.Name
}
maturityValue = maturity.Check(maturityInput, opts...)
mappedMValue := types.MValueToString(maturityValue)
pluginResult = append(pluginResult, maturityMeta.Type, maturityMeta.Name, mappedMValue)
repoMaturityValues = append(repoMaturityValues, pluginResult)
}
write(repoMaturityValues, repo.Name)
}
}