Skip to content

Commit 12df9f4

Browse files
committed
Add enabled config for aspectj weaver agent frmrk
1 parent 3f4e022 commit 12df9f4

1 file changed

Lines changed: 39 additions & 1 deletion

File tree

src/java/frameworks/aspectj_weaver_agent.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
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"
88
"strings"
@@ -22,6 +22,15 @@ func NewAspectJWeaverAgentFramework(ctx *common.Context) *AspectJWeaverAgentFram
2222

2323
// Detect determines if AspectJ Weaver JAR and configuration exist in the application
2424
func (a *AspectJWeaverAgentFramework) Detect() (string, error) {
25+
config, err := a.loadConfig()
26+
if err != nil {
27+
a.context.Log.Warning("Failed to load aspectj weaver agent config: %s", err.Error())
28+
return "", nil // Don't fail the build
29+
}
30+
31+
if !config.isEnabled() {
32+
return "", nil
33+
}
2534
// Look for aspectjweaver-*.jar in the application
2635
aspectjJar, err := a.findAspectJWeaver()
2736
if err != nil || aspectjJar == "" {
@@ -127,3 +136,32 @@ func (a *AspectJWeaverAgentFramework) findAspectJWeaver() (string, error) {
127136

128137
return "", nil
129138
}
139+
140+
func (a *AspectJWeaverAgentFramework) loadConfig() (*aspectjWeaverConfig, error) {
141+
// initialize default values
142+
ajwConfig := aspectjWeaverConfig{
143+
Enabled: true,
144+
}
145+
config := os.Getenv("JBP_CONFIG_ASPECTJ_WEAVER_AGENT")
146+
if config != "" {
147+
yamlHandler := common.YamlHandler{}
148+
err := yamlHandler.ValidateFields([]byte(config), &ajwConfig)
149+
if err != nil {
150+
a.context.Log.Warning("Unknown user config values: %s", err.Error())
151+
}
152+
// overlay JBP_CONFIG_ASPECTJ_WEAVER_AGENT over default values
153+
if err = yamlHandler.Unmarshal([]byte(config), &ajwConfig); err != nil {
154+
return nil, fmt.Errorf("failed to parse JBP_CONFIG_ASPECTJ_WEAVER_AGENT: %w", err)
155+
}
156+
}
157+
return &ajwConfig, nil
158+
}
159+
160+
type aspectjWeaverConfig struct {
161+
Enabled bool `yaml:"enabled"`
162+
}
163+
164+
// isEnabled checks if client certificate mapper is enabled
165+
func (a *aspectjWeaverConfig) isEnabled() bool {
166+
return a.Enabled
167+
}

0 commit comments

Comments
 (0)