mirror of
https://github.com/openziti/zrok.git
synced 2024-12-23 07:09:12 +01:00
updated store.Services and friends (#103)
This commit is contained in:
parent
cbb9ec833f
commit
6184e0e450
@ -45,10 +45,18 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
|
||||
return metadata.NewOverviewInternalServerError()
|
||||
}
|
||||
for _, svc := range svcs {
|
||||
fe := ""
|
||||
if svc.FrontendEndpoint != nil {
|
||||
fe = *svc.FrontendEndpoint
|
||||
}
|
||||
be := ""
|
||||
if svc.BackendProxyEndpoint != nil {
|
||||
be = *svc.BackendProxyEndpoint
|
||||
}
|
||||
es.Services = append(es.Services, &rest_model_zrok.Service{
|
||||
CreatedAt: svc.CreatedAt.UnixMilli(),
|
||||
Frontend: svc.Frontend,
|
||||
Backend: svc.Backend,
|
||||
Frontend: fe,
|
||||
Backend: be,
|
||||
UpdatedAt: svc.UpdatedAt.UnixMilli(),
|
||||
ZID: svc.ZId,
|
||||
Name: svc.Name,
|
||||
|
@ -93,12 +93,12 @@ func (h *sharePublicHandler) Handle(params service.ShareParams, principal *rest_
|
||||
|
||||
frontendUrl := h.proxyUrl(svcName)
|
||||
sid, err := str.CreateService(envId, &store.Service{
|
||||
ZId: svcZId,
|
||||
Name: svcName,
|
||||
Frontend: frontendUrl,
|
||||
Backend: params.Body.BackendProxyEndpoint,
|
||||
ShareMode: "public",
|
||||
BackendMode: "proxy",
|
||||
ZId: svcZId,
|
||||
Name: svcName,
|
||||
ShareMode: "public",
|
||||
BackendMode: "proxy",
|
||||
FrontendEndpoint: &frontendUrl,
|
||||
BackendProxyEndpoint: ¶ms.Body.BackendProxyEndpoint,
|
||||
}, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error creating service record: %v", err)
|
||||
|
@ -7,22 +7,23 @@ import (
|
||||
|
||||
type Service struct {
|
||||
Model
|
||||
EnvironmentId int
|
||||
ZId string
|
||||
Name string
|
||||
Frontend string
|
||||
Backend string
|
||||
ShareMode string
|
||||
BackendMode string
|
||||
EnvironmentId int
|
||||
ZId string
|
||||
Name string
|
||||
ShareMode string
|
||||
BackendMode string
|
||||
FrontendSelection *string
|
||||
FrontendEndpoint *string
|
||||
BackendProxyEndpoint *string
|
||||
}
|
||||
|
||||
func (self *Store) CreateService(envId int, svc *Service, tx *sqlx.Tx) (int, error) {
|
||||
stmt, err := tx.Prepare("insert into services (environment_id, z_id, name, frontend, backend, share_mode, backend_mode) values ($1, $2, $3, $4, $5, $6, $7) returning id")
|
||||
stmt, err := tx.Prepare("insert into services (environment_id, z_id, name, share_mode, backend_mode, frontend_selection, frontend_endpoint, backend_proxy_endpoint) values ($1, $2, $3, $4, $5, $6, $7, $8) returning id")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error preparing services insert statement")
|
||||
}
|
||||
var id int
|
||||
if err := stmt.QueryRow(envId, svc.ZId, svc.Name, svc.Frontend, svc.Backend, svc.ShareMode, svc.BackendMode).Scan(&id); err != nil {
|
||||
if err := stmt.QueryRow(envId, svc.ZId, svc.Name, svc.ShareMode, svc.BackendMode, svc.FrontendSelection, svc.FrontendEndpoint, svc.BackendProxyEndpoint).Scan(&id); err != nil {
|
||||
return 0, errors.Wrap(err, "error executing services insert statement")
|
||||
}
|
||||
return id, nil
|
||||
@ -69,12 +70,12 @@ func (self *Store) FindServicesForEnvironment(envId int, tx *sqlx.Tx) ([]*Servic
|
||||
}
|
||||
|
||||
func (self *Store) UpdateService(svc *Service, tx *sqlx.Tx) error {
|
||||
sql := "update services set z_id = $1, name = $2, frontend = $3, backend = $4, share_mode = $5, backend_mode = $6, updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now') where id = $7"
|
||||
sql := "update services set z_id = $1, name = $2, share_mode = $3, backend_mode = $4, frontend_selection = $5, frontend_endpoint = $6, backend_proxy_endpoint = $7, updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now') where id = $8"
|
||||
stmt, err := tx.Prepare(sql)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing services update statement")
|
||||
}
|
||||
_, err = stmt.Exec(svc.ZId, svc.Name, svc.Frontend, svc.Backend, svc.ShareMode, svc.BackendMode, svc.Id)
|
||||
_, err = stmt.Exec(svc.ZId, svc.Name, svc.ShareMode, svc.BackendMode, svc.FrontendSelection, svc.FrontendEndpoint, svc.BackendProxyEndpoint, svc.Id)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing services update statement")
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ create table services (
|
||||
|
||||
constraint chk_z_id check (z_id <> ''),
|
||||
constraint chk_name check (name <> ''),
|
||||
constraint chk_share_mode check (share_mode == 'public' || share_mode == 'private'),
|
||||
constraint chk_backend_mode check (backend_mode == 'proxy' || backend_mode == 'web' || backend_mode == 'dav')
|
||||
constraint chk_share_mode check (share_mode == 'public' or share_mode == 'private'),
|
||||
constraint chk_backend_mode check (backend_mode == 'proxy' or backend_mode == 'web' or backend_mode == 'dav')
|
||||
);
|
||||
|
||||
insert into services (id, environment_id, z_id, name, share_mode, backend_mode, frontend_selection, frontend_endpoint, backend_proxy_endpoint, created_at, updated_at)
|
||||
|
Loading…
Reference in New Issue
Block a user