more naming simplification

This commit is contained in:
Michael Quigley 2022-10-19 12:24:43 -04:00
parent 2d75181483
commit 887db1d2b6
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
12 changed files with 34 additions and 34 deletions

View File

@ -43,10 +43,10 @@ func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
}
panic(err)
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.Token)
req := identity.NewDisableParams()
req.Body = &rest_model_zrok.DisableRequest{
Identity: env.ZitiIdentityId,
Identity: env.ZId,
}
_, err = zrok.Identity.Disable(req, auth)
if err != nil {
@ -66,5 +66,5 @@ func (cmd *disableCommand) run(_ *cobra.Command, args []string) {
showError("error removing zrok backend identity", err)
}
}
fmt.Printf("zrok environment '%v' disabled for '%v'\n", env.ZitiIdentityId, env.ZrokToken)
fmt.Printf("zrok environment '%v' disabled for '%v'\n", env.ZId, env.Token)
}

View File

@ -38,7 +38,7 @@ func newEnableCommand() *enableCommand {
func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
env, err := zrokdir.LoadEnvironment()
if err == nil {
showError(fmt.Sprintf("you already have an environment '%v' for '%v'", env.ZitiIdentityId, env.ZrokToken), nil)
showError(fmt.Sprintf("you already have an environment '%v' for '%v'", env.ZId, env.Token), nil)
}
token := args[0]
@ -73,7 +73,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
}
panic(err)
}
if err := zrokdir.SaveEnvironment(&zrokdir.Environment{ZrokToken: token, ZitiIdentityId: resp.Payload.Identity, ApiEndpoint: apiEndpoint}); err != nil {
if err := zrokdir.SaveEnvironment(&zrokdir.Environment{Token: token, ZId: resp.Payload.Identity, ApiEndpoint: apiEndpoint}); err != nil {
if !panicInstead {
showError("there was an error saving the new environment", err)
}

View File

@ -88,10 +88,10 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
}
panic(err)
}
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.ZrokToken)
auth := httptransport.APIKeyAuth("X-TOKEN", "header", env.Token)
req := tunnel.NewTunnelParams()
req.Body = &rest_model_zrok.TunnelRequest{
ZitiIdentityID: env.ZitiIdentityId,
ZitiIdentityID: env.ZId,
Endpoint: cfg.EndpointAddress,
AuthScheme: string(model.None),
}
@ -121,7 +121,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
self.destroy(env.ZitiIdentityId, cfg, zrok, auth)
self.destroy(env.ZId, cfg, zrok, auth)
os.Exit(0)
}()
@ -184,7 +184,7 @@ func (self *httpBackendCommand) run(_ *cobra.Command, args []string) {
switch e.ID {
case "q", "<C-c>":
ui.Close()
self.destroy(env.ZitiIdentityId, cfg, zrok, auth)
self.destroy(env.ZId, cfg, zrok, auth)
os.Exit(0)
}
}

View File

@ -163,10 +163,10 @@ func (l *looper) startup() {
if err != nil {
panic(err)
}
l.auth = httptransport.APIKeyAuth("x-token", "header", l.env.ZrokToken)
l.auth = httptransport.APIKeyAuth("x-token", "header", l.env.Token)
tunnelReq := tunnel.NewTunnelParams()
tunnelReq.Body = &rest_model_zrok.TunnelRequest{
ZitiIdentityID: l.env.ZitiIdentityId,
ZitiIdentityID: l.env.ZId,
Endpoint: fmt.Sprintf("looper#%d", l.id),
AuthScheme: string(model.None),
}
@ -233,7 +233,7 @@ func (l *looper) shutdown() {
untunnelReq := tunnel.NewUntunnelParams()
untunnelReq.Body = &rest_model_zrok.UntunnelRequest{
ZitiIdentityID: l.env.ZitiIdentityId,
ZitiIdentityID: l.env.ZId,
Service: l.service,
}
if _, err := l.zrok.Tunnel.Untunnel(untunnelReq, l.auth); err != nil {

View File

@ -63,7 +63,7 @@ func (self *disableHandler) checkZitiIdentity(id string, principal *rest_model_z
return -1, err
}
for _, env := range envs {
if env.ZitiIdentityId == id {
if env.ZId == id {
return env.Id, nil
}
}

View File

@ -57,10 +57,10 @@ func (self *enableHandler) Handle(params identity.EnableParams, principal *rest_
return identity.NewEnableInternalServerError()
}
envId, err := str.CreateEnvironment(int(principal.ID), &store.Environment{
Description: params.Body.Description,
Host: params.Body.Host,
Address: realRemoteAddress(params.HTTPRequest),
ZitiIdentityId: ident.Payload.Data.ID,
Description: params.Body.Description,
Host: params.Body.Host,
Address: realRemoteAddress(params.HTTPRequest),
ZId: ident.Payload.Data.ID,
}, tx)
if err != nil {
logrus.Errorf("error storing created identity: %v", err)

View File

@ -23,7 +23,7 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
for _, env := range envs {
svcs, err := str.FindServicesForEnvironment(env.Id, tx)
if err != nil {
logrus.Errorf("error finding services for environment '%v': %v", env.ZitiIdentityId, err)
logrus.Errorf("error finding services for environment '%v': %v", env.ZId, err)
return metadata.NewOverviewInternalServerError()
}
es := &rest_model_zrok.EnvironmentServices{
@ -34,7 +34,7 @@ func overviewHandler(_ metadata.OverviewParams, principal *rest_model_zrok.Princ
Description: env.Description,
Host: env.Host,
UpdatedAt: env.UpdatedAt.String(),
ZitiIdentityID: env.ZitiIdentityId,
ZitiIdentityID: env.ZId,
},
}
for _, svc := range svcs {

View File

@ -7,20 +7,20 @@ import (
type Environment struct {
Model
AccountId int
Description string
Host string
Address string
ZitiIdentityId string
Active bool
AccountId int
Description string
Host string
Address string
ZId string
Active bool
}
func (self *Store) CreateEnvironment(accountId int, i *Environment, tx *sqlx.Tx) (int, error) {
stmt, err := tx.Prepare("insert into environments (account_id, description, host, address, ziti_identity_id, active) values (?, ?, ?, ?, ?, true)")
stmt, err := tx.Prepare("insert into environments (account_id, description, host, address, z_id, active) values (?, ?, ?, ?, ?, true)")
if err != nil {
return 0, errors.Wrap(err, "error preparing environments insert statement")
}
res, err := stmt.Exec(accountId, i.Description, i.Host, i.Address, i.ZitiIdentityId)
res, err := stmt.Exec(accountId, i.Description, i.Host, i.Address, i.ZId)
if err != nil {
return 0, errors.Wrap(err, "error executing environments insert statement")
}

View File

@ -37,12 +37,12 @@ create table environments (
description string,
host string,
address string,
ziti_identity_id string not null unique,
z_id string not null unique,
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')),
constraint chk_ziti_identity_id check (ziti_identity_id <> '')
constraint chk_z_id check (z_id <> '')
);
--

View File

@ -42,7 +42,7 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
if envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx); err == nil {
found := false
for _, env := range envs {
if env.ZitiIdentityId == envId {
if env.ZId == envId {
logrus.Infof("found identity '%v' for user '%v'", envId, principal.Email)
envIdDb = env.Id
found = true

View File

@ -46,7 +46,7 @@ func (self *untunnelHandler) Handle(params tunnel.UntunnelParams, principal *res
var senv *store.Environment
if envs, err := str.FindEnvironmentsForAccount(int(principal.ID), tx); err == nil {
for _, env := range envs {
if env.ZitiIdentityId == params.Body.ZitiIdentityID {
if env.ZId == params.Body.ZitiIdentityID {
senv = env
break
}

View File

@ -9,9 +9,9 @@ import (
)
type Environment struct {
ZrokToken string `json:"zrok_token"`
ZitiIdentityId string `json:"ziti_identity"`
ApiEndpoint string `json:"api_endpoint"`
Token string `json:"zrok_token"`
ZId string `json:"ziti_identity"`
ApiEndpoint string `json:"api_endpoint"`
}
func LoadEnvironment() (*Environment, error) {