Skip to content
Merged
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
3 changes: 3 additions & 0 deletions .changelog/27065.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
api: Fixed a bug in the Go API where an event stream request without a topic filter would require a management token
```
4 changes: 4 additions & 0 deletions api/event_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ func (e *EventStream) Stream(ctx context.Context, topics map[Topic][]string, ind

// Build topic query params
for topic, keys := range topics {
if len(keys) == 0 {
r.params.Add("topic", fmt.Sprintf("%s", topic))
continue
}
for _, k := range keys {
r.params.Add("topic", fmt.Sprintf("%s:%s", topic, k))
}
Expand Down
23 changes: 21 additions & 2 deletions api/event_stream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,40 @@ func TestTopic_String(t *testing.T) {
func TestEvent_Stream(t *testing.T) {
testutil.Parallel(t)

c, s := makeClient(t, nil, nil)
c, s, _ := makeACLClient(t, nil, nil)
defer s.Stop()

aclPolicy := ACLPolicy{
Name: "read-events-policy",
Rules: `namespace "default" { policy = "read" }`,
}
_, err := c.ACLPolicies().Upsert(&aclPolicy, nil)
must.NoError(t, err)

at := c.ACLTokens()
tokenSpec := &ACLToken{
Name: "read-events-token",
Type: "client",
Policies: []string{"read-events-policy"},
}
token, _, err := at.Create(tokenSpec, nil)
must.NoError(t, err)

// register job to generate events
jobs := c.Jobs()
job := testJob()
resp2, _, err := jobs.Register(job, nil)
must.NoError(t, err)
must.NotNil(t, resp2)

// downscope our client
c.SetSecretID(token.SecretID)

// build event stream request
events := c.EventStream()
q := &QueryOptions{}
topics := map[Topic][]string{
TopicEvaluation: {"*"},
TopicEvaluation: {},
}

ctx, cancel := context.WithCancel(context.Background())
Expand Down