Skip to content

Commit

Permalink
add registration refresh and expiry to executable capability remote c…
Browse files Browse the repository at this point in the history
…onfig (#968)

* wip

* tests
  • Loading branch information
ettec authored Dec 17, 2024
1 parent b403079 commit bbe318c
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 47 deletions.
14 changes: 14 additions & 0 deletions pkg/capabilities/capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ type RemoteTargetConfig struct {

type RemoteExecutableConfig struct {
RequestHashExcludedAttributes []string
RegistrationRefresh time.Duration
RegistrationExpiry time.Duration
}

// NOTE: consider splitting this config into values stored in Registry (KS-118)
Expand All @@ -375,6 +377,18 @@ func (c *RemoteTriggerConfig) ApplyDefaults() {
}
}

func (c *RemoteExecutableConfig) ApplyDefaults() {
if c == nil {
return
}
if c.RegistrationRefresh == 0 {
c.RegistrationRefresh = DefaultRegistrationRefresh
}
if c.RegistrationExpiry == 0 {
c.RegistrationExpiry = DefaultRegistrationExpiry
}
}

type CapabilityConfiguration struct {
DefaultConfig *values.Map
RemoteTriggerConfig *RemoteTriggerConfig
Expand Down
8 changes: 8 additions & 0 deletions pkg/capabilities/capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,11 @@ func Test_MustNewCapabilityInfo(t *testing.T) {
)
})
}

func Test_RemoteExecutableConfig_ApplyDefaults(t *testing.T) {
rec := &RemoteExecutableConfig{}
rec.ApplyDefaults()

assert.Equal(t, DefaultRegistrationRefresh, rec.RegistrationRefresh)
assert.Equal(t, DefaultRegistrationExpiry, rec.RegistrationExpiry)
}
122 changes: 75 additions & 47 deletions pkg/capabilities/pb/registry.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/capabilities/pb/registry.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ message RemoteExecutableConfig {
// when calculating the hash of the request. This is useful for excluding attributes that are not deterministic to ensure
// that the hash of logically identical requests is consistent.
repeated string requestHashExcludedAttributes = 1;
google.protobuf.Duration registrationRefresh = 2;
google.protobuf.Duration registrationExpiry = 3;
}

message CapabilityConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func (cr *capabilitiesRegistryClient) ConfigForCapability(ctx context.Context, c
prtc := res.CapabilityConfig.GetRemoteExecutableConfig()
remoteExecutableConfig = &capabilities.RemoteExecutableConfig{}
remoteExecutableConfig.RequestHashExcludedAttributes = prtc.RequestHashExcludedAttributes
remoteExecutableConfig.RegistrationRefresh = prtc.RegistrationRefresh.AsDuration()
remoteExecutableConfig.RegistrationExpiry = prtc.RegistrationExpiry.AsDuration()
}

return capabilities.CapabilityConfiguration{
Expand Down Expand Up @@ -352,6 +354,16 @@ func (c *capabilitiesRegistryServer) ConfigForCapability(ctx context.Context, re
}
}

if cc.RemoteExecutableConfig != nil {
ccp.RemoteConfig = &capabilitiespb.CapabilityConfig_RemoteExecutableConfig{
RemoteExecutableConfig: &capabilitiespb.RemoteExecutableConfig{
RequestHashExcludedAttributes: cc.RemoteExecutableConfig.RequestHashExcludedAttributes,
RegistrationRefresh: durationpb.New(cc.RemoteExecutableConfig.RegistrationRefresh),
RegistrationExpiry: durationpb.New(cc.RemoteExecutableConfig.RegistrationExpiry),
},
}
}

return &pb.ConfigForCapabilityReply{
CapabilityConfig: ccp,
}, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"testing"
"time"

"github.com/hashicorp/go-plugin"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -435,3 +436,54 @@ func TestCapabilitiesRegistry_ConfigForCapabilities(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, expectedCapConfig, capConf)
}

func TestCapabilitiesRegistry_ConfigForCapability_RemoteExecutableConfig(t *testing.T) {
stopCh := make(chan struct{})
logger := logger.Test(t)
reg := mocks.NewCapabilitiesRegistry(t)

pluginName := "registry-test"
client, server := plugin.TestPluginGRPCConn(
t,
true,
map[string]plugin.Plugin{
pluginName: &testRegistryPlugin{
impl: reg,
brokerExt: &net.BrokerExt{
BrokerConfig: net.BrokerConfig{
StopCh: stopCh,
Logger: logger,
},
},
},
},
)

defer client.Close()
defer server.Stop()

regClient, err := client.Dispense(pluginName)
require.NoError(t, err)

rc, ok := regClient.(*capabilitiesRegistryClient)
require.True(t, ok)

capID := "[email protected]"
donID := uint32(1)
wm, err := values.WrapMap(map[string]any{"hello": "world"})
require.NoError(t, err)

var rec capabilities.RemoteExecutableConfig
rec.ApplyDefaults()
expectedCapConfig := capabilities.CapabilityConfiguration{
DefaultConfig: wm,
RemoteExecutableConfig: &rec,
}
reg.On("ConfigForCapability", mock.Anything, capID, donID).Once().Return(expectedCapConfig, nil)

capConf, err := rc.ConfigForCapability(tests.Context(t), capID, donID)
require.NoError(t, err)
assert.Equal(t, expectedCapConfig, capConf)
assert.Equal(t, 30*time.Second, capConf.RemoteExecutableConfig.RegistrationRefresh)
assert.Equal(t, 2*time.Minute, capConf.RemoteExecutableConfig.RegistrationExpiry)
}

0 comments on commit bbe318c

Please sign in to comment.