sr: add schema context support and generic context handling in srfake#1267
sr: add schema context support and generic context handling in srfake#1267c-julin wants to merge 3 commits intotwmb:masterfrom
Conversation
When using schema contexts, the registry returns subjects with a context prefix (e.g. ":.myctx:subject") in usages. Match against both plain and prefixed forms so CreateSchema succeeds under a schema context.
c5f5d2c to
1e1da70
Compare
| } | ||
|
|
||
| // DeleteContext deletes a context from the schema registry. | ||
| func (cl *Client) DeleteContext(ctx context.Context, context_ string) error { |
| } | ||
| // When using schema contexts, the registry stores subjects with a | ||
| // context prefix (e.g. ":.myctx:subject"). We need to match against | ||
| // both the plain subject and the context-prefixed form. |
There was a problem hiding this comment.
This is universal? Meaning if I opt into using contexts, ALL schemas are now prefixed with the context?
| // Offset returns a Param that sets the pagination offset. | ||
| func Offset(o int) Param { return Param{offset: o} } | ||
|
|
||
| // Limit returns a Param that sets the maximum number of results to return. |
There was a problem hiding this comment.
did I just ... not have this before? even though I had it above in merge / struct def? weird.
| }} | ||
| } | ||
|
|
||
| // DefaultSchemaContext sets a default schema context applied to every request. |
There was a problem hiding this comment.
sets a default schema registry context (namespacing) applied to every request
trying to be a bit more clear since SR contexts and Go contexts can be confusing when used in the same space
|
|
||
| // WithSchemaContext returns a context that scopes schema registry requests | ||
| // to the given context name. For client-wide scoping, use [DefaultSchemaContext]. | ||
| func WithSchemaContext(ctx context.Context, name string) context.Context { |
There was a problem hiding this comment.
// InContext scopes requests to be issued to the given schema registry context (namespacing).
// For client wide scoping, use [DefaultSchemaContext]. The following will return the subjects
// from the "foo" context:
//
// cl.Subjects(sr.InContext(ctx, "foo"))
also wdyt of InContext, or WithContext` as the name? Maybe With is better, it's more standard. I think dropping "Schema" though helps to keep it shorter. "In" for some reason to my brain separates it from Go contexts, whereas WithContext kinda just still sounds like with a context.Context (which then means you need the "Schema" => WithSchemaContext).
Summary
WithSchemaContext/DefaultSchemaContextto scope anysr.Clientrequest to a schema registry context by prepending/contexts/{name}to pathsContexts,DeleteContextContextPrefix,Offset, andLimitquery parameterssrfakewith a generic context-stripping middleware, so all existing endpoints work under/contexts/{name}/...Test plan
go test ./... -count=1 -racepasses inpkg/srCreateSchemawithWithSchemaContext