From b69780908c3970fe60d378e8f25a8100786d2e00 Mon Sep 17 00:00:00 2001 From: Cam Date: Wed, 24 Jan 2024 09:48:27 -0600 Subject: [PATCH 1/5] return 409 for share token collision. Have property table show strings to correctly render booleans. Fixes #531 and #443 --- controller/share.go | 10 +++ rest_client_zrok/share/share_responses.go | 62 +++++++++++++++++++ rest_server_zrok/embedded_spec.go | 6 ++ .../operations/share/share_responses.go | 25 ++++++++ specs/zrok.yml | 2 + ui/src/console/PropertyTable.js | 2 +- 6 files changed, 106 insertions(+), 1 deletion(-) diff --git a/controller/share.go b/controller/share.go index dbb22c2e..f3a0f6e0 100644 --- a/controller/share.go +++ b/controller/share.go @@ -135,6 +135,16 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr sshr.FrontendEndpoint = &sshr.ShareMode } + sh, err := str.FindShareWithToken(sshr.Token, trx) + if err != nil { + logrus.Errorf("error checking share token collision: %v", err) + return share.NewShareInternalServerError() + } + if sh != nil { + logrus.Errorf("attempting to create share with conflcting token: %v", sshr.Token) + return share.NewShareConflict() + } + sid, err := str.CreateShare(envId, sshr, trx) if err != nil { logrus.Errorf("error creating share record: %v", err) diff --git a/rest_client_zrok/share/share_responses.go b/rest_client_zrok/share/share_responses.go index 346cbdf3..8af0e374 100644 --- a/rest_client_zrok/share/share_responses.go +++ b/rest_client_zrok/share/share_responses.go @@ -41,6 +41,12 @@ func (o *ShareReader) ReadResponse(response runtime.ClientResponse, consumer run return nil, err } return nil, result + case 409: + result := NewShareConflict() + if err := result.readResponse(response, consumer, o.formats); err != nil { + return nil, err + } + return nil, result case 422: result := NewShareUnprocessableEntity() if err := result.readResponse(response, consumer, o.formats); err != nil { @@ -238,6 +244,62 @@ func (o *ShareNotFound) readResponse(response runtime.ClientResponse, consumer r return nil } +// NewShareConflict creates a ShareConflict with default headers values +func NewShareConflict() *ShareConflict { + return &ShareConflict{} +} + +/* +ShareConflict describes a response with status code 409, with default header values. + +conflict +*/ +type ShareConflict struct { +} + +// IsSuccess returns true when this share conflict response has a 2xx status code +func (o *ShareConflict) IsSuccess() bool { + return false +} + +// IsRedirect returns true when this share conflict response has a 3xx status code +func (o *ShareConflict) IsRedirect() bool { + return false +} + +// IsClientError returns true when this share conflict response has a 4xx status code +func (o *ShareConflict) IsClientError() bool { + return true +} + +// IsServerError returns true when this share conflict response has a 5xx status code +func (o *ShareConflict) IsServerError() bool { + return false +} + +// IsCode returns true when this share conflict response a status code equal to that given +func (o *ShareConflict) IsCode(code int) bool { + return code == 409 +} + +// Code gets the status code for the share conflict response +func (o *ShareConflict) Code() int { + return 409 +} + +func (o *ShareConflict) Error() string { + return fmt.Sprintf("[POST /share][%d] shareConflict ", 409) +} + +func (o *ShareConflict) String() string { + return fmt.Sprintf("[POST /share][%d] shareConflict ", 409) +} + +func (o *ShareConflict) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error { + + return nil +} + // NewShareUnprocessableEntity creates a ShareUnprocessableEntity with default headers values func NewShareUnprocessableEntity() *ShareUnprocessableEntity { return &ShareUnprocessableEntity{} diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index 08c43fd2..b1d082ce 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -865,6 +865,9 @@ func init() { "404": { "description": "not found" }, + "409": { + "description": "conflict" + }, "422": { "description": "unprocessable" }, @@ -2488,6 +2491,9 @@ func init() { "404": { "description": "not found" }, + "409": { + "description": "conflict" + }, "422": { "description": "unprocessable" }, diff --git a/rest_server_zrok/operations/share/share_responses.go b/rest_server_zrok/operations/share/share_responses.go index d49c044e..9bf46588 100644 --- a/rest_server_zrok/operations/share/share_responses.go +++ b/rest_server_zrok/operations/share/share_responses.go @@ -108,6 +108,31 @@ func (o *ShareNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.P rw.WriteHeader(404) } +// ShareConflictCode is the HTTP code returned for type ShareConflict +const ShareConflictCode int = 409 + +/* +ShareConflict conflict + +swagger:response shareConflict +*/ +type ShareConflict struct { +} + +// NewShareConflict creates ShareConflict with default headers values +func NewShareConflict() *ShareConflict { + + return &ShareConflict{} +} + +// WriteResponse to the client +func (o *ShareConflict) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) { + + rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses + + rw.WriteHeader(409) +} + // ShareUnprocessableEntityCode is the HTTP code returned for type ShareUnprocessableEntity const ShareUnprocessableEntityCode int = 422 diff --git a/specs/zrok.yml b/specs/zrok.yml index 275e7a73..12ac7658 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -577,6 +577,8 @@ paths: description: unauthorized 404: description: not found + 409: + description: conflict 422: description: unprocessable 500: diff --git a/ui/src/console/PropertyTable.js b/ui/src/console/PropertyTable.js index 355aec2d..14ccf711 100644 --- a/ui/src/console/PropertyTable.js +++ b/ui/src/console/PropertyTable.js @@ -18,7 +18,7 @@ const rowToValue = (row) => { if(row.property.endsWith("At")) { return new Date(row.value).toLocaleString(); } - return row.value; + return row.value.toString(); }; const PropertyTable = (props) => { From f7d4dfba1b0addd65985bbfc96969f2d5e1dc448 Mon Sep 17 00:00:00 2001 From: Cam Date: Thu, 25 Jan 2024 10:01:38 -0600 Subject: [PATCH 2/5] update error messaging --- controller/share.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controller/share.go b/controller/share.go index f3a0f6e0..e2fbbcf5 100644 --- a/controller/share.go +++ b/controller/share.go @@ -137,11 +137,11 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr sh, err := str.FindShareWithToken(sshr.Token, trx) if err != nil { - logrus.Errorf("error checking share token collision: %v", err) + logrus.Errorf("error checking share for token collision: %v", err) return share.NewShareInternalServerError() } if sh != nil { - logrus.Errorf("attempting to create share with conflcting token: %v", sshr.Token) + logrus.Errorf("token '%v' already exists; cannot create share", sshr.Token) return share.NewShareConflict() } From 9580fb55708ea25cedb264ecb5657e8a94818074 Mon Sep 17 00:00:00 2001 From: Cam Date: Wed, 7 Feb 2024 15:05:39 -0600 Subject: [PATCH 3/5] update changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 448b2a83..c206baf9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # CHANGELOG +## v0.4.24 + +CHANGE: Update to share creation. Now checks for token collision and returns a relevant error. + +CHANGE: Update UI to add a 'true' value on booleans. + ## v0.4.23 FEATURE: New CLI commands have been implemented for working with the `drive` share backend mode (part of the "zrok Drives" functionality). These commands include `zrok cp`, `zrok mkdir` `zrok mv`, `zrok ls`, and `zrok rm`. These are initial, minimal versions of these commands and very likely contain bugs and ergonomic annoyances. There is a guide available at (`docs/guides/drives/cli.md`) that explains how to work with these tools in detail (https://github.com/openziti/zrok/issues/438) From 3fafb550359448a2f1be3b70a6360355cc3a54f3 Mon Sep 17 00:00:00 2001 From: Cam Date: Wed, 14 Feb 2024 13:21:50 -0600 Subject: [PATCH 4/5] update changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c206baf9..89aa595b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ # CHANGELOG -## v0.4.24 +## v0.4.25 -CHANGE: Update to share creation. Now checks for token collision and returns a relevant error. +CHANGE: Update to share creation. Now checks for token collision and returns a relevant error. (https://github.com/openziti/zrok/issues/531) -CHANGE: Update UI to add a 'true' value on booleans. +CHANGE: Update UI to add a 'true' value on booleans. (https://github.com/openziti/zrok/issues/443) ## v0.4.23 From 8cc0ca02151f2f3c0708d485ebe947c65abdb469 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 14 Feb 2024 15:05:32 -0500 Subject: [PATCH 5/5] changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf07ed6c..f03c4e80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,9 @@ ## v0.4.25 -CHANGE: Update to share creation. Now checks for token collision and returns a relevant error. (https://github.com/openziti/zrok/issues/531) +CHANGE: Creating a reserved share checks for token collision and returns a more appropriate error message (https://github.com/openziti/zrok/issues/531) -CHANGE: Update UI to add a 'true' value on booleans. (https://github.com/openziti/zrok/issues/443) +CHANGE: Update UI to add a 'true' value on `reserved` boolean (https://github.com/openziti/zrok/issues/443) ## v0.4.24