mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
frontends.name -> frontends.token (#119)
This commit is contained in:
parent
0f9ed9dd68
commit
f54d315e34
@ -61,13 +61,13 @@ func (h *accessHandler) Handle(params service.AccessParams, principal *rest_mode
|
||||
return service.NewAccessNotFound()
|
||||
}
|
||||
|
||||
frontendName, err := createToken()
|
||||
feToken, err := createToken()
|
||||
if err != nil {
|
||||
logrus.Error(err)
|
||||
return service.NewAccessInternalServerError()
|
||||
}
|
||||
|
||||
if _, err := str.CreateFrontend(envId, &store.Frontend{Name: frontendName, ZId: envZId}, tx); err != nil {
|
||||
if _, err := str.CreateFrontend(envId, &store.Frontend{Token: feToken, ZId: envZId}, tx); err != nil {
|
||||
logrus.Errorf("error creating frontend record: %v", err)
|
||||
return service.NewAccessInternalServerError()
|
||||
}
|
||||
@ -79,7 +79,7 @@ func (h *accessHandler) Handle(params service.AccessParams, principal *rest_mode
|
||||
}
|
||||
extraTags := &rest_model_edge.Tags{SubTags: map[string]interface{}{
|
||||
"zrokEnvironmentZId": envZId,
|
||||
"zrokFrontendName": frontendName,
|
||||
"zrokFrontendToken": feToken,
|
||||
}}
|
||||
if err := createServicePolicyDialForEnvironment(envZId, ssvc.Name, ssvc.ZId, edge, extraTags); err != nil {
|
||||
logrus.Errorf("unable to create dial policy: %v", err)
|
||||
@ -91,7 +91,7 @@ func (h *accessHandler) Handle(params service.AccessParams, principal *rest_mode
|
||||
return service.NewAccessInternalServerError()
|
||||
}
|
||||
|
||||
return service.NewAccessCreated().WithPayload(&rest_model_zrok.AccessResponse{FrontendName: frontendName})
|
||||
return service.NewAccessCreated().WithPayload(&rest_model_zrok.AccessResponse{FrontendName: feToken})
|
||||
}
|
||||
|
||||
func createServicePolicyDialForEnvironment(envZId, svcName, svcZId string, edge *rest_management_api_client.ZitiEdgeManagement, tags ...*rest_model.Tags) error {
|
||||
|
@ -8,19 +8,19 @@ import (
|
||||
type Frontend struct {
|
||||
Model
|
||||
EnvironmentId int
|
||||
Name string
|
||||
Token string
|
||||
ZId string
|
||||
PublicName *string
|
||||
Reserved bool
|
||||
}
|
||||
|
||||
func (str *Store) CreateFrontend(envId int, f *Frontend, tx *sqlx.Tx) (int, error) {
|
||||
stmt, err := tx.Prepare("insert into frontends (environment_id, name, z_id, public_name, reserved) values ($1, $2, $3, $4, $5) returning id")
|
||||
stmt, err := tx.Prepare("insert into frontends (environment_id, token, z_id, public_name, reserved) values ($1, $2, $3, $4, $5) returning id")
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "error preparing frontends insert statement")
|
||||
}
|
||||
var id int
|
||||
if err := stmt.QueryRow(envId, f.Name, f.ZId, f.PublicName, f.Reserved).Scan(&id); err != nil {
|
||||
if err := stmt.QueryRow(envId, f.Token, f.ZId, f.PublicName, f.Reserved).Scan(&id); err != nil {
|
||||
return 0, errors.Wrap(err, "error executing frontends insert statement")
|
||||
}
|
||||
return id, nil
|
||||
|
@ -31,7 +31,7 @@ func TestPublicFrontend(t *testing.T) {
|
||||
|
||||
feName := "public"
|
||||
feId, err := str.CreateFrontend(envId, &Frontend{
|
||||
Name: "name",
|
||||
Token: "token",
|
||||
ZId: "zId0",
|
||||
PublicName: &feName,
|
||||
}, tx)
|
||||
|
@ -3,7 +3,7 @@
|
||||
create table frontends (
|
||||
id serial primary key,
|
||||
environment_id integer not null references environments(id),
|
||||
name varchar(32) not null unique,
|
||||
token varchar(32) not null unique,
|
||||
z_id varchar(32) not null unique,
|
||||
public_name varchar(64) unique,
|
||||
reserved boolean not null default(false),
|
||||
|
@ -20,7 +20,7 @@ drop table environments_old;
|
||||
create table frontends (
|
||||
id integer primary key,
|
||||
environment_id integer not null references environments(id),
|
||||
name varchar(32) not null unique,
|
||||
token varchar(32) not null unique,
|
||||
z_id varchar(32) not null unique,
|
||||
public_name varchar(64) unique,
|
||||
reserved boolean not null default(false),
|
||||
|
@ -69,7 +69,7 @@ func (h *unaccessHandler) Handle(params service.UnaccessParams, principal *rest_
|
||||
return service.NewUnaccessNotFound()
|
||||
}
|
||||
|
||||
if err := deleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceName=\"%v\" and tags.zrokFrontendName=\"%v\" and type=1", svcName, frontendName), edge); err != nil {
|
||||
if err := deleteServicePolicy(envZId, fmt.Sprintf("tags.zrokServiceName=\"%v\" and tags.zrokFrontendToken=\"%v\" and type=1", svcName, frontendName), edge); err != nil {
|
||||
logrus.Errorf("error removing access to '%v' for '%v': %v", svcName, envZId, err)
|
||||
return service.NewUnaccessInternalServerError()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user