MCPcopy Index your code
hub / github.com/cli/cli / HeaderHasMinimumScopes

Function HeaderHasMinimumScopes

pkg/cmd/auth/shared/oauth_scopes.go:77–106  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
77func 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}

Callers 3

StringMethod · 0.92
HasMinimumScopesFunction · 0.85

Calls

no outgoing calls

Tested by 1