@@ -19,30 +19,54 @@ func PhaseGetContext(userData AppKeyResponse, opts GetContextOptions) (string, s
1919 return "" , "" , "" , fmt .Errorf ("matching context not found" )
2020}
2121
22- // FindEnvironmentKey searches for an environment key with case-insensitive and partial matching.
22+ // FindEnvironmentKey searches for an environment key with case-insensitive matching.
2323func FindEnvironmentKey (userData AppKeyResponse , opts FindEnvironmentKeyOptions ) (* EnvironmentKey , error ) {
24- lcEnvName := strings .ToLower (opts .EnvName )
25- lcAppName := strings .ToLower (opts .AppName )
24+ lcEnvName := strings .ToLower (strings .TrimSpace (opts .EnvName ))
2625
27- for _ , app := range userData . Apps {
28- if ( opts .AppID != "" && app . ID == opts . AppID ) ||
29- ( opts . AppName != "" && ( opts . AppName == "" || strings . Contains ( strings . ToLower ( app . Name ), lcAppName ))) {
26+ // If no app specified, try all apps
27+ if opts .AppName == "" && opts . AppID == "" {
28+ for _ , app := range userData . Apps {
3029 for _ , envKey := range app .EnvironmentKeys {
31- if strings .Contains (strings .ToLower (envKey .Environment .Name ), lcEnvName ) {
30+ if strings .EqualFold (strings .TrimSpace (envKey .Environment .Name ), lcEnvName ) {
3231 return & envKey , nil
3332 }
3433 }
3534 }
35+ } else {
36+ // Check specific app
37+ for _ , app := range userData .Apps {
38+ if (opts .AppID != "" && app .ID == opts .AppID ) ||
39+ (opts .AppName != "" && strings .EqualFold (app .Name , opts .AppName )) {
40+
41+ for _ , envKey := range app .EnvironmentKeys {
42+ if strings .EqualFold (strings .TrimSpace (envKey .Environment .Name ), lcEnvName ) {
43+ return & envKey , nil
44+ }
45+ }
46+ }
47+ }
3648 }
37- return nil , fmt .Errorf ("environment key not found for app '%s' (ID: %s) and environment '%s'" , opts .AppName , opts .AppID , opts .EnvName )
49+
50+ // If exact match not found, try partial matches
51+ for _ , app := range userData .Apps {
52+ for _ , envKey := range app .EnvironmentKeys {
53+ envName := strings .ToLower (strings .TrimSpace (envKey .Environment .Name ))
54+ if strings .Contains (envName , lcEnvName ) {
55+ return & envKey , nil
56+ }
57+ }
58+ }
59+
60+ return nil , fmt .Errorf ("environment key not found for app '%s' (ID: %s) and environment '%s'" ,
61+ opts .AppName , opts .AppID , opts .EnvName )
3862}
3963
4064// normalizeTag replaces underscores with spaces and converts the string to lower case.
4165func normalizeTag (tag string ) string {
4266 return strings .ToLower (strings .Replace (tag , "_" , " " , - 1 ))
4367}
4468
45- // tagMatches checks if the user-provided tag partially matches any of the secret tags.
69+ // TagMatches checks if the user-provided tag partially matches any of the secret tags.
4670func TagMatches (secretTags []string , userTag string ) bool {
4771 normalizedUserTag := normalizeTag (userTag )
4872 for _ , tag := range secretTags {
0 commit comments