Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ddb1c52
APIGOV-31452 - send new insights events formats
sbolosan May 17, 2026
f0b71e2
APIGOV-31452 - updates on access request
sbolosan May 17, 2026
0b26a12
APIGOV-31452 - add deep logging for event building
sbolosan May 18, 2026
7ceb635
APIGOV-31452 - add missing attribs for service revision id and agent …
sbolosan May 19, 2026
48fc483
APIGOV-31452 - updated metric v3 events
sbolosan May 19, 2026
624b89f
APIGOV-31452 - update for product owner
sbolosan May 19, 2026
2e0435f
APIGOV-31452 - fall back to apiserviceinstance by name
sbolosan May 20, 2026
69601f5
APIGOV-31452 - add logging for unmarshaling
sbolosan May 20, 2026
7f43f59
APIGOV-31452 - update for embedded shape
sbolosan May 20, 2026
cbf185f
APIGOV-31452 - match the actual _embedded.metadata.references shape f…
sbolosan May 20, 2026
cb898e3
APIGOV-31452 - addition of owner
sbolosan May 21, 2026
4b3a084
APIGOV-31452 - add SetReporter builder method to CentralMetricBuilder
sbolosan May 21, 2026
5cb9589
APIGOV-31452 - update for published product watch topic
sbolosan May 21, 2026
1f0ce9d
APIGOV-31452 - revert watch topic logic
sbolosan May 21, 2026
58261b1
APIGOV-31452 - get published product owner from embedded
sbolosan May 21, 2026
7981e5b
APIGOV-31452 - update unit test coverage
sbolosan May 22, 2026
e7fc516
APIGOV-31452 - add api metric for agents explicitly calling
sbolosan May 23, 2026
0dabbeb
APIGOV-31452 - user id path
sbolosan May 23, 2026
da3484e
APIGOV-31452 - update test coverage
sbolosan May 24, 2026
b30cfa9
APIGOV-31452 - update sonar fixes
sbolosan May 27, 2026
ca85058
APIGOV-31452 - update embed for x agent details apiservice fetch
sbolosan May 28, 2026
0d86956
APIGOV-31452 - update leg with consumer details
sbolosan May 28, 2026
f6c4cb2
APIGOV-31452 - remove consumer details
sbolosan May 28, 2026
e19bf47
APIGOV-31452 - review
sbolosan May 28, 2026
fffd176
APIGOV-31452 - set proxy funcs for on prem agents
sbolosan May 28, 2026
24e2475
APIGOV-31452 - add backwards compatibility for leg
sbolosan May 29, 2026
ef8484b
APIGOV-31452 - update product block
sbolosan May 30, 2026
6a27914
APIGOV-31452 - update rev id for on prem
sbolosan May 30, 2026
37cdbee
APIGOV-31452 - apiservicerev setter for some on prem agents
sbolosan May 30, 2026
3a302b8
APIGOV-31452 - update transaction fields
sbolosan May 30, 2026
c28e0fd
APIGOV-31452 - update leg direction and proxy
sbolosan Jun 1, 2026
aa3f18c
APIGOV-31452 - update proxy
sbolosan Jun 1, 2026
52c33ab
APIGOV-31452 - expose SetLegProxy for controller enrichment
sbolosan Jun 1, 2026
7d85787
APIGOV-31452 - update on legs
sbolosan Jun 1, 2026
4854f79
APIGOV-31452 - set owner from man app
sbolosan Jun 2, 2026
d2a9035
APIGOV-31452 - product owner fix
sbolosan Jun 2, 2026
7397b67
APIGOV-31452 - update source and ip for v7 fixes
sbolosan Jun 2, 2026
f3205b6
APIGOV-31452 - remove flow header
sbolosan Jun 2, 2026
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
3 changes: 3 additions & 0 deletions pkg/agent/cache/accessrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ func (c *cacheManager) AddAccessRequest(ri *v1.ResourceInstance) {
instID = instRef.ID

instance, _ := c.GetAPIServiceInstanceByID(instID)
if instance == nil && ar.Spec.ApiServiceInstance != "" {
instance, _ = c.GetAPIServiceInstanceByName(ar.Spec.ApiServiceInstance)
}
apiID := ""
apiStage := ""
apiVersion := ""
Expand Down
9 changes: 8 additions & 1 deletion pkg/agent/discoverycache.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ func (dc *discoveryCache) buildResourceFunc(filter management.WatchTopicSpecFilt
logger := dc.logger.WithField("kind", filter.Kind)
logger.Tracef("fetching %s and updating cache", filter.Kind)

resources, err := dc.client.GetAPIV1ResourceInstances(nil, ri.GetKindLink())
var queryParams map[string]string
if filter.Kind == management.AccessRequestGVK().Kind {
queryParams = map[string]string{"embed": "metadata.references"}
} else if filter.Kind == management.APIServiceGVK().Kind {
queryParams = map[string]string{"embed": "x-agent-details"}
}

resources, err := dc.client.GetAPIV1ResourceInstances(queryParams, ri.GetKindLink())
if err != nil {
return fmt.Errorf("failed to fetch resources of kind %s: %s", filter.Kind, err)
}
Expand Down
40 changes: 31 additions & 9 deletions pkg/agent/discoverycache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

const envName = "mockEnv"

func TestDiscoveryCache_execute(t *testing.T) {
func TestDiscoveryCacheExecute(t *testing.T) {
tests := []struct {
agentType config.AgentType
name string
Expand Down Expand Up @@ -128,6 +128,17 @@ func TestDiscoveryCache_execute(t *testing.T) {
} else {
assert.False(t, migration.called)
}

// AccessRequest fetch must include embed=metadata.references.
if tc.accessReqCount > 0 {
arParams := c.queryParams["accessrequests"]
assert.Equal(t, "metadata.references", arParams["embed"], "accessrequests must be fetched with embed=metadata.references")
}
// APIService fetch must include embed=x-agent-details so externalAPIID is populated in the cache.
if tc.svcCount > 0 {
svcParams := c.queryParams["apiservices"]
assert.Equal(t, "x-agent-details", svcParams["embed"], "apiservices must be fetched with embed=x-agent-details")
}
})
}

Expand Down Expand Up @@ -194,19 +205,30 @@ type mockRIClient struct {
accessReqs []*apiv1.ResourceInstance
creds []*apiv1.ResourceInstance
err error
// queryParams records the query params passed per URL fragment (kind name)
queryParams map[string]map[string]string
}

func (m mockRIClient) GetAPIV1ResourceInstances(_ map[string]string, URL string) ([]*apiv1.ResourceInstance, error) {
func (m *mockRIClient) GetAPIV1ResourceInstances(query map[string]string, URL string) ([]*apiv1.ResourceInstance, error) {
fmt.Println(URL)
if strings.Contains(URL, "apiservices") {
return m.svcs, m.err
} else if strings.Contains(URL, "managedapplications") {
return m.managedApps, m.err
} else if strings.Contains(URL, "managedapplicationprofiles") {
if m.queryParams == nil {
m.queryParams = make(map[string]map[string]string)
}
switch {
case strings.Contains(URL, "managedapplicationprofiles"):
m.queryParams["managedapplicationprofiles"] = query
return m.manAppProfs, m.err
} else if strings.Contains(URL, "accessrequests") {
case strings.Contains(URL, "managedapplications"):
m.queryParams["managedapplications"] = query
return m.managedApps, m.err
case strings.Contains(URL, "apiservices"):
m.queryParams["apiservices"] = query
return m.svcs, m.err
case strings.Contains(URL, "accessrequests"):
m.queryParams["accessrequests"] = query
return m.accessReqs, m.err
} else if strings.Contains(URL, "credentials") {
case strings.Contains(URL, "credentials"):
m.queryParams["credentials"] = query
return m.creds, m.err
}
return make([]*apiv1.ResourceInstance, 0), m.err
Expand Down
24 changes: 13 additions & 11 deletions pkg/agent/handler/credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

apiv1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
management "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/management/v1alpha1"
defs "github.com/Axway/agent-sdk/pkg/apic/definitions"
prov "github.com/Axway/agent-sdk/pkg/apic/provisioning"
Expand All @@ -21,9 +22,10 @@ import (
"github.com/Axway/agent-sdk/pkg/util"
"github.com/Axway/agent-sdk/pkg/util/log"
"github.com/Axway/agent-sdk/pkg/watchmanager/proto"
"github.com/stretchr/testify/assert"
)

const algRSAOAEP = "RSA-OAEP"

func TestCredentialHandler(t *testing.T) {
crdRI, _ := crd.AsInstance()

Expand Down Expand Up @@ -196,7 +198,7 @@ func TestCredentialHandler(t *testing.T) {
}
}

func TestCredentialHandler_deleting(t *testing.T) {
func TestCredentialHandlerDeleting(t *testing.T) {
crdRI, _ := crd.AsInstance()

tests := []struct {
Expand Down Expand Up @@ -311,7 +313,7 @@ func TestCredentialHandler_deleting(t *testing.T) {
}
}

func TestCredentialHandler_update(t *testing.T) {
func TestCredentialHandlerUpdate(t *testing.T) {
crdRI, _ := crd.AsInstance()

tests := []struct {
Expand Down Expand Up @@ -412,7 +414,7 @@ func TestCredentialHandler_update(t *testing.T) {
}
}

func TestCredentialHandler_wrong_kind(t *testing.T) {
func TestCredentialHandlerWrongKind(t *testing.T) {
c := &mockClient{}
p := &mockCredProv{}
handler := NewCredentialHandler(p, c, nil)
Expand All @@ -425,7 +427,7 @@ func TestCredentialHandler_wrong_kind(t *testing.T) {
assert.Nil(t, err)
}

func Test_creds(t *testing.T) {
func TestCreds(t *testing.T) {
c := provCreds{
managedApp: "app-name",
credType: "api-key",
Expand Down Expand Up @@ -792,7 +794,7 @@ func decrypt(pk string, alg, hash string, data map[string]interface{}) map[strin
return data
}

func Test_encrypt(t *testing.T) {
func TestEncrypt(t *testing.T) {
var crdSchema = `{
"type": "object",
"$schema": "http://json-schema.org/draft-07/schema#",
Expand Down Expand Up @@ -843,7 +845,7 @@ func Test_encrypt(t *testing.T) {
},
{
name: "should encrypt when the algorithm is RSA-OAEP",
alg: "RSA-OAEP",
alg: algRSAOAEP,
hash: "SHA256",
publicKey: pub,
privateKey: priv,
Expand All @@ -859,15 +861,15 @@ func Test_encrypt(t *testing.T) {
{
name: "should return an error when the hash is unknown",
hasErr: true,
alg: "RSA-OAEP",
alg: algRSAOAEP,
hash: "fake",
publicKey: pub,
privateKey: priv,
},
{
name: "should return an error when the public key cannot be parsed",
hasErr: true,
alg: "RSA-OAEP",
alg: algRSAOAEP,
hash: "SHA256",
publicKey: "fake",
privateKey: priv,
Expand Down Expand Up @@ -946,7 +948,7 @@ func (m *credClient) UpdateResourceInstance(ri apiv1.Interface) (*apiv1.Resource
return nil, nil
}

func (m *credClient) DeleteResourceInstance(ri v1.Interface) error {
func (m *credClient) DeleteResourceInstance(ri apiv1.Interface) error {
return nil
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/agent/handler/traceaccessrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ func (h *traceAccessRequestHandler) Handle(ctx context.Context, _ *proto.EventMe
if h.shouldProcessForTrace(ar.Status, ar.Metadata.State) {
cachedAccessReq := h.cache.GetAccessRequest(resource.Metadata.ID)
if cachedAccessReq == nil {
h.cache.AddAccessRequest(resource)
enriched, err := h.client.GetResource(resource.GetSelfLink() + "?embed=metadata.references")
if err != nil || enriched == nil {
enriched = resource
}
h.cache.AddAccessRequest(enriched)
}
}
return nil
Expand Down
Loading
Loading