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