checkSecretsAvailability checks which secrets are available and where
(secrets []SecretInfo, useActionsSecrets bool)
| 101 | |
| 102 | // checkSecretsAvailability checks which secrets are available and where |
| 103 | func checkSecretsAvailability(secrets []SecretInfo, useActionsSecrets bool) []SecretInfo { |
| 104 | for i := range secrets { |
| 105 | // First check if it's in environment variables |
| 106 | if value := os.Getenv(secrets[i].Name); value != "" { |
| 107 | secrets[i].Available = true |
| 108 | secrets[i].Source = "env" |
| 109 | secrets[i].Value = value |
| 110 | continue |
| 111 | } |
| 112 | |
| 113 | // If --check-secrets flag is enabled, try to fetch from GitHub Actions |
| 114 | if useActionsSecrets { |
| 115 | exists, err := checkSecretExists(secrets[i].Name) |
| 116 | if err != nil { |
| 117 | // If we get a 403 error, skip silently (no permission to check) |
| 118 | if errorutil.IsForbiddenError(err) { |
| 119 | continue |
| 120 | } |
| 121 | } |
| 122 | if exists { |
| 123 | secrets[i].Available = true |
| 124 | secrets[i].Source = "actions" |
| 125 | // Note: We can't actually fetch the secret value from GitHub Actions |
| 126 | // The secret exists but its value is not accessible via gh CLI |
| 127 | continue |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // Secret not available |
| 132 | secrets[i].Available = false |
| 133 | secrets[i].Source = "" |
| 134 | } |
| 135 | |
| 136 | return secrets |
| 137 | } |