Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/Axway/agent-sdk
go 1.25.0

require (
github.com/elastic/beats/v7 v7.17.29
github.com/emicklei/proto v1.9.2
github.com/fsnotify/fsnotify v1.5.4
github.com/getkin/kin-openapi v0.144.0
Expand All @@ -30,78 +29,43 @@ require (
google.golang.org/protobuf v1.36.11
gopkg.in/h2non/gock.v1 v1.1.2
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.22.7
)

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/elastic/elastic-agent-client/v7 v7.17.2 // indirect
github.com/elastic/elastic-agent-libs v0.21.5 // indirect
github.com/elastic/go-licenser v0.4.2 // indirect
github.com/elastic/go-sysinfo v1.15.3 // indirect
github.com/elastic/go-ucfg v0.8.8 // indirect
github.com/elastic/go-windows v1.0.2 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/go-openapi/jsonpointer v0.22.5 // indirect
github.com/go-openapi/swag/jsonname v0.25.5 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/pprof v0.0.0-20250630185457-6e76a2b096b5 // indirect
Comment thread
jcollins-axway marked this conversation as resolved.
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jcchavezs/porto v0.7.0 // indirect
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
github.com/lestrrat-go/blackmagic v1.0.2 // indirect
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/httprc v1.0.5 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oasdiff/yaml v0.1.1 // indirect
github.com/oasdiff/yaml3 v0.0.14 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect
github.com/santhosh-tekuri/jsonschema/v6 v6.0.2 // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
go.elastic.co/apm v1.15.0 // indirect
go.elastic.co/ecszap v1.0.3 // indirect
go.elastic.co/fastjson v1.5.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.54.0 // indirect
golang.org/x/lint v0.0.0-20241112194109-818c5a804067 // indirect
golang.org/x/mod v0.37.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/telemetry v0.0.0-20260625142307-59b4966ccb57 // indirect
golang.org/x/tools v0.47.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect
gopkg.in/ini.v1 v1.66.6 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.1 // indirect
)

replace github.com/Shopify/sarama => github.com/elastic/sarama v1.19.1-0.20210823122811-11c3ef800752

retract ( // errored versions
[v1.1.35, v1.1.36]
[v1.1.21, v1.1.23]
Expand Down
177 changes: 0 additions & 177 deletions go.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/agent/resource/manager_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resource

import (
"encoding/json"
"fmt"
"strconv"
"testing"
Expand All @@ -16,7 +17,6 @@ import (
management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1"
"github.com/Axway/agent-sdk/pkg/config"
"github.com/stretchr/testify/assert"
"k8s.io/apimachinery/pkg/util/json"
)

func createDiscoveryAgentRes(id, name, dataplane, teamID string) *v1.ResourceInstance {
Expand Down
483 changes: 287 additions & 196 deletions pkg/cmd/cmd_test.go

Large diffs are not rendered by default.

47 changes: 25 additions & 22 deletions pkg/cmd/properties/properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Properties interface {
// Log Properties
MaskValues(name string)
DebugLogProperties()

SetAliasKeyPrefix(aliasKeyPrefix string)
}

Expand Down Expand Up @@ -122,8 +123,20 @@ func WithUpperLimitInt(upper int) IntOpt {
}
}

// aliasKeyPrefix - when set, properties are looked up under "<aliasKeyPrefix>.<key>" first,
// falling back to the plain "<key>".
var aliasKeyPrefix string

// SetAliasKeyPrefix -
Comment thread
jcollins-axway marked this conversation as resolved.
func SetAliasKeyPrefix(keyPrefix string) {
aliasKeyPrefix = keyPrefix
}

// GetAliasKeyPrefix -
func GetAliasKeyPrefix() string {
return aliasKeyPrefix
}

type properties struct {
Properties
rootCmd *cobra.Command
Expand Down Expand Up @@ -162,16 +175,6 @@ func NewPropertiesWithSecretResolver(rootCmd *cobra.Command, secretResolver Secr
return cmdprops
}

// SetAliasKeyPrefix -
func SetAliasKeyPrefix(keyPrefix string) {
aliasKeyPrefix = keyPrefix
}

// GetAliasKeyPrefix -
func GetAliasKeyPrefix() string {
return aliasKeyPrefix
}

func (p *properties) bindOrPanic(key string, flg *flag.Flag) {
if err := viper.BindPFlag(key, flg); err != nil {
panic(err)
Expand Down Expand Up @@ -441,6 +444,18 @@ func (p *properties) parseStringValueForKey(key string) string {
return s
}

func (p *properties) parseStringValue(key string) string {
Comment thread
jcollins-axway marked this conversation as resolved.
var s string
if aliasKeyPrefix != "" {
s = p.parseStringValueForKey(aliasKeyPrefix + "." + key)
}
// If no alias or no value parsed for alias key
if s == "" {
s = p.parseStringValueForKey(key)
}
return s
}

func (p *properties) parseSlice(s string, expSlice [][]byte) string {
rtnS := s
envVar := string(expSlice[1])
Expand All @@ -465,18 +480,6 @@ func (p *properties) parseSlice(s string, expSlice [][]byte) string {
return rtnS
}

func (p *properties) parseStringValue(key string) string {
var s string
if aliasKeyPrefix != "" {
s = p.parseStringValueForKey(aliasKeyPrefix + "." + key)
}
// If no alias or no value parsed for alias key
if s == "" {
s = p.parseStringValueForKey(key)
}
return s
}

func (p *properties) resolveSecretReference(cfgName, cfgValue string) string {
if p.secretResolver != nil {
secretValue, err := p.secretResolver.ResolveSecret(cfgValue)
Expand Down
53 changes: 53 additions & 0 deletions pkg/cmd/properties/properties_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package properties

import (
"bytes"
"testing"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
)

// TestAliasKeyPrefixResolvesNestedYamlValue guards against a regression where yaml nested under
// an agent's own name (e.g. "traceability_agent:") silently stopped resolving.
func TestAliasKeyPrefixResolvesNestedYamlValue(t *testing.T) {
yamlContent := []byte(`
traceability_agent:
status:
port: 8990
`)

tests := map[string]struct {
aliasKeyPrefix string
expectedPort int
}{
"no alias prefix set, falls back to flag default": {
aliasKeyPrefix: "",
expectedPort: 8989,
},
"alias prefix set, resolves nested yaml value": {
aliasKeyPrefix: "traceability_agent",
expectedPort: 8990,
},
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
viper.Reset()
SetAliasKeyPrefix(tc.aliasKeyPrefix)
defer SetAliasKeyPrefix("")

rootCmd := &cobra.Command{Use: "test"}
props := NewPropertiesWithSecretResolver(rootCmd, nil)
props.AddIntProperty("status.port", 8989, "test port property")

viper.SetConfigType("yaml")
err := viper.ReadConfig(bytes.NewReader(yamlContent))
assert.Nil(t, err)

assert.Equal(t, tc.expectedPort, props.IntPropertyValue("status.port"))
})
}
}
30 changes: 19 additions & 11 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/Axway/agent-sdk/pkg/cmd/properties/resolver"
"github.com/Axway/agent-sdk/pkg/config"
"github.com/Axway/agent-sdk/pkg/jobs"
"github.com/Axway/agent-sdk/pkg/traceability"
"github.com/Axway/agent-sdk/pkg/util"
"github.com/Axway/agent-sdk/pkg/util/errors"
hc "github.com/Axway/agent-sdk/pkg/util/healthcheck"
Expand Down Expand Up @@ -134,6 +135,11 @@ func NewRootCmd(exeName, desc string, initConfigHandler InitConfigHandler, comma
}

c.props = properties.NewPropertiesWithSecretResolver(c.rootCmd, c.secretResolver)
if agentType == config.TraceabilityAgent || agentType == config.ComplianceAgent {
properties.SetAliasKeyPrefix(c.agentName)
} else {
properties.SetAliasKeyPrefix("")
}
c.addBaseProps(agentType)
config.AddLogConfigProperties(c.props, fmt.Sprintf("%s.log", exeName))
config.AddMetricLogConfigProperties(c.props, agentType)
Expand Down Expand Up @@ -179,6 +185,8 @@ func NewCmd(rootCmd *cobra.Command, exeName, desc string, initConfigHandler Init
c.props = properties.NewPropertiesWithSecretResolver(c.rootCmd, c.secretResolver)
if agentType == config.TraceabilityAgent || agentType == config.ComplianceAgent {
properties.SetAliasKeyPrefix(c.agentName)
} else {
properties.SetAliasKeyPrefix("")
}

c.addBaseProps(agentType)
Expand Down Expand Up @@ -243,6 +251,14 @@ func (c *agentRootCommand) initialize(cmd *cobra.Command, args []string) error {
_, beatsConfigFilePath = c.props.StringFlagValue(beatsPathConfigFlag)
}

// Most agents never set --pathConfig (it defaults to "."), so fall back to "./data"
// Instead of dumping files in the working directory, default pkg/agent/cache already uses.
dataDirPath := agentConfigFilePath
if dataDirPath == "" || dataDirPath == "." {
dataDirPath = "./data"
}
traceability.SetDataDirPath(dataDirPath)

viper.SetConfigName(c.agentName)
// viper.SetConfigType("yaml") //Comment out since yaml, yml is a support extension already. We need an updated story to take into account the other supported extensions

Expand All @@ -255,9 +271,9 @@ func (c *agentRootCommand) initialize(cmd *cobra.Command, args []string) error {
viper.AutomaticEnv()
err = viper.ReadInConfig()
if err != nil {
if envFile == "" {
return err
} else if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
// Config can be read entirely from env vars.
// Any other error (e.g. malformed YAML) still fails startup.
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return err
}
}
Expand Down Expand Up @@ -418,14 +434,6 @@ func (c *agentRootCommand) run(cmd *cobra.Command, args []string) (err error) {
WithField("sdkVersion", SDKBuildVersion).
Infof("Starting %s", c.rootCmd.Short)
if c.commandHandler != nil {
// Setup logp to use beats logger.
// Setting up late here as log entries for agent/command initialization are not logged
// as the beats logger is initialized only when the beat instance is created.
if c.agentType == config.TraceabilityAgent || c.agentType == config.ComplianceAgent {
properties.SetAliasKeyPrefix(c.agentName)
log.SetIsLogP()
}

c.healthCheckTicker()

if util.IsNotTest() && c.agentFeaturesCfg.AgentStatusUpdatesEnabled() && !c.centralCfg.GetUsageReportingConfig().IsOfflineMode() {
Expand Down
12 changes: 6 additions & 6 deletions pkg/config/centralconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,26 @@ var regionalSettingsMap = map[Region]regionalSettings{
CentralURL: "https://apicentral.axway.com",
AuthURL: "https://login.axway.com/auth",
PlatformURL: "https://platform.axway.com",
TraceabilityHost: "ingestion.datasearch.axway.com:5044",
TraceabilityProtocol: "tcp",
TraceabilityHost: "phoenix.datasearch.axway.com:443",
TraceabilityProtocol: "https",
Deployment: "prod",
},
EU: {
SingleURL: "https://ingestion-eu.platform.axway.com",
CentralURL: "https://central.eu-fr.axway.com",
AuthURL: "https://login.axway.com/auth",
PlatformURL: "https://platform.axway.com",
TraceabilityHost: "ingestion.visibility.eu-fr.axway.com:5044",
TraceabilityProtocol: "tcp",
TraceabilityHost: "phoenix.visibility.eu-fr.axway.com:443",
TraceabilityProtocol: "https",
Deployment: "prod-eu",
},
AP: {
SingleURL: "https://ingestion-ap-sg.platform.axway.com",
CentralURL: "https://central.ap-sg.axway.com",
AuthURL: "https://login.axway.com/auth",
PlatformURL: "https://platform.axway.com",
TraceabilityHost: "ingestion.visibility.ap-sg.axway.com:5044",
TraceabilityProtocol: "tcp",
TraceabilityHost: "phoenix.visibility.ap-sg.axway.com:443",
TraceabilityProtocol: "https",
Deployment: "prod-ap",
},
EU2: {
Expand Down
22 changes: 22 additions & 0 deletions pkg/config/centralconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,25 @@ func cleanupFiles(fileName string) {
// cleanup files
os.Remove("./" + fileName)
}

func TestRegionalTraceabilityDefaults(t *testing.T) {
tests := map[string]struct {
region Region
expectHost string
expectProto string
}{
"US": {region: US, expectHost: "phoenix.datasearch.axway.com:443", expectProto: "https"},
"EU": {region: EU, expectHost: "phoenix.visibility.eu-fr.axway.com:443", expectProto: "https"},
"AP": {region: AP, expectHost: "phoenix.visibility.ap-sg.axway.com:443", expectProto: "https"},
"EU2": {region: EU2, expectHost: "phoenix.eu-fr.axway.com:443", expectProto: "https"},
}

for name, tc := range tests {
tc := tc
t.Run(name, func(t *testing.T) {
settings := regionalSettingsMap[tc.region]
assert.Equal(t, tc.expectHost, settings.TraceabilityHost)
assert.Equal(t, tc.expectProto, settings.TraceabilityProtocol)
})
}
}
Loading
Loading