Skip to content

Commit 43664af

Browse files
committed
fix(api): support X-Tenant-ID header in tag requests
Add header binding for X-Tenant-ID alongside param binding in tag request structs, allowing new endpoints without :tenant path param to work correctly. Also normalize paginator and sorter in GetTags.
1 parent 7de4712 commit 43664af

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

api/routes/tags.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ func (h *Handler) GetTags(c gateway.Context) error {
6464
return err
6565
}
6666

67+
req.Paginator.Normalize()
68+
req.Sorter.Normalize()
69+
6770
tags, totalCount, err := h.service.ListTags(c.Ctx(), req)
6871
if err != nil {
6972
return err

pkg/api/requests/tags.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ package requests
33
import "github.com/shellhub-io/shellhub/pkg/api/query"
44

55
type CreateTag struct {
6-
TenantID string `param:"tenant" validate:"required,uuid"`
6+
TenantID string `param:"tenant" header:"X-Tenant-ID" validate:"required,uuid"`
77
Name string `json:"name" validate:"required,min=3,max=255,alphanum,ascii,excludes=/@&:"`
88
}
99

1010
type PushTag struct {
11-
TenantID string `param:"tenant" validate:"required,uuid"`
11+
TenantID string `param:"tenant" header:"X-Tenant-ID" validate:"required,uuid"`
1212
Name string `param:"name" validate:"required,min=3,max=255,alphanum,ascii,excludes=/@&:"`
1313
// TargetID is the identifier of the target to push the tag on.
1414
// For the reason cannot of it can be a list of things (UID for device, ID for firewall, etc...), it
@@ -17,7 +17,7 @@ type PushTag struct {
1717
}
1818

1919
type PullTag struct {
20-
TenantID string `param:"tenant" validate:"required,uuid"`
20+
TenantID string `param:"tenant" header:"X-Tenant-ID" validate:"required,uuid"`
2121
Name string `param:"name" validate:"required,min=3,max=255,alphanum,ascii,excludes=/@&:"`
2222
// TargetID is the identifier of the target to pull the tag of.
2323
// For the reason cannot of it can be a list of things (UID for device, ID for firewall, etc...), it
@@ -26,21 +26,21 @@ type PullTag struct {
2626
}
2727

2828
type ListTags struct {
29-
TenantID string `param:"tenant" validate:"required,uuid"`
29+
TenantID string `param:"tenant" header:"X-Tenant-ID" validate:"required,uuid"`
3030
query.Paginator
3131
query.Filters
3232
query.Sorter
3333
}
3434

3535
type UpdateTag struct {
36-
TenantID string `param:"tenant" validate:"required,uuid"`
36+
TenantID string `param:"tenant" header:"X-Tenant-ID" validate:"required,uuid"`
3737
Name string `param:"name" validate:"required"`
3838
// Similar to [UpdateTag.Name], but is used to update the tag's name instead of retrieve the tag.
3939
NewName string `json:"name" validate:"omitempty,min=3,max=255,alphanum,ascii,excludes=/@&:"`
4040
}
4141

4242
type DeleteTag struct {
43-
TenantID string `param:"tenant" validate:"required,uuid"`
43+
TenantID string `param:"tenant" header:"X-Tenant-ID" validate:"required,uuid"`
4444
Name string `param:"name" validate:"required"`
4545
}
4646

0 commit comments

Comments
 (0)