Skip to content

Commit 8a8711e

Browse files
committed
warp: refactor identity creation
Signed-off-by: Mark Pashmfouroush <mark@markpash.me>
1 parent cdb551a commit 8a8711e

File tree

2 files changed

+213
-480
lines changed

2 files changed

+213
-480
lines changed

app/app.go

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func RunWarp(ctx context.Context, l *slog.Logger, opts WarpOptions) error {
4040
}
4141

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

209212
func createPrimaryAndSecondaryIdentities(l *slog.Logger, license string) error {
210213
// make primary identity
211-
warp.UpdatePath("./primary")
212-
if !warp.CheckProfileExists(license) {
213-
err := warp.LoadOrCreateIdentity(l, license)
214-
if err != nil {
215-
return err
216-
}
217-
}
218-
// make secondary
219-
warp.UpdatePath("./secondary")
220-
if !warp.CheckProfileExists(license) {
221-
err := warp.LoadOrCreateIdentity(l, license)
222-
if err != nil {
223-
return err
224-
}
225-
}
226-
return nil
227-
}
228-
229-
func makeDirs() error {
230-
stuffDir := "stuff"
231-
primaryDir := "primary"
232-
secondaryDir := "secondary"
233-
234-
// Check if 'stuff' directory exists, if not create it
235-
if _, err := os.Stat(stuffDir); os.IsNotExist(err) {
236-
if err := os.Mkdir(stuffDir, 0o755); err != nil {
237-
return fmt.Errorf("error creating 'stuff' directory: %w", err)
238-
}
214+
err := warp.LoadOrCreateIdentity(l, "./primary", license)
215+
if err != nil {
216+
l.Error("couldn't load primary warp identity")
217+
return err
239218
}
240219

241-
// Create 'primary' and 'secondary' directories if they don't exist
242-
for _, dir := range []string{primaryDir, secondaryDir} {
243-
if _, err := os.Stat(filepath.Join(stuffDir, dir)); os.IsNotExist(err) {
244-
if err := os.Mkdir(filepath.Join(stuffDir, dir), 0o755); err != nil {
245-
return fmt.Errorf("error creating '%s' directory: %w", dir, err)
246-
}
247-
}
220+
// make secondary
221+
err = warp.LoadOrCreateIdentity(l, "./secondary", license)
222+
if err != nil {
223+
l.Error("couldn't load secondary warp identity")
224+
return err
248225
}
249226

250227
return nil

0 commit comments

Comments
 (0)