mirror of
https://github.com/openziti/zrok.git
synced 2025-05-31 07:07:14 +02:00
update 'share' implementation in store package to include permission mode (#432)
This commit is contained in:
parent
5cfd67ab19
commit
033d52c4c3
@ -7,3 +7,10 @@ const (
|
|||||||
WarningAction LimitJournalAction = "warning"
|
WarningAction LimitJournalAction = "warning"
|
||||||
ClearAction LimitJournalAction = "clear"
|
ClearAction LimitJournalAction = "clear"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PermissionMode string
|
||||||
|
|
||||||
|
const (
|
||||||
|
OpenPermissionMode PermissionMode = "open"
|
||||||
|
ClosedPermissionMode PermissionMode = "closed"
|
||||||
|
)
|
||||||
|
@ -16,16 +16,17 @@ type Share struct {
|
|||||||
FrontendEndpoint *string
|
FrontendEndpoint *string
|
||||||
BackendProxyEndpoint *string
|
BackendProxyEndpoint *string
|
||||||
Reserved bool
|
Reserved bool
|
||||||
|
PermissionMode PermissionMode
|
||||||
Deleted bool
|
Deleted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (str *Store) CreateShare(envId int, shr *Share, tx *sqlx.Tx) (int, error) {
|
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) values ($1, $2, $3, $4, $5, $6, $7, $8, $9) 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, permission_mode) values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) returning id")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.Wrap(err, "error preparing shares insert statement")
|
return 0, errors.Wrap(err, "error preparing shares insert statement")
|
||||||
}
|
}
|
||||||
var id int
|
var id int
|
||||||
if err := stmt.QueryRow(envId, shr.ZId, shr.Token, shr.ShareMode, shr.BackendMode, shr.FrontendSelection, shr.FrontendEndpoint, shr.BackendProxyEndpoint, shr.Reserved).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.PermissionMode).Scan(&id); err != nil {
|
||||||
return 0, errors.Wrap(err, "error executing shares insert statement")
|
return 0, errors.Wrap(err, "error executing shares insert statement")
|
||||||
}
|
}
|
||||||
return id, nil
|
return id, nil
|
||||||
@ -96,12 +97,12 @@ func (str *Store) FindSharesForEnvironment(envId int, tx *sqlx.Tx) ([]*Share, er
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (str *Store) UpdateShare(shr *Share, tx *sqlx.Tx) error {
|
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, updated_at = current_timestamp where id = $9"
|
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"
|
||||||
stmt, err := tx.Prepare(sql)
|
stmt, err := tx.Prepare(sql)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error preparing shares update statement")
|
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.Id)
|
_, err = stmt.Exec(shr.ZId, shr.Token, shr.ShareMode, shr.BackendMode, shr.FrontendSelection, shr.FrontendEndpoint, shr.BackendProxyEndpoint, shr.Reserved, shr.PermissionMode, shr.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error executing shares update statement")
|
return errors.Wrap(err, "error executing shares update statement")
|
||||||
}
|
}
|
||||||
|
14
controller/store/shareTest.go
Normal file
14
controller/store/shareTest.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package store
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestShareDefaultPermissionMode(t *testing.T) {
|
||||||
|
shr := &Share{}
|
||||||
|
assert.Equal(t, OpenPermissionMode, shr.PermissionMode)
|
||||||
|
|
||||||
|
var shr2 Share
|
||||||
|
assert.Equal(t, OpenPermissionMode, shr2.PermissionMode)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user