HeaderHasMinimumScopes parses the comma separated scopesHeader string and returns an error if it lacks the minimum required scopes for performing API operations with gh.
(scopesHeader string)
| 70 | // HeaderHasMinimumScopes parses the comma separated scopesHeader string and returns an error |
| 71 | // if it lacks the minimum required scopes for performing API operations with gh. |
| 72 | func HeaderHasMinimumScopes(scopesHeader string) error { |
| 73 | if scopesHeader == "" { |
| 74 | // if the token reports no scopes, assume that it's an integration token and give up on |
| 75 | // detecting its capabilities |
| 76 | return nil |
| 77 | } |
| 78 | |
| 79 | search := map[string]bool{ |
| 80 | "repo": false, |
| 81 | "read:org": false, |
| 82 | "admin:org": false, |
| 83 | } |
| 84 | for s := range strings.SplitSeq(scopesHeader, ",") { |
| 85 | search[strings.TrimSpace(s)] = true |
| 86 | } |
| 87 | |
| 88 | var missingScopes []string |
| 89 | if !search["repo"] { |
| 90 | missingScopes = append(missingScopes, "repo") |
| 91 | } |
| 92 | |
| 93 | if !search["read:org"] && !search["write:org"] && !search["admin:org"] { |
| 94 | missingScopes = append(missingScopes, "read:org") |
| 95 | } |
| 96 | |
| 97 | if len(missingScopes) > 0 { |
| 98 | return &MissingScopesError{MissingScopes: missingScopes} |
| 99 | } |
| 100 | return nil |
| 101 | } |
no outgoing calls