diff --git a/controller/overview.go b/controller/overview.go index 857c1b2d..1ae9216b 100644 --- a/controller/overview.go +++ b/controller/overview.go @@ -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) diff --git a/controller/store/service.go b/controller/store/service.go index 51afc453..4cbbddd7 100644 --- a/controller/store/service.go +++ b/controller/store/service.go @@ -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") } diff --git a/controller/store/sql/000_base.sql b/controller/store/sql/000_base.sql index 9f04153a..8fc00183 100644 --- a/controller/store/sql/000_base.sql +++ b/controller/store/sql/000_base.sql @@ -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')), diff --git a/controller/tunnel.go b/controller/tunnel.go index 76d92d3d..be077b4b 100644 --- a/controller/tunnel.go +++ b/controller/tunnel.go @@ -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, }) } diff --git a/rest_model_zrok/service.go b/rest_model_zrok/service.go index f2f430b3..59bf44d8 100644 --- a/rest_model_zrok/service.go +++ b/rest_model_zrok/service.go @@ -20,17 +20,23 @@ type Service struct { // active Active bool `json:"active,omitempty"` + // backend + Backend string `json:"backend,omitempty"` + // created at CreatedAt string `json:"createdAt,omitempty"` - // endpoint - Endpoint string `json:"endpoint,omitempty"` + // frontend + Frontend string `json:"frontend,omitempty"` // updated at UpdatedAt string `json:"updatedAt,omitempty"` // ziti service Id ZitiServiceID string `json:"zitiServiceId,omitempty"` + + // zrok service Id + ZrokServiceID string `json:"zrokServiceId,omitempty"` } // Validate validates this service diff --git a/rest_server_zrok/embedded_spec.go b/rest_server_zrok/embedded_spec.go index f166afbe..02cdd8ab 100644 --- a/rest_server_zrok/embedded_spec.go +++ b/rest_server_zrok/embedded_spec.go @@ -523,10 +523,13 @@ func init() { "active": { "type": "boolean" }, + "backend": { + "type": "string" + }, "createdAt": { "type": "string" }, - "endpoint": { + "frontend": { "type": "string" }, "updatedAt": { @@ -534,6 +537,9 @@ func init() { }, "zitiServiceId": { "type": "string" + }, + "zrokServiceId": { + "type": "string" } } }, @@ -1119,10 +1125,13 @@ func init() { "active": { "type": "boolean" }, + "backend": { + "type": "string" + }, "createdAt": { "type": "string" }, - "endpoint": { + "frontend": { "type": "string" }, "updatedAt": { @@ -1130,6 +1139,9 @@ func init() { }, "zitiServiceId": { "type": "string" + }, + "zrokServiceId": { + "type": "string" } } }, diff --git a/specs/zrok.yml b/specs/zrok.yml index 8123e28f..f761c728 100644 --- a/specs/zrok.yml +++ b/specs/zrok.yml @@ -343,7 +343,11 @@ definitions: properties: zitiServiceId: type: string - endpoint: + zrokServiceId: + type: string + frontend: + type: string + backend: type: string active: type: boolean diff --git a/ui/src/Network.js b/ui/src/Network.js index c992e519..148fda11 100644 --- a/ui/src/Network.js +++ b/ui/src/Network.js @@ -82,7 +82,7 @@ function buildGraph(overview) { if(item.active) { out.nodes.push({ id: '' + id, - data: {label: