Skip to content

Commit 8bbd424

Browse files
committed
Merge remote-tracking branch 'upstream/feature/go-migration' into feature/go-migration
2 parents 1cb1277 + 47a747a commit 8bbd424

8 files changed

Lines changed: 50 additions & 89 deletions

File tree

src/java/common/context.go

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,15 @@ func GetVCAPServices() (VCAPServices, error) {
123123
}
124124

125125
// HasService checks if a service with the given label exists
126+
// Matching is case-insensitive to handle various service broker conventions
126127
func (v VCAPServices) HasService(label string) bool {
127-
_, exists := v[label]
128-
return exists
128+
labelLower := strings.ToLower(label)
129+
for key := range v {
130+
if strings.ToLower(key) == labelLower {
131+
return true
132+
}
133+
}
134+
return false
129135
}
130136

131137
// GetService returns the first service with the given label
@@ -139,11 +145,13 @@ func (v VCAPServices) GetService(label string) *VCAPService {
139145
}
140146

141147
// HasTag checks if any service has the given tag
148+
// Matching is case-insensitive to handle various service broker tag conventions
142149
func (v VCAPServices) HasTag(tag string) bool {
150+
tagLower := strings.ToLower(tag)
143151
for _, serviceList := range v {
144152
for _, service := range serviceList {
145153
for _, t := range service.Tags {
146-
if t == tag {
154+
if strings.ToLower(t) == tagLower {
147155
return true
148156
}
149157
}
@@ -152,30 +160,27 @@ func (v VCAPServices) HasTag(tag string) bool {
152160
return false
153161
}
154162

155-
// HasServiceByNamePattern checks if any service in "user-provided" matches the pattern
156-
// This is needed for Docker platform where services are under "user-provided" label
163+
// HasServiceByNamePattern checks if any service matches the pattern
157164
// Pattern matching is case-insensitive substring matching
165+
// Searches across all service labels, not just "user-provided"
158166
func (v VCAPServices) HasServiceByNamePattern(pattern string) bool {
159167
return v.GetServiceByNamePattern(pattern) != nil
160168
}
161169

162-
// GetServiceByNamePattern returns the first service in "user-provided" that matches the pattern
170+
// GetServiceByNamePattern returns the first service that matches the pattern
163171
// Returns nil if no matching service is found
164172
// Pattern matching is case-insensitive substring matching (e.g., "newrelic" matches "my-newrelic-service")
173+
// Searches across all service labels, not just "user-provided"
165174
func (v VCAPServices) GetServiceByNamePattern(pattern string) *VCAPService {
166-
userProvided, exists := v["user-provided"]
167-
if !exists {
168-
return nil
169-
}
170-
171175
// Case-insensitive substring matching
172176
patternLower := strings.ToLower(pattern)
173-
for _, service := range userProvided {
174-
if strings.Contains(strings.ToLower(service.Name), patternLower) {
175-
return &service
177+
for _, services := range v {
178+
for _, service := range services {
179+
if strings.Contains(strings.ToLower(service.Name), patternLower) {
180+
return &service
181+
}
176182
}
177183
}
178-
179184
return nil
180185
}
181186

src/java/frameworks/elastic_apm_agent.go

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -142,40 +142,23 @@ func (e *ElasticApmAgentFramework) findElasticApmService() *VCAPService {
142142
return nil
143143
}
144144

145-
// Use helper methods for detection
146-
// Elastic APM can be bound as:
147-
// - "elastic-apm" service (marketplace or label)
148-
// - Services with "elastic-apm" or "elastic" tag
149-
// - User-provided services with these patterns in the name (Docker platform)
150-
if vcapServices.HasService("elastic-apm") ||
151-
vcapServices.HasService("elastic") ||
152-
vcapServices.HasTag("elastic-apm") ||
153-
vcapServices.HasTag("elastic") {
154-
// Return first elastic-apm service from any label
155-
for _, services := range vcapServices {
156-
if len(services) > 0 {
157-
// Check if this service has elastic-apm tags or credentials
158-
for _, service := range services {
159-
for _, tag := range service.Tags {
160-
if strings.Contains(strings.ToLower(tag), "elastic") {
161-
return &service
162-
}
163-
}
164-
}
165-
}
166-
}
145+
if vcapServices.HasService("elastic-apm") {
146+
return vcapServices.GetService("elastic-apm")
147+
}
148+
if vcapServices.HasService("elastic") {
149+
return vcapServices.GetService("elastic")
167150
}
168151

169-
// Check user-provided services by name pattern
170-
if vcapServices.HasServiceByNamePattern("elastic-apm") ||
171-
vcapServices.HasServiceByNamePattern("elastic") {
172-
// Look for service with elastic in the name
173-
if userProvided, ok := vcapServices["user-provided"]; ok {
174-
for _, service := range userProvided {
175-
if strings.Contains(strings.ToLower(service.Name), "elastic") {
152+
for _, services := range vcapServices {
153+
for _, service := range services {
154+
for _, tag := range service.Tags {
155+
if common.ContainsIgnoreCase(tag, "elastic-apm") || common.ContainsIgnoreCase(tag, "elastic") {
176156
return &service
177157
}
178158
}
159+
if common.ContainsIgnoreCase(service.Name, "elastic-apm") || common.ContainsIgnoreCase(service.Name, "elastic") {
160+
return &service
161+
}
179162
}
180163
}
181164

src/java/frameworks/luna_security_provider.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,12 @@ func (l *LunaSecurityProviderFramework) writeCredentials() error {
174174
}
175175

176176
// Find Luna service (try multiple lookup patterns)
177-
// VCAPServices is a map[string][]VCAPService where keys are service labels
178177
var credentials map[string]interface{}
179178

180-
// Iterate over all service labels and services
181179
for label, services := range vcapServices {
182180
for _, service := range services {
183-
// Check if service name or label contains "luna"
184-
if strings.Contains(strings.ToLower(service.Name), "luna") ||
185-
strings.Contains(strings.ToLower(label), "luna") {
181+
if common.ContainsIgnoreCase(service.Name, "luna") ||
182+
common.ContainsIgnoreCase(label, "luna") {
186183
credentials = service.Credentials
187184
break
188185
}

src/java/frameworks/maria_db_jdbc.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,12 @@ func (f *MariaDBJDBCFramework) hasMariaDBService() bool {
125125
// Verify the service has a 'uri' credential
126126
for _, services := range vcapServices {
127127
for _, service := range services {
128-
// Check if service name, label, or tags contain "mysql" or "mariadb"
129-
nameMatch := contains(strings.ToLower(service.Name), "mysql") ||
130-
contains(strings.ToLower(service.Name), "mariadb")
128+
nameMatch := common.ContainsIgnoreCase(service.Name, "mysql") ||
129+
common.ContainsIgnoreCase(service.Name, "mariadb")
131130
tagMatch := false
132131

133132
for _, tag := range service.Tags {
134-
tagLower := strings.ToLower(tag)
135-
if contains(tagLower, "mysql") || contains(tagLower, "mariadb") {
133+
if common.ContainsIgnoreCase(tag, "mysql") || common.ContainsIgnoreCase(tag, "mariadb") {
136134
tagMatch = true
137135
break
138136
}

src/java/frameworks/postgresql_jdbc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package frameworks
22

33
import (
4-
"github.com/cloudfoundry/java-buildpack/src/java/common"
54
"fmt"
5+
"github.com/cloudfoundry/java-buildpack/src/java/common"
66
"os"
77
"path/filepath"
8+
"strings"
89

910
"github.com/cloudfoundry/libbuildpack"
1011
)
@@ -107,18 +108,17 @@ func (p *PostgresqlJdbcFramework) hasPostgresService() bool {
107108
for _, services := range vcapServices {
108109
for _, service := range services {
109110
// Check if service name, label, or tags contain "postgres"
110-
nameMatch := contains(service.Name, "postgres")
111-
labelMatch := false
111+
nameMatch := strings.Contains(strings.ToLower(service.Name), "postgres")
112112
tagMatch := false
113113

114114
for _, tag := range service.Tags {
115-
if contains(tag, "postgres") {
115+
if strings.Contains(strings.ToLower(tag), "postgres") {
116116
tagMatch = true
117117
break
118118
}
119119
}
120120

121-
if nameMatch || labelMatch || tagMatch {
121+
if nameMatch || tagMatch {
122122
if _, hasURI := service.Credentials["uri"]; hasURI {
123123
return true
124124
}

src/java/frameworks/protect_app_security_provider.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -308,36 +308,30 @@ func (p *ProtectAppSecurityProviderFramework) findProtectAppService() (map[strin
308308
return nil, fmt.Errorf("failed to parse VCAP_SERVICES: %w", err)
309309
}
310310

311-
// Search for service with "protectapp" in name, label, or tags
312311
for serviceType, serviceList := range services {
313-
// Check if service type contains "protectapp"
314-
if strings.Contains(strings.ToLower(serviceType), "protectapp") {
312+
if common.ContainsIgnoreCase(serviceType, "protectapp") {
315313
if len(serviceList) > 0 {
316314
return serviceList[0], nil
317315
}
318316
}
319317

320-
// Check individual services
321318
for _, service := range serviceList {
322-
// Check service name
323319
if name, ok := service["name"].(string); ok {
324-
if strings.Contains(strings.ToLower(name), "protectapp") {
320+
if common.ContainsIgnoreCase(name, "protectapp") {
325321
return service, nil
326322
}
327323
}
328324

329-
// Check service label
330325
if label, ok := service["label"].(string); ok {
331-
if strings.Contains(strings.ToLower(label), "protectapp") {
326+
if common.ContainsIgnoreCase(label, "protectapp") {
332327
return service, nil
333328
}
334329
}
335330

336-
// Check service tags
337331
if tags, ok := service["tags"].([]interface{}); ok {
338332
for _, tag := range tags {
339333
if tagStr, ok := tag.(string); ok {
340-
if strings.Contains(strings.ToLower(tagStr), "protectapp") {
334+
if common.ContainsIgnoreCase(tagStr, "protectapp") {
341335
return service, nil
342336
}
343337
}

src/java/frameworks/seeker_security_provider.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net/http"
99
"os"
1010
"path/filepath"
11-
"strings"
1211

1312
"github.com/cloudfoundry/libbuildpack"
1413
)
@@ -186,36 +185,30 @@ func (s *SeekerSecurityProviderFramework) findSeekerService() (map[string]interf
186185
return nil, fmt.Errorf("failed to parse VCAP_SERVICES: %w", err)
187186
}
188187

189-
// Search for service with "seeker" in name, label, or tags
190188
for serviceType, serviceList := range services {
191-
// Check if service type contains "seeker"
192-
if strings.Contains(strings.ToLower(serviceType), "seeker") {
189+
if common.ContainsIgnoreCase(serviceType, "seeker") {
193190
if len(serviceList) > 0 {
194191
return serviceList[0], nil
195192
}
196193
}
197194

198-
// Check individual services
199195
for _, service := range serviceList {
200-
// Check service name
201196
if name, ok := service["name"].(string); ok {
202-
if strings.Contains(strings.ToLower(name), "seeker") {
197+
if common.ContainsIgnoreCase(name, "seeker") {
203198
return service, nil
204199
}
205200
}
206201

207-
// Check service label
208202
if label, ok := service["label"].(string); ok {
209-
if strings.Contains(strings.ToLower(label), "seeker") {
203+
if common.ContainsIgnoreCase(label, "seeker") {
210204
return service, nil
211205
}
212206
}
213207

214-
// Check service tags
215208
if tags, ok := service["tags"].([]interface{}); ok {
216209
for _, tag := range tags {
217210
if tagStr, ok := tag.(string); ok {
218-
if strings.Contains(strings.ToLower(tagStr), "seeker") {
211+
if common.ContainsIgnoreCase(tagStr, "seeker") {
219212
return service, nil
220213
}
221214
}

src/java/jres/jre.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ type JRE interface {
5050
MemoryCalculatorCommand() string
5151
}
5252

53-
// Context holds shared dependencies for JRE providers
54-
type Context struct {
55-
Stager *libbuildpack.Stager
56-
Manifest *libbuildpack.Manifest
57-
Installer *libbuildpack.Installer
58-
Log *libbuildpack.Logger
59-
Command *libbuildpack.Command
60-
}
61-
6253
// Registry manages multiple JRE providers
6354
type Registry struct {
6455
ctx *common.Context

0 commit comments

Comments
 (0)