further ziti identity naming cleanup (#369)

This commit is contained in:
Michael Quigley 2023-07-14 10:14:32 -04:00
parent 48cfaada20
commit 4713243e2c
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
15 changed files with 46 additions and 30 deletions

View File

@ -101,20 +101,20 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
case "tcpTunnel":
fe, err := tcpTunnel.NewFrontend(&tcpTunnel.FrontendConfig{
BindAddress: cmd.bindAddress,
IdentityName: "backend",
IdentityName: env.ShareIdentityName(),
ShrToken: args[0],
RequestsChan: requests,
})
if err != nil {
if !panicInstead {
tui.Error("unable to create private frontend", err)
tui.Error("unable to create private access", err)
}
panic(err)
}
go func() {
if err := fe.Run(); err != nil {
if !panicInstead {
tui.Error("error starting frontend", err)
tui.Error("error starting access", err)
}
panic(err)
}
@ -123,7 +123,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
case "udpTunnel":
fe, err := udpTunnel.NewFrontend(&udpTunnel.FrontendConfig{
BindAddress: cmd.bindAddress,
IdentityName: "backend",
IdentityName: env.ShareIdentityName(),
ShrToken: args[0],
RequestsChan: requests,
IdleTime: time.Minute,
@ -144,7 +144,7 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
}()
default:
cfg := proxy.DefaultFrontendConfig("backend")
cfg := proxy.DefaultFrontendConfig(env.ShareIdentityName())
cfg.ShrToken = shrToken
cfg.Address = cmd.bindAddress
cfg.RequestsChan = requests

View File

@ -36,7 +36,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
if err != nil {
panic(err)
}
zif, err := env.ZitiIdentityFile(name)
zif, err := env.ZitiIdentityNamed(name)
if err != nil {
panic(err)
}
@ -58,7 +58,7 @@ func (cmd *adminCreateIdentity) run(_ *cobra.Command, args []string) {
panic(err)
}
if err := env.SaveZitiIdentity(name, resp.Payload.Cfg); err != nil {
if err := env.SaveZitiIdentityNamed(name, resp.Payload.Cfg); err != nil {
panic(err)
}

View File

@ -65,7 +65,7 @@ func (cmd *disableCommand) run(_ *cobra.Command, _ []string) {
}
panic(err)
}
if err := env.DeleteZitiIdentity("backend"); err != nil {
if err := env.DeleteZitiIdentityNamed(env.ShareIdentityName()); err != nil {
if !panicInstead {
tui.Error("error removing zrok backend identity", err)
}

View File

@ -130,7 +130,7 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
}
os.Exit(1)
}
if err := env.SaveZitiIdentity("backend", resp.Payload.Cfg); err != nil {
if err := env.SaveZitiIdentityNamed(env.ShareIdentityName(), resp.Payload.Cfg); err != nil {
if !cmd.headless && prg != nil {
prg.Send(fmt.Sprintf("there was an error writing the environment: %v", err))
prg.Quit()

View File

@ -90,7 +90,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}
zif, err := env.ZitiIdentityFile("backend")
zif, err := env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
if !panicInstead {
tui.Error("unable to load ziti identity configuration", err)

View File

@ -84,7 +84,7 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
tui.Error("unable to load environment; did you 'zrok enable'?", nil)
}
zif, err := env.ZitiIdentityFile("backend")
zif, err := env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
if !panicInstead {
tui.Error("unable to load ziti identity configuration", err)

View File

@ -78,7 +78,7 @@ func (cmd *shareReservedCommand) run(_ *cobra.Command, args []string) {
target = resp.Payload.BackendProxyEndpoint
}
zif, err := env.ZitiIdentityFile("backend")
zif, err := env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
if !panicInstead {
tui.Error("unable to load ziti identity configuration", err)

View File

@ -186,7 +186,7 @@ func (l *looper) startup() {
}
l.env = env.Environment()
l.zif, err = env.ZitiIdentityFile("backend")
l.zif, err = env.ZitiIdentityNamed(env.ShareIdentityName())
if err != nil {
panic(err)
}

View File

@ -36,14 +36,19 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
return errors.Wrap(err, "error connecting to the ziti edge management api")
}
env, err := environment.LoadRoot()
if err != nil {
return err
}
var frontendZId string
if !skipFrontend {
logrus.Info("creating identity for frontend ziti access")
if frontendZId, err = getIdentityId("frontend"); err == nil {
if frontendZId, err = getIdentityId(env.AccessIdentityName()); err == nil {
logrus.Infof("frontend identity: %v", frontendZId)
} else {
frontendZId, err = bootstrapIdentity("frontend", edge)
frontendZId, err = bootstrapIdentity(env.AccessIdentityName(), edge)
if err != nil {
panic(err)
}
@ -51,7 +56,7 @@ func Bootstrap(skipFrontend bool, inCfg *config.Config) error {
if err := assertIdentity(frontendZId, edge); err != nil {
panic(err)
}
if err := assertErpForIdentity("frontend", frontendZId, edge); err != nil {
if err := assertErpForIdentity(env.AccessIdentityName(), frontendZId, edge); err != nil {
panic(err)
}
@ -117,7 +122,7 @@ func getIdentityId(identityName string) (string, error) {
if err != nil {
return "", errors.Wrap(err, "error opening environment root")
}
zif, err := env.ZitiIdentityFile(identityName)
zif, err := env.ZitiIdentityNamed(identityName)
if err != nil {
return "", errors.Wrapf(err, "error opening identity '%v' from environment", identityName)
}
@ -184,7 +189,7 @@ func bootstrapIdentity(name string, edge *rest_management_api_client.ZitiEdgeMan
if err != nil {
return "", errors.Wrapf(err, "error encoding identity config '%v'", name)
}
if err := env.SaveZitiIdentity(name, out.String()); err != nil {
if err := env.SaveZitiIdentityNamed(name, out.String()); err != nil {
return "", errors.Wrapf(err, "error saving identity config '%v'", name)
}
return zId, nil

View File

@ -44,7 +44,7 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.IdentityName)
zCfgPath, err := env.ZitiIdentityNamed(cfg.IdentityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName)
}

View File

@ -30,7 +30,7 @@ func NewHTTP(cfg *Config) (*httpFrontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.Identity)
zCfgPath, err := env.ZitiIdentityNamed(cfg.Identity)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.Identity)
}

View File

@ -33,7 +33,7 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.IdentityName)
zCfgPath, err := env.ZitiIdentityNamed(cfg.IdentityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName)
}

View File

@ -103,7 +103,7 @@ func NewFrontend(cfg *FrontendConfig) (*Frontend, error) {
if err != nil {
return nil, errors.Wrap(err, "error loading environment root")
}
zCfgPath, err := env.ZitiIdentityFile(cfg.IdentityName)
zCfgPath, err := env.ZitiIdentityNamed(cfg.IdentityName)
if err != nil {
return nil, errors.Wrapf(err, "error getting ziti identity '%v' from environment", cfg.IdentityName)
}

View File

@ -24,9 +24,12 @@ type Root interface {
SetEnvironment(env *env_core.Environment) error
DeleteEnvironment() error
ZitiIdentityFile(name string) (string, error)
SaveZitiIdentity(name, data string) error
DeleteZitiIdentity(name string) error
AccessIdentityName() string
ShareIdentityName() string
ZitiIdentityNamed(name string) (string, error)
SaveZitiIdentityNamed(name, data string) error
DeleteZitiIdentityNamed(name string) error
}
func LoadRoot() (Root, error) {

View File

@ -116,15 +116,23 @@ func (r *Root) IsEnabled() bool {
return r.env != nil
}
func (r *Root) ZitiIdentityFile(name string) (string, error) {
func (r *Root) AccessIdentityName() string {
return "frontend"
}
func (r *Root) ShareIdentityName() string {
return "backend"
}
func (r *Root) ZitiIdentityNamed(name string) (string, error) {
return identityFile(name)
}
func (r *Root) SaveZitiIdentity(name, data string) error {
func (r *Root) SaveZitiIdentityNamed(name, data string) error {
if err := assertMetadata(); err != nil {
return err
}
zif, err := r.ZitiIdentityFile(name)
zif, err := r.ZitiIdentityNamed(name)
if err != nil {
return err
}
@ -137,8 +145,8 @@ func (r *Root) SaveZitiIdentity(name, data string) error {
return nil
}
func (r *Root) DeleteZitiIdentity(name string) error {
zif, err := r.ZitiIdentityFile(name)
func (r *Root) DeleteZitiIdentityNamed(name string) error {
zif, err := r.ZitiIdentityNamed(name)
if err != nil {
return errors.Wrapf(err, "error getting ziti identity file path for '%v'", name)
}