better url-ing in the ui (#68); demo improvements

This commit is contained in:
Michael Quigley
2022-09-28 14:47:42 -04:00
parent 3639635d48
commit 02d6b7fce9
10 changed files with 53 additions and 25 deletions

View File

@ -41,9 +41,11 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
es.Services = append(es.Services, &rest_model_zrok.Service{
Active: svc.Active,
CreatedAt: svc.CreatedAt.String(),
Endpoint: svc.Endpoint,
Frontend: svc.Frontend,
Backend: svc.Backend,
UpdatedAt: svc.UpdatedAt.String(),
ZitiServiceID: svc.ZitiServiceId,
ZrokServiceID: svc.ZrokServiceId,
})
}
out = append(out, es)

View File

@ -9,16 +9,18 @@ type Service struct {
Model
EnvironmentId int
ZitiServiceId string
Endpoint string
ZrokServiceId string
Frontend string
Backend string
Active bool
}
func (self *Store) CreateService(envId int, svc *Service, tx *sqlx.Tx) (int, error) {
stmt, err := tx.Prepare("insert into services (environment_id, ziti_service_id, endpoint, active) values (?, ?, ?, true)")
stmt, err := tx.Prepare("insert into services (environment_id, ziti_service_id, zrok_service_id, frontend, backend, active) values (?, ?, ?, ?, ?, true)")
if err != nil {
return 0, errors.Wrap(err, "error preparing services insert statement")
}
res, err := stmt.Exec(envId, svc.ZitiServiceId, svc.Endpoint)
res, err := stmt.Exec(envId, svc.ZitiServiceId, svc.ZrokServiceId, svc.Frontend, svc.Backend)
if err != nil {
return 0, errors.Wrap(err, "error executing services insert statement")
}
@ -54,12 +56,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 ziti_service_id = ?, endpoint = ?, active = ?, updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now') where id = ?"
sql := "update services set ziti_service_id = ?, zrok_service_id = ?, frontend = ?, backend = ?, active = ?, updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now') where id = ?"
stmt, err := tx.Prepare(sql)
if err != nil {
return errors.Wrap(err, "error preparing services update statement")
}
_, err = stmt.Exec(svc.ZitiServiceId, svc.Endpoint, svc.Active, svc.Id)
_, err = stmt.Exec(svc.ZitiServiceId, svc.ZrokServiceId, svc.Frontend, svc.Backend, svc.Active, svc.Id)
if err != nil {
return errors.Wrap(err, "error executing services update statement")
}

View File

@ -52,7 +52,9 @@ create table services (
id integer primary key,
environment_id integer constraint fk_environments_services references environments on delete cascade,
ziti_service_id string not null unique,
endpoint string,
zrok_service_id string not null unique,
frontend string,
backend string,
active boolean not null,
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
updated_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),

View File

@ -93,9 +93,12 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
logrus.Infof("allocated service '%v'", svcName)
frontendUrl := self.proxyUrl(svcName)
sid, err := str.CreateService(envIdDb, &store.Service{
ZitiServiceId: svcId,
Endpoint: params.Body.Endpoint,
ZrokServiceId: svcName,
Frontend: frontendUrl,
Backend: params.Body.Endpoint,
}, tx)
if err != nil {
logrus.Errorf("error creating service record: %v", err)
@ -109,7 +112,7 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
logrus.Infof("recorded service '%v' with id '%v' for '%v'", svcId, sid, principal.Email)
return tunnel.NewTunnelCreated().WithPayload(&rest_model_zrok.TunnelResponse{
ProxyEndpoint: self.proxyUrl(svcName),
ProxyEndpoint: frontendUrl,
Service: svcName,
})
}