mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
naming clarification
This commit is contained in:
parent
4a69d9dd31
commit
2d75181483
@ -76,7 +76,7 @@ func (self *disableHandler) removeServicesForEnvironment(envId int, tx *sqlx.Tx,
|
||||
return err
|
||||
}
|
||||
for _, svc := range svcs {
|
||||
svcName := svc.ZrokServiceId
|
||||
svcName := svc.Name
|
||||
logrus.Infof("garbage collecting service '%v'", svcName)
|
||||
if err := deleteServiceEdgeRouterPolicy(svcName, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
@ -90,10 +90,10 @@ func (self *disableHandler) removeServicesForEnvironment(envId int, tx *sqlx.Tx,
|
||||
if err := deleteConfig(svcName, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
if err := deleteService(svc.ZitiServiceId, edge); err != nil {
|
||||
if err := deleteService(svc.ZId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
logrus.Infof("removed service '%v'", svc.ZrokServiceId)
|
||||
logrus.Infof("removed service '%v'", svc.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ func GC(cfg *Config) error {
|
||||
}
|
||||
liveMap := make(map[string]struct{})
|
||||
for _, dbSvc := range dbSvcs {
|
||||
liveMap[dbSvc.ZrokServiceId] = struct{}{}
|
||||
liveMap[dbSvc.Name] = struct{}{}
|
||||
}
|
||||
if err := gcServices(edge, liveMap); err != nil {
|
||||
return errors.Wrap(err, "error garbage collecting services")
|
||||
|
@ -44,8 +44,8 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
|
||||
Frontend: svc.Frontend,
|
||||
Backend: svc.Backend,
|
||||
UpdatedAt: svc.UpdatedAt.String(),
|
||||
ZitiServiceID: svc.ZitiServiceId,
|
||||
ZrokServiceID: svc.ZrokServiceId,
|
||||
ZitiServiceID: svc.ZId,
|
||||
ZrokServiceID: svc.Name,
|
||||
})
|
||||
}
|
||||
out = append(out, es)
|
||||
|
@ -8,19 +8,19 @@ import (
|
||||
type Service struct {
|
||||
Model
|
||||
EnvironmentId int
|
||||
ZitiServiceId string
|
||||
ZrokServiceId string
|
||||
ZId string
|
||||
Name 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, zrok_service_id, frontend, backend, active) values (?, ?, ?, ?, ?, true)")
|
||||
stmt, err := tx.Prepare("insert into services (environment_id, z_id, name, 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.ZrokServiceId, svc.Frontend, svc.Backend)
|
||||
res, err := stmt.Exec(envId, svc.ZId, svc.Name, svc.Frontend, svc.Backend)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error executing services insert statement")
|
||||
}
|
||||
@ -72,12 +72,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 = ?, zrok_service_id = ?, frontend = ?, backend = ?, active = ?, updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now') where id = ?"
|
||||
sql := "update services set z_id = ?, name = ?, 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.ZrokServiceId, svc.Frontend, svc.Backend, svc.Active, svc.Id)
|
||||
_, err = stmt.Exec(svc.ZId, svc.Name, svc.Frontend, svc.Backend, svc.Active, svc.Id)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing services update statement")
|
||||
}
|
||||
|
@ -32,17 +32,17 @@ create table account_requests (
|
||||
-- environments
|
||||
--
|
||||
create table environments (
|
||||
id integer primary key,
|
||||
account_id integer constraint fk_accounts_identities references accounts on delete cascade,
|
||||
description string,
|
||||
host string,
|
||||
address string,
|
||||
ziti_identity_id string not null unique,
|
||||
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')),
|
||||
id integer primary key,
|
||||
account_id integer constraint fk_accounts_identities references accounts on delete cascade,
|
||||
description string,
|
||||
host string,
|
||||
address string,
|
||||
ziti_identity_id string not null unique,
|
||||
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')),
|
||||
|
||||
constraint chk_ziti_identity_id check (ziti_identity_id <> '')
|
||||
constraint chk_ziti_identity_id check (ziti_identity_id <> '')
|
||||
);
|
||||
|
||||
--
|
||||
@ -51,13 +51,14 @@ create table environments (
|
||||
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,
|
||||
zrok_service_id string not null unique,
|
||||
z_id string not null unique,
|
||||
name 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')),
|
||||
|
||||
constraint chk_ziti_service_id check (ziti_service_id <> '')
|
||||
constraint chk_z_id check (z_id <> ''),
|
||||
constraint chk_name check (name <> '')
|
||||
);
|
@ -73,20 +73,20 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
|
||||
logrus.Error(err)
|
||||
return tunnel.NewTunnelInternalServerError()
|
||||
}
|
||||
svcId, err := self.createService(svcName, cfgId, edge)
|
||||
svcZId, err := self.createService(svcName, cfgId, edge)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return tunnel.NewTunnelInternalServerError()
|
||||
}
|
||||
if err := self.createServicePolicyBind(svcName, svcId, envId, edge); err != nil {
|
||||
if err := self.createServicePolicyBind(svcName, svcZId, envId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return tunnel.NewTunnelInternalServerError()
|
||||
}
|
||||
if err := self.createServicePolicyDial(svcName, svcId, edge); err != nil {
|
||||
if err := self.createServicePolicyDial(svcName, svcZId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return tunnel.NewTunnelInternalServerError()
|
||||
}
|
||||
if err := self.createServiceEdgeRouterPolicy(svcName, svcId, edge); err != nil {
|
||||
if err := self.createServiceEdgeRouterPolicy(svcName, svcZId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return tunnel.NewTunnelInternalServerError()
|
||||
}
|
||||
@ -95,10 +95,10 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
|
||||
|
||||
frontendUrl := self.proxyUrl(svcName)
|
||||
sid, err := str.CreateService(envIdDb, &store.Service{
|
||||
ZitiServiceId: svcId,
|
||||
ZrokServiceId: svcName,
|
||||
Frontend: frontendUrl,
|
||||
Backend: params.Body.Endpoint,
|
||||
ZId: svcZId,
|
||||
Name: svcName,
|
||||
Frontend: frontendUrl,
|
||||
Backend: params.Body.Endpoint,
|
||||
}, tx)
|
||||
if err != nil {
|
||||
logrus.Errorf("error creating service record: %v", err)
|
||||
@ -109,7 +109,7 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
|
||||
logrus.Errorf("error committing service record: %v", err)
|
||||
return tunnel.NewTunnelInternalServerError()
|
||||
}
|
||||
logrus.Infof("recorded service '%v' with id '%v' for '%v'", svcId, sid, principal.Email)
|
||||
logrus.Infof("recorded service '%v' with id '%v' for '%v'", svcZId, sid, principal.Email)
|
||||
|
||||
return tunnel.NewTunnelCreated().WithPayload(&rest_model_zrok.TunnelResponse{
|
||||
ProxyEndpoint: frontendUrl,
|
||||
|
@ -38,7 +38,7 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
|
||||
return tunnel.NewUntunnelInternalServerError()
|
||||
}
|
||||
svcName := params.Body.Service
|
||||
svcId, err := self.findServiceId(svcName, edge)
|
||||
svcZId, err := self.findServiceZId(svcName, edge)
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return tunnel.NewUntunnelInternalServerError()
|
||||
@ -64,13 +64,13 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
|
||||
var ssvc *store.Service
|
||||
if svcs, err := str.FindServicesForEnvironment(senv.Id, tx); err == nil {
|
||||
for _, svc := range svcs {
|
||||
if svc.ZitiServiceId == svcId {
|
||||
if svc.ZId == svcZId {
|
||||
ssvc = svc
|
||||
break
|
||||
}
|
||||
}
|
||||
if ssvc == nil {
|
||||
err := errors.Errorf("service with id '%v' not found for '%v'", svcId, principal.Email)
|
||||
err := errors.Errorf("service with id '%v' not found for '%v'", svcZId, principal.Email)
|
||||
logrus.Error(err)
|
||||
return tunnel.NewUntunnelNotFound()
|
||||
}
|
||||
@ -95,7 +95,7 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
|
||||
logrus.Error(err)
|
||||
return tunnel.NewTunnelInternalServerError()
|
||||
}
|
||||
if err := deleteService(svcId, edge); err != nil {
|
||||
if err := deleteService(svcZId, edge); err != nil {
|
||||
logrus.Error(err)
|
||||
return tunnel.NewUntunnelInternalServerError()
|
||||
}
|
||||
@ -104,7 +104,7 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
|
||||
|
||||
ssvc.Active = false
|
||||
if err := str.UpdateService(ssvc, tx); err != nil {
|
||||
logrus.Errorf("error deactivating service '%v': %v", svcId, err)
|
||||
logrus.Errorf("error deactivating service '%v': %v", svcZId, err)
|
||||
return tunnel.NewUntunnelInternalServerError()
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
@ -115,7 +115,7 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
|
||||
return tunnel.NewUntunnelOK()
|
||||
}
|
||||
|
||||
func (_ *untunnelHandler) findServiceId(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
func (_ *untunnelHandler) findServiceZId(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) (string, error) {
|
||||
filter := fmt.Sprintf("name=\"%v\"", svcName)
|
||||
limit := int64(1)
|
||||
offset := int64(0)
|
||||
|
Loading…
Reference in New Issue
Block a user