MCPcopy Create free account
hub / github.com/github/gh-aw / checkAndSuggestSecrets

Function checkAndSuggestSecrets

pkg/cli/mcp_secrets.go:16–78  ·  view source on GitHub ↗

checkAndSuggestSecrets checks if required secrets exist in the repository and suggests CLI commands to add them

(toolConfig map[string]any, verbose bool)

Source from the content-addressed store, hash-verified

14
15// checkAndSuggestSecrets checks if required secrets exist in the repository and suggests CLI commands to add them
16func checkAndSuggestSecrets(toolConfig map[string]any, verbose bool) error {
17 mcpSecretsLog.Print("Checking and suggesting secrets for MCP tool configuration")
18
19 // Extract environment variables from the tool config
20 var requiredSecrets []string
21
22 if mcpSection, ok := toolConfig["mcp"].(map[string]any); ok {
23 if env, hasEnv := mcpSection["env"].(map[string]string); hasEnv {
24 for _, value := range env {
25 // Extract secret name from GitHub Actions syntax: ${{ secrets.SECRET_NAME }}
26 if strings.HasPrefix(value, "${{ secrets.") && strings.HasSuffix(value, " }}") {
27 secretName := value[12 : len(value)-3] // Remove "${{ secrets." and " }}"
28 requiredSecrets = append(requiredSecrets, secretName)
29 }
30 }
31 }
32 }
33
34 if len(requiredSecrets) == 0 {
35 mcpSecretsLog.Print("No required secrets found in tool configuration")
36 return nil
37 }
38 mcpSecretsLog.Printf("Found %d required secrets in configuration", len(requiredSecrets))
39
40 if verbose {
41 fmt.Fprintln(os.Stderr, console.FormatInfoMessage("Checking repository secrets..."))
42 }
43
44 // Check each secret using GitHub CLI
45 var missingSecrets []string
46 for _, secretName := range requiredSecrets {
47 exists, err := checkSecretExists(secretName)
48 if err != nil {
49 // If we get a 403 error, ignore it as requested
50 if errorutil.IsForbiddenError(err) {
51 if verbose {
52 fmt.Fprintln(os.Stderr, console.FormatWarningMessage("Repository secrets check skipped (insufficient permissions)"))
53 }
54 return nil
55 }
56 return err
57 }
58
59 if !exists {
60 missingSecrets = append(missingSecrets, secretName)
61 }
62 }
63
64 // Suggest CLI commands for missing secrets
65 if len(missingSecrets) > 0 {
66 mcpSecretsLog.Printf("Found %d missing secrets", len(missingSecrets))
67 fmt.Fprintln(os.Stderr, console.FormatWarningMessage("The following secrets are required but not found in the repository:"))
68 for _, secretName := range missingSecrets {
69 fmt.Fprintln(os.Stderr, console.FormatInfoMessage(fmt.Sprintf("To add %s secret:", secretName)))
70 fmt.Fprintln(os.Stderr, console.FormatCommandMessage("gh secret set "+secretName))
71 }
72 } else if verbose {
73 mcpSecretsLog.Print("All required secrets are available in repository")

Callers 3

AddMCPToolFunction · 0.85

Calls 8

FormatInfoMessageFunction · 0.92
IsForbiddenErrorFunction · 0.92
FormatWarningMessageFunction · 0.92
FormatCommandMessageFunction · 0.92
FormatSuccessMessageFunction · 0.92
checkSecretExistsFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45