MCPcopy Create free account
hub / github.com/crashappsec/github-analyzer / parsePermissions

Function parsePermissions

pkg/output/html/html.go:142–191  ·  view source on GitHub ↗
(
	permJson string,
)

Source from the content-addressed store, hash-verified

140}
141
142func parsePermissions(
143 permJson string,
144) ([]string, []string, map[string]map[string]string, error) {
145 type userRepoPermissions map[string]([]string)
146 var permissionSummary map[string]userRepoPermissions
147
148 jsonFile, err := os.Open(permJson)
149 defer jsonFile.Close()
150 if err != nil {
151 return nil, nil, nil, err
152 }
153 jsonBytes, _ := ioutil.ReadAll(jsonFile)
154 json.Unmarshal(jsonBytes, &permissionSummary)
155
156 allPerms := map[string]bool{}
157 allUsers := map[string]bool{}
158 for u, perms := range permissionSummary {
159 allUsers[u] = true
160 for perm := range perms {
161 allPerms[perm] = true
162 }
163 }
164 var permissions []string
165 for p := range allPerms {
166 permissions = append(permissions, p)
167 }
168 var users []string
169 for p := range allUsers {
170 users = append(users, p)
171 }
172 sort.Strings(permissions)
173 sort.Strings(users)
174
175 finalSummary := map[string]map[string]string{}
176 /// Make sure we fill everything up
177 for _, u := range users {
178 finalSummary[u] = map[string]string{}
179 for _, perm := range permissions {
180 _, ok := permissionSummary[u][perm]
181 if !ok {
182 finalSummary[u][perm] = ""
183 } else {
184 sort.Strings(permissionSummary[u][perm])
185 finalSummary[u][perm] = strings.Join(permissionSummary[u][perm], ", ")
186 }
187 }
188 }
189
190 return permissions, users, finalSummary, nil
191}
192
193func parseIssues(
194 execStatusPath, issuesPath string,

Callers 1

ServeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected