From 9b03765086ce78f5a975c1d4680cc0a903d21fa0 Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Wed, 22 May 2024 14:42:14 -0400 Subject: [PATCH] tracking unique names in the shares table (#632) --- controller/share.go | 1 + controller/store/share.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/controller/share.go b/controller/share.go index 8752a086..b2daabf7 100644 --- a/controller/share.go +++ b/controller/share.go @@ -147,6 +147,7 @@ func (h *shareHandler) Handle(params share.ShareParams, principal *rest_model_zr BackendMode: params.Body.BackendMode, BackendProxyEndpoint: ¶ms.Body.BackendProxyEndpoint, Reserved: reserved, + UniqueName: reserved && uniqueName != "", PermissionMode: store.OpenPermissionMode, } if params.Body.PermissionMode != "" { diff --git a/controller/store/share.go b/controller/store/share.go index 7005e603..305d76e3 100644 --- a/controller/store/share.go +++ b/controller/store/share.go @@ -16,17 +16,18 @@ type Share struct { FrontendEndpoint *string BackendProxyEndpoint *string Reserved bool + UniqueName bool PermissionMode PermissionMode Deleted bool } func (str *Store) CreateShare(envId int, shr *Share, tx *sqlx.Tx) (int, error) { - stmt, err := tx.Prepare("insert into shares (environment_id, z_id, token, share_mode, backend_mode, frontend_selection, frontend_endpoint, backend_proxy_endpoint, reserved, permission_mode) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) returning id") + stmt, err := tx.Prepare("insert into shares (environment_id, z_id, token, share_mode, backend_mode, frontend_selection, frontend_endpoint, backend_proxy_endpoint, reserved, unique_name, permission_mode) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) returning id") if err != nil { return 0, errors.Wrap(err, "error preparing shares insert statement") } var id int - if err := stmt.QueryRow(envId, shr.ZId, shr.Token, shr.ShareMode, shr.BackendMode, shr.FrontendSelection, shr.FrontendEndpoint, shr.BackendProxyEndpoint, shr.Reserved, shr.PermissionMode).Scan(&id); err != nil { + if err := stmt.QueryRow(envId, shr.ZId, shr.Token, shr.ShareMode, shr.BackendMode, shr.FrontendSelection, shr.FrontendEndpoint, shr.BackendProxyEndpoint, shr.Reserved, shr.UniqueName, shr.PermissionMode).Scan(&id); err != nil { return 0, errors.Wrap(err, "error executing shares insert statement") } return id, nil @@ -97,12 +98,12 @@ func (str *Store) FindSharesForEnvironment(envId int, tx *sqlx.Tx) ([]*Share, er } func (str *Store) UpdateShare(shr *Share, tx *sqlx.Tx) error { - sql := "update shares set z_id = $1, token = $2, share_mode = $3, backend_mode = $4, frontend_selection = $5, frontend_endpoint = $6, backend_proxy_endpoint = $7, reserved = $8, permission_mode = $9, updated_at = current_timestamp where id = $10" + sql := "update shares set z_id = $1, token = $2, share_mode = $3, backend_mode = $4, frontend_selection = $5, frontend_endpoint = $6, backend_proxy_endpoint = $7, reserved = $8, unique_name = $9, permission_mode = $10, updated_at = current_timestamp where id = $11" stmt, err := tx.Prepare(sql) if err != nil { return errors.Wrap(err, "error preparing shares update statement") } - _, err = stmt.Exec(shr.ZId, shr.Token, shr.ShareMode, shr.BackendMode, shr.FrontendSelection, shr.FrontendEndpoint, shr.BackendProxyEndpoint, shr.Reserved, shr.PermissionMode, shr.Id) + _, err = stmt.Exec(shr.ZId, shr.Token, shr.ShareMode, shr.BackendMode, shr.FrontendSelection, shr.FrontendEndpoint, shr.BackendProxyEndpoint, shr.Reserved, shr.UniqueName, shr.PermissionMode, shr.Id) if err != nil { return errors.Wrap(err, "error executing shares update statement") }