From 9db6aa1c07ab864c0a5b58b9c8d4b62952304a2f Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Thu, 1 Dec 2022 14:56:55 -0500 Subject: [PATCH] frontends.environment_id is now nullable; support anonymous public frontends (#110, #129) --- controller/store/frontend.go | 3 ++- controller/store/frontend_test.go | 2 +- .../store/sql/postgresql/002_v0_3_0_frontend_selection.sql | 3 ++- controller/store/sql/sqlite3/002_v0_3_0_frontend_selection.sql | 2 +- controller/unaccess.go | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/controller/store/frontend.go b/controller/store/frontend.go index 8fa883eb..a1643edd 100644 --- a/controller/store/frontend.go +++ b/controller/store/frontend.go @@ -7,10 +7,11 @@ import ( type Frontend struct { Model - EnvironmentId int + EnvironmentId *int Token string ZId string PublicName *string + UrlTemplate *string Reserved bool } diff --git a/controller/store/frontend_test.go b/controller/store/frontend_test.go index 24aa191c..24b6cd4c 100644 --- a/controller/store/frontend_test.go +++ b/controller/store/frontend_test.go @@ -40,7 +40,7 @@ func TestPublicFrontend(t *testing.T) { fe, err := str.GetFrontend(feId, tx) assert.Nil(t, err) assert.NotNil(t, fe) - assert.Equal(t, envId, fe.EnvironmentId) + assert.Equal(t, envId, *fe.EnvironmentId) assert.Equal(t, feName, *fe.PublicName) fe0, err := str.FindFrontendPubliclyNamed(feName, tx) diff --git a/controller/store/sql/postgresql/002_v0_3_0_frontend_selection.sql b/controller/store/sql/postgresql/002_v0_3_0_frontend_selection.sql index ff6d5158..91455144 100644 --- a/controller/store/sql/postgresql/002_v0_3_0_frontend_selection.sql +++ b/controller/store/sql/postgresql/002_v0_3_0_frontend_selection.sql @@ -2,9 +2,10 @@ create table frontends ( id serial primary key, - environment_id integer not null references environments(id), + environment_id integer references environments(id), token varchar(32) not null unique, z_id varchar(32) not null, + url_template varchar(1024), public_name varchar(64) unique, reserved boolean not null default(false), created_at timestamptz not null default(current_timestamp), diff --git a/controller/store/sql/sqlite3/002_v0_3_0_frontend_selection.sql b/controller/store/sql/sqlite3/002_v0_3_0_frontend_selection.sql index d8dc53e1..a047acf8 100644 --- a/controller/store/sql/sqlite3/002_v0_3_0_frontend_selection.sql +++ b/controller/store/sql/sqlite3/002_v0_3_0_frontend_selection.sql @@ -19,7 +19,7 @@ drop table environments_old; create table frontends ( id integer primary key, - environment_id integer not null references environments(id), + environment_id integer references environments(id), token varchar(32) not null unique, z_id varchar(32) not null, public_name varchar(64) unique, diff --git a/controller/unaccess.go b/controller/unaccess.go index 1f30d353..f9fc2f8e 100644 --- a/controller/unaccess.go +++ b/controller/unaccess.go @@ -59,7 +59,7 @@ func (h *unaccessHandler) Handle(params service.UnaccessParams, principal *rest_ return service.NewUnaccessInternalServerError() } - if sfe == nil || sfe.EnvironmentId != senv.Id { + if sfe == nil || (sfe.EnvironmentId != nil && *sfe.EnvironmentId != senv.Id) { logrus.Errorf("frontend named '%v' not found", feToken) return service.NewUnaccessInternalServerError() }