moveAllowInsecureFromLockfile will modernize a Devbox project by moving the allow_insecure: boolean setting from the devbox.lock file to the corresponding package in devbox.json. NOTE: ideally, this function would be in devconfig, but it leads to an import cycle with devpkg, so leaving in this "top
(writer io.Writer, lockfile *lock.File, cfg *devconfig.Config)
| 681 | // NOTE: ideally, this function would be in devconfig, but it leads to an import cycle with devpkg, so |
| 682 | // leaving in this "top-level" devbox package where we can import devconfig, devpkg and lock. |
| 683 | func (d *Devbox) moveAllowInsecureFromLockfile(writer io.Writer, lockfile *lock.File, cfg *devconfig.Config) error { |
| 684 | if !lockfile.HasAllowInsecurePackages() { |
| 685 | return nil |
| 686 | } |
| 687 | |
| 688 | insecurePackages := []string{} |
| 689 | for name, pkg := range lockfile.Packages { |
| 690 | if pkg.AllowInsecure { |
| 691 | insecurePackages = append(insecurePackages, name) |
| 692 | } |
| 693 | pkg.AllowInsecure = false |
| 694 | } |
| 695 | |
| 696 | // Set the devbox.json packages to allow_insecure |
| 697 | for _, versionedName := range insecurePackages { |
| 698 | pkg := devpkg.PackageFromStringWithDefaults(versionedName, lockfile) |
| 699 | storeName, err := pkg.StoreName() |
| 700 | if err != nil { |
| 701 | return fmt.Errorf("failed to get package's store name for package %q with error %w", versionedName, err) |
| 702 | } |
| 703 | if err := cfg.PackageMutator().SetAllowInsecure(writer, versionedName, []string{storeName}); err != nil { |
| 704 | return fmt.Errorf("failed to set allow_insecure in devbox.json for package %q with error %w", versionedName, err) |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | if err := d.saveCfg(); err != nil { |
| 709 | return err |
| 710 | } |
| 711 | |
| 712 | // Now, clear it from the lockfile |
| 713 | if err := lockfile.Save(); err != nil { |
| 714 | return err |
| 715 | } |
| 716 | |
| 717 | ux.Finfof( |
| 718 | writer, |
| 719 | "Modernized the allow_insecure setting for package %q by moving it from devbox.lock to devbox.json. Please commit the changes.\n", |
| 720 | strings.Join(insecurePackages, ", "), |
| 721 | ) |
| 722 | |
| 723 | return nil |
| 724 | } |
| 725 | |
| 726 | func (d *Devbox) FixMissingStorePaths(ctx context.Context) error { |
| 727 | packages := d.InstallablePackages() |
no test coverage detected