mirror of
https://github.com/openziti/zrok.git
synced 2024-12-26 00:29:15 +01:00
parent
f193976a50
commit
1fcb496321
69
controller/store/frontend.go
Normal file
69
controller/store/frontend.go
Normal file
@ -0,0 +1,69 @@
|
||||
package store
|
||||
|
||||
import (
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Frontend struct {
|
||||
Model
|
||||
EnvironmentId int
|
||||
ZId string
|
||||
Name *string
|
||||
}
|
||||
|
||||
func (str *Store) CreateFrontend(envId int, f *Frontend, tx *sqlx.Tx) (int, error) {
|
||||
stmt, err := tx.Prepare("insert into frontends (environment_id, z_id, name) values ($1, $2, $3) returning id")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error preparing frontends insert statement")
|
||||
}
|
||||
var id int
|
||||
if err := stmt.QueryRow(envId, f.ZId, f.Name).Scan(&id); err != nil {
|
||||
return 0, errors.Wrap(err, "error executing frontends insert statement")
|
||||
}
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (str *Store) GetFrontend(id int, tx *sqlx.Tx) (*Frontend, error) {
|
||||
i := &Frontend{}
|
||||
if err := tx.QueryRowx("select * from frontends where id = $1", id).StructScan(i); err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting frontend by id")
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (str *Store) FindFrontendNamed(name string, tx *sqlx.Tx) (*Frontend, error) {
|
||||
i := &Frontend{}
|
||||
if err := tx.QueryRowx("select frontends.* from frontends where name = $1", name).Scan(i); err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting frontend by name")
|
||||
}
|
||||
return i, nil
|
||||
}
|
||||
|
||||
func (str *Store) FindFrontendsForEnvironment(envId int, tx *sqlx.Tx) ([]*Frontend, error) {
|
||||
rows, err := tx.Queryx("select frontends.* from frontends where environment_id = $1", envId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "error selecting frontends by environment_id")
|
||||
}
|
||||
var is []*Frontend
|
||||
for rows.Next() {
|
||||
i := &Frontend{}
|
||||
if err := rows.StructScan(i); err != nil {
|
||||
return nil, errors.Wrap(err, "error scanning frontend")
|
||||
}
|
||||
is = append(is, i)
|
||||
}
|
||||
return is, nil
|
||||
}
|
||||
|
||||
func (str *Store) DeleteFrontend(id int, tx *sqlx.Tx) error {
|
||||
stmt, err := tx.Prepare("delete from frontends where id = $1")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing frontends delete statement")
|
||||
}
|
||||
_, err = stmt.Exec(id)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing frontends delete statement")
|
||||
}
|
||||
return nil
|
||||
}
|
1
controller/store/frontend_test.go
Normal file
1
controller/store/frontend_test.go
Normal file
@ -0,0 +1 @@
|
||||
package store
|
@ -2,7 +2,7 @@
|
||||
|
||||
create table frontends (
|
||||
id serial primary key,
|
||||
environment_id integer references environments(id),
|
||||
environment_id integer not null references environments(id),
|
||||
z_id varchar(32) not null unique,
|
||||
name varchar(64) unique,
|
||||
created_at timestamptz not null default(current_timestamp),
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
create table frontends (
|
||||
id serial primary key,
|
||||
environment_id integer references environments(id),
|
||||
environment_id integer not null references environments(id),
|
||||
z_id varchar(32) not null unique,
|
||||
name varchar(64) unique,
|
||||
created_at datetime not null default(strftime('%Y-%m-%d %H:%M:%f', 'now')),
|
||||
|
@ -1 +1 @@
|
||||
<mxfile host="Electron" modified="2022-11-16T17:17:30.495Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="q8HG4eKwCLBa5n6kjszd" version="20.3.0" type="device"><diagram id="oqxypaCZoQuY0yNYre-9" name="Page-1">7Vxbc9soFP41ftmZeix0sx9rJ023m3YyTXe22ZcdYhGLDRYqwrf8+kUS6IZiy17bUWxnMhM4QkfifN/hwAGlY46myxsGQ/8r9RDpgJ637JhX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xd4KJ+B/IP1cKhYILrPMSTf0ZjDYJJ4WWFcrwuTMpcGc9yoMM0TSaKDjz0PBfXQbUePBGjErucoxTt+HUjwJIhjEAqSyVJjCM2dIDT620EoteW23F4dJKJjgZjJDOOIGh1k4NWXtd/+vL09DYbsnxDLCnoFRJ298qOJtv3S49ftz+fRyLkffgMvQzP8ju2XryoDdwkYxwgYqzLMx4gftaDrc7EATtGpDgnreH9uIaLWFvosMpw9ErHouxDizEJE7QAHGiQS3tvSzXTfeu2WdeGydttbKM6Y2uK1m4L5snZb7xZbBuYtIdwUmBuoO8bIq0dmA5jWaTBk/4RYVtArIOrWpGh350cTbcegh54GuoSQ44WQN1jN1b+ynuE55eXcele4hA1hDP2swNml/LYgxNmFDXdz2ChsDEvkGmz/dgqbv72um20Gb9j/VccT09vUXvC+93+zA8ObNoAlcVqyAQzc8sLVNnbcADZBWZHlHHcDGOgHatZPVtqYRXCMshFbkEbQD8dc5oD/dw7Yb8yLN5v0mXpS7pJGqHGLy3xQcEVPNQ4GjnsaDNk/Ic5tPmjqGclLCDleCGlLGsHUk41nl0bIXOESNoQx9PTi2aURtiDE2YWN7b6X2jWNsFsWwT1UGqHpMXI132hJGsEeVNIIu54jd6xKGuFw58ifsXnz+6z34+M0uP/izW9u7r481HykfAjSgTfLXa07m/LOPqe11OfvKllSzTg15ZxlVxRVc2A7c05U84/u0+b5vy4wr/8D</diagram></mxfile>
|
||||
<mxfile host="Electron" modified="2022-11-17T18:39:26.490Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/20.3.0 Chrome/104.0.5112.114 Electron/20.1.3 Safari/537.36" etag="Va4ym45iM5ACQJZKhOlW" version="20.3.0" type="device"><diagram id="oqxypaCZoQuY0yNYre-9" name="Page-1">7VzbcqM4EP0av2zVuAziYj+OPZnsZpJUKp6tnezLlGJkWxuMGCHf8vUjQDIXERtY3xKTSqWkRmpQ91EfqQVpgcFsdU2hP70jDnJbesdZtcCXlq53DZv/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yQg5AXLZZKuxDUcqHWreZCoS2xZXV10OUD8/hKph8yanCQwKtuazUdGB8DIfsHxCrnvZRHrb3io4y2/cLj1+2Pl8HAGvbv9dc+8B+x+XonU2sNYRyDMNZZNx+DPwqdrq7FPDhDHzUkbMP9pVFEoS3UVaQ/f3b5pq8BxIVRRGGA00skEt7b1g3Yp967bYbQ7N32RsUbpJ7x3k26udm7bZ8WFYm5ogt3EXMJdceIvCozX9zerXqo33gv5VG7IEVbHx9ltB0DHmoaqKGQ41HICXZzxY+sZng+8nZu+1RoaIMbQ31X4P7v29sGEA1tRKaxd9NG6mBYeK7E8W8rdfjbadubw+Ad579aK3X6uzkL3vf57+a1zF0HwAI4Z3IArNvZjaup1TwABnpWkWEd9wBYV1+o2b5YOccsgqVljXgGaQT15ZhmDfh/14Dd0rg42aIPqEm5Jo1QMC2a9SDHippq7PUs+2MgZP+AuLT1IFAzkg2FHI9CziWNANRk48WlETZToaENbgw1vXhxaYQKgLg42qj2vVTdNEK9LIJ9qDRC2dfI5XrjTNIIZi+XRqj7Hrll5NIIh3uP/AWD67/mne+fZ97wxllcXz/cPBV8CnoI0Okny11tezdlJ+i0s8KcIT8ylsmSfMapLOYMM6conwPbH+ZuPPJtDG4nAYDDn/d3/fHouVcRc+/pw9AcUuqFRKsKOk8FRmBkPzAE3Rxjls6j5hTpeUW1wciryXf2cfPkfxWAq98=</diagram></mxfile>
|
Binary file not shown.
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
@ -48,6 +48,6 @@ The following illustration shows the possibilities available.
|
||||
|
||||
![v0.3 Frontend Selection](images/zrok_frontends_v0.3.png)
|
||||
|
||||
The `*.in.zrok.io` frontend is a "public" frontend, available to all `zrok` users. Most `zrok` installations will want to have at least one public, global frontend for all public, internet-facing ingress traffic for private backend instances. In the underlying data store, the public frontend will have a row in the `frontends` table with a `NULL` `environment_id`, and a `name` set to `public` (or some other representative name).
|
||||
The `*.in.zrok.io` frontend is a "public" frontend, available to all `zrok` users. Most `zrok` installations will want to have at least one public, global frontend for all public, internet-facing ingress traffic for private backend instances. In the underlying data store, the public frontend will have a `name` set to `public` (or some other representative name), allowing users to reference that `frontend` using a friendly label.
|
||||
|
||||
The other two "private" frontends are configured with an `environment_id` and no `name` label (the lack of a `name` label signifies that these are "private" frontends). The ephemeral environment is allocated when a `zrok` frontend request is made without an account on behalf of a private share.
|
||||
The other two "private" frontends are configured with no `name` label (the lack of a `name` label signifies that these are "private" frontends). The ephemeral environment is allocated when a `zrok` frontend request is made without an account on behalf of a private share.
|
||||
|
Loading…
Reference in New Issue
Block a user