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
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
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,
})
}

View File

@ -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

View File

@ -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"
}
}
},

View File

@ -343,7 +343,11 @@ definitions:
properties:
zitiServiceId:
type: string
endpoint:
zrokServiceId:
type: string
frontend:
type: string
backend:
type: string
active:
type: boolean

View File

@ -82,7 +82,7 @@ function buildGraph(overview) {
if(item.active) {
out.nodes.push({
id: '' + id,
data: {label: <div><Icon path={mdiAccessPointNetwork} size={0.75} className={"flowNode"}/> { item.endpoint }</div>},
data: {label: <div><Icon path={mdiAccessPointNetwork} size={0.75} className={"flowNode"}/> { item.frontend }</div>},
position: {x: (id * 25), y: 0},
style: { width: 'fit-content', backgroundColor: '#9367ef', color: 'white' },
type: 'output',

View File

@ -8,20 +8,15 @@ const Services = (props) => {
const columns = [
{
name: 'Endpoint',
selector: row => row.endpoint,
name: 'Frontend',
selector: row => row.frontend,
sortable: true,
},
{
name: 'Service',
selector: row => row.zitiServiceId,
name: 'Backend',
selector: row => row.backend,
sortable: true,
},
{
name: 'Updated',
selector: row => row.updatedAt,
sortable: true
}
]
const conditionalRowStyles = [

View File

@ -97,7 +97,9 @@
* @memberof module:types
*
* @property {string} zitiServiceId
* @property {string} endpoint
* @property {string} zrokServiceId
* @property {string} frontend
* @property {string} backend
* @property {boolean} active
* @property {string} createdAt
* @property {string} updatedAt