Skip to content

Commit

Permalink
warp: refactor identity creation
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Pashmfouroush <[email protected]>
  • Loading branch information
markpash committed Mar 29, 2024
1 parent cdb551a commit 8a8711e
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 480 deletions.
49 changes: 13 additions & 36 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func RunWarp(ctx context.Context, l *slog.Logger, opts WarpOptions) error {
}

// create necessary file structures
if err := makeDirs(); err != nil {
if err := os.MkdirAll(filepath.Join("stuff", "primary"), os.ModePerm); err != nil {
return err
}
if err := os.MkdirAll(filepath.Join("stuff", "secondary"), os.ModePerm); err != nil {
return err
}
l.Debug("'primary' and 'secondary' directories are ready")
Expand Down Expand Up @@ -208,43 +211,17 @@ func runWarpInWarp(ctx context.Context, l *slog.Logger, bind netip.AddrPort, end

func createPrimaryAndSecondaryIdentities(l *slog.Logger, license string) error {
// make primary identity
warp.UpdatePath("./primary")
if !warp.CheckProfileExists(license) {
err := warp.LoadOrCreateIdentity(l, license)
if err != nil {
return err
}
}
// make secondary
warp.UpdatePath("./secondary")
if !warp.CheckProfileExists(license) {
err := warp.LoadOrCreateIdentity(l, license)
if err != nil {
return err
}
}
return nil
}

func makeDirs() error {
stuffDir := "stuff"
primaryDir := "primary"
secondaryDir := "secondary"

// Check if 'stuff' directory exists, if not create it
if _, err := os.Stat(stuffDir); os.IsNotExist(err) {
if err := os.Mkdir(stuffDir, 0o755); err != nil {
return fmt.Errorf("error creating 'stuff' directory: %w", err)
}
err := warp.LoadOrCreateIdentity(l, "./primary", license)
if err != nil {
l.Error("couldn't load primary warp identity")
return err
}

// Create 'primary' and 'secondary' directories if they don't exist
for _, dir := range []string{primaryDir, secondaryDir} {
if _, err := os.Stat(filepath.Join(stuffDir, dir)); os.IsNotExist(err) {
if err := os.Mkdir(filepath.Join(stuffDir, dir), 0o755); err != nil {
return fmt.Errorf("error creating '%s' directory: %w", dir, err)
}
}
// make secondary
err = warp.LoadOrCreateIdentity(l, "./secondary", license)
if err != nil {
l.Error("couldn't load secondary warp identity")
return err
}

return nil
Expand Down
Loading

0 comments on commit 8a8711e

Please sign in to comment.