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