MCPcopy Create free account
hub / github.com/cli/cli / HeaderHasMinimumScopes

Function HeaderHasMinimumScopes

pkg/cmd/auth/shared/oauth_scopes.go:81–110  ·  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

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

Callers 3

StringMethod · 0.92
HasMinimumScopesFunction · 0.85

Calls

no outgoing calls

Tested by 1