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

Function GetEngineSecretNameAndValue

pkg/cli/engine_secrets.go:531–575  ·  view source on GitHub ↗

GetEngineSecretNameAndValue returns the secret name and value for an engine. It checks if the secret exists in the repository and retrieves the value from environment if needed. Returns: secretName, secretValue (empty if exists in repo or not in env), existsInRepo, error

(engine string, existingSecrets map[string]struct{})

Source from the content-addressed store, hash-verified

529// It checks if the secret exists in the repository and retrieves the value from environment if needed.
530// Returns: secretName, secretValue (empty if exists in repo or not in env), existsInRepo, error
531func GetEngineSecretNameAndValue(engine string, existingSecrets map[string]struct{}) (string, string, bool, error) {
532 engineSecretsLog.Printf("Getting secret name and value for engine: %s", engine)
533
534 opt := constants.GetEngineOption(engine)
535 if opt == nil {
536 return "", "", false, fmt.Errorf("unknown engine: %s", engine)
537 }
538
539 secretName := opt.SecretName
540
541 // Check if secret already exists in repository
542 if setutil.Contains(existingSecrets, secretName) {
543 engineSecretsLog.Printf("Secret %s already exists in repository", secretName)
544 return secretName, "", true, nil
545 }
546
547 // Check alternative secret names in repository
548 for _, alt := range opt.AlternativeSecrets {
549 if setutil.Contains(existingSecrets, alt) {
550 engineSecretsLog.Printf("Alternative secret %s exists in repository", alt)
551 return secretName, "", true, nil
552 }
553 }
554
555 // Get value from environment variable
556 // Use EnvVarName if specified, otherwise use SecretName
557 envVar := opt.SecretName
558 if opt.EnvVarName != "" {
559 envVar = opt.EnvVarName
560 }
561
562 value := os.Getenv(envVar)
563 if value == "" {
564 // Check alternative environment variables
565 for _, alt := range opt.AlternativeSecrets {
566 value = os.Getenv(alt)
567 if value != "" {
568 engineSecretsLog.Printf("Found secret in alternative env var: %s", alt)
569 break
570 }
571 }
572 }
573
574 return secretName, value, false, nil
575}
576
577// displayMissingSecrets shows information about missing secrets with setup instructions
578func displayMissingSecrets(requirements []SecretRequirement, repoSlug string, existingSecrets map[string]struct {

Calls 5

GetEngineOptionFunction · 0.92
ContainsFunction · 0.92
GetenvMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1