@@ -6,6 +6,7 @@ package devbox
6
6
import (
7
7
"context"
8
8
"fmt"
9
+ "io"
9
10
"io/fs"
10
11
"os"
11
12
"path/filepath"
@@ -17,8 +18,10 @@ import (
17
18
"github.com/pkg/errors"
18
19
"github.com/samber/lo"
19
20
"go.jetpack.io/devbox/internal/devbox/devopt"
21
+ "go.jetpack.io/devbox/internal/devconfig"
20
22
"go.jetpack.io/devbox/internal/devpkg"
21
23
"go.jetpack.io/devbox/internal/devpkg/pkgtype"
24
+ "go.jetpack.io/devbox/internal/lock"
22
25
"go.jetpack.io/devbox/internal/nix/nixprofile"
23
26
"go.jetpack.io/devbox/internal/shellgen"
24
27
@@ -516,3 +519,51 @@ func (d *Devbox) packagesToInstallInProfile(ctx context.Context) ([]*devpkg.Pack
516
519
}
517
520
return packagesToInstall , nil
518
521
}
522
+
523
+ // moveAllowInsecureFromLockfile will modernize a Devbox project by moving the allow_insecure: boolean
524
+ // setting from the devbox.lock file to the corresponding package in devbox.json.
525
+ //
526
+ // NOTE: ideally, this function would be in devconfig, but it leads to an import cycle with devpkg, so
527
+ // leaving in this "top-level" devbox package where we can import devconfig, devpkg and lock.
528
+ func (d * Devbox ) moveAllowInsecureFromLockfile (writer io.Writer , lockfile * lock.File , cfg * devconfig.Config ) error {
529
+ if ! lockfile .HasAllowInsecurePackages () {
530
+ return nil
531
+ }
532
+
533
+ insecurePackages := []string {}
534
+ for name , pkg := range lockfile .Packages {
535
+ if pkg .AllowInsecure {
536
+ insecurePackages = append (insecurePackages , name )
537
+ }
538
+ pkg .AllowInsecure = false
539
+ }
540
+
541
+ // Set the devbox.json packages to allow_insecure
542
+ for _ , versionedName := range insecurePackages {
543
+ pkg := devpkg .PackageFromStringWithDefaults (versionedName , lockfile )
544
+ storeName , err := pkg .StoreName ()
545
+ if err != nil {
546
+ return fmt .Errorf ("failed to get package's store name for package %q with error %w" , versionedName , err )
547
+ }
548
+ if err := cfg .Packages .SetAllowInsecure (writer , versionedName , []string {storeName }); err != nil {
549
+ return fmt .Errorf ("failed to set allow_insecure in devbox.json for package %q with error %w" , versionedName , err )
550
+ }
551
+ }
552
+
553
+ if err := d .saveCfg (); err != nil {
554
+ return err
555
+ }
556
+
557
+ // Now, clear it from the lockfile
558
+ if err := lockfile .Save (); err != nil {
559
+ return err
560
+ }
561
+
562
+ ux .Finfo (
563
+ writer ,
564
+ "Modernized the allow_insecure setting for package %q by moving it from devbox.lock to devbox.json. Please commit the changes.\n " ,
565
+ strings .Join (insecurePackages , ", " ),
566
+ )
567
+
568
+ return nil
569
+ }
0 commit comments